I' writing a parser for a particular acknowledgement message in my tracker-agent. When parsed, I would like to retrieve all pending commands/firmware updates for the tracker so I can compare them with the content of the acknowledgement and update the relevant operation so that they display accordingly in Cumulocity.
How can I do that? For example, maybe I could use OperationsHelper.getOperationsByStatusAndAgent() ? But how do I have access to OperationsHelper at this level?
EDIT
Here is what I'm going to try now:
TrackerDevice:
public Iterable<OperationRepresentation> getPendingOps() {
OperationFilter opsFilter = new OperationFilter().byStatus(OperationStatus.PENDING)
.byAgent(this.gid.getValue());
return deviceControl.getOperationsByFilter(opsFilter).get().allPages();
}
My custom parser:
TrackerDevice trackerDevice = trackerAgent.getOrCreateTrackerDevice(reportCtx.getEntry(POS_IMEI));
// Looking into pending operations...
for (OperationRepresentation operation: trackerDevice.getPendingOps()) {
Firmware frm = operation.get(Firmware.class);
// ...for firmware updates
if (frm != null) {
String command = (String) frm.getProperty("command");
// (GL200Fallback associated a command string to these)
if (command != null) {
Matcher m = commandPattern.matcher(command);
// In each command there is a random count number...
if (m.find()) {
String cmdCountNumber = command.substring(m.start(), m.end());
// ...that must match with the acknowledgement's
if (cmdCountNumber.equals(reportCtx.getEntry(POS_COUNT_NUMBER))) {
trackerDevice.setOperationSuccessful(operation);
return true;
}
}
}
}
}