/** * Update an existing device command. * * @param context * @param token * @param request * @return * @throws SiteWhereException */ public static DeviceCommand updateDeviceCommand(IHBaseContext context, String token, IDeviceCommandCreateRequest request) throws SiteWhereException { DeviceCommand updated = assertDeviceCommand(context, token); List<IDeviceCommand> existing = listDeviceCommands(context, updated.getSpecificationToken(), false); SiteWherePersistence.deviceCommandUpdateLogic(request, updated, existing); return putDeviceCommandPayload(context, updated); }
@Override public IDeviceCommand updateDeviceCommand(String token, IDeviceCommandCreateRequest request) throws SiteWhereException { Document match = assertDeviceCommand(token); DeviceCommand command = MongoDeviceCommand.fromDocument(match); // Note: This allows duplicates if duplicate was marked deleted. List<IDeviceCommand> existing = listDeviceCommands(token, false); // Use common update logic. SiteWherePersistence.deviceCommandUpdateLogic(request, command, existing); Document updated = MongoDeviceCommand.toDocument(command); Document query = new Document(MongoDeviceCommand.PROP_TOKEN, token); MongoCollection<Document> commands = getMongoClient().getDeviceCommandsCollection(getTenant()); MongoPersistence.update(commands, query, updated); return MongoDeviceCommand.fromDocument(updated); }