/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDeviceCommandInvocation source, Document target) { MongoDeviceEvent.toDocument(source, target, false); target.append(PROP_INITIATOR, source.getInitiator().name()); target.append(PROP_INITIATOR_ID, source.getInitiatorId()); target.append(PROP_TARGET, source.getTarget().name()); target.append(PROP_TARGET_ID, source.getTargetId()); target.append(PROP_COMMAND_TOKEN, source.getCommandToken()); Document params = new Document(); for (String key : source.getParameterValues().keySet()) { params.append(key, source.getParameterValues().get(key)); } target.append(PROP_PARAMETER_VALUES, params); }
@Override public void onCommandInvocationNotFiltered(IDeviceCommandInvocation invocation) throws SiteWhereException { DeviceCommandInvocation converted = invocationHelper.convert(invocation); commandInvocationsTopic.publish(converted); LOGGER.debug("Published command invocation event to Hazelcast (id=" + invocation.getId() + ")"); }
@Override public CommandStatus getStatus() { return ((IDeviceCommandInvocation) getWrapped()).getStatus(); } }
result.setInitiator(source.getInitiator()); result.setInitiatorId(source.getInitiatorId()); result.setTarget(source.getTarget()); result.setTargetId(source.getTargetId()); result.setCommandToken(source.getCommandToken()); result.setParameterValues(source.getParameterValues()); result.setId(source.getId()); result.setAlternateId(source.getAlternateId()); result.setEventType(source.getEventType()); result.setDeviceId(source.getDeviceId()); result.setDeviceAssignmentId(source.getDeviceAssignmentId()); result.setAreaId(source.getAreaId()); result.setAssetId(source.getAssetId()); result.setEventDate(source.getEventDate()); result.setReceivedDate(source.getReceivedDate()); MetadataProvider.copy(source, result); if ((source.getCommandToken() == null) || (source.getCommandToken().isEmpty())) { LOGGER.warn("Device invocation is missing command token."); return result; DeviceCommand command = commandsByToken.get(source.getCommandToken()); if (command == null) { IDeviceCommand found = getDeviceManagement().getDeviceCommandByToken(source.getCommandToken()); if (found == null) { LOGGER.warn("Device invocation references a non-existent command token.");
@Override public Map<String, String> getParameterValues() { return ((IDeviceCommandInvocation) getWrapped()).getParameterValues(); } }
@Override public String getCommandToken() { return ((IDeviceCommandInvocation) getWrapped()).getCommandToken(); }
@Override public CommandInitiator getInitiator() { return ((IDeviceCommandInvocation) getWrapped()).getInitiator(); }
@Override public String getInitiatorId() { return ((IDeviceCommandInvocation) getWrapped()).getInitiatorId(); }
@Override public CommandTarget getTarget() { return ((IDeviceCommandInvocation) getWrapped()).getTarget(); }
@Override public String getTargetId() { return ((IDeviceCommandInvocation) getWrapped()).getTargetId(); }
@Override public Map<String, String> getParameterValues() { return ((IDeviceCommandInvocation) getWrapped()).getParameterValues(); }
@Override public String getCommandToken() { return ((IDeviceCommandInvocation) getWrapped()).getCommandToken(); }
@Override public CommandInitiator getInitiator() { return ((IDeviceCommandInvocation) getWrapped()).getInitiator(); }
@Override public String getInitiatorId() { return ((IDeviceCommandInvocation) getWrapped()).getInitiatorId(); }
@Override public CommandTarget getTarget() { return ((IDeviceCommandInvocation) getWrapped()).getTarget(); }
@Override public String getTargetId() { return ((IDeviceCommandInvocation) getWrapped()).getTargetId(); }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDeviceCommandInvocation source, Document target) { MongoDeviceEvent.toDocument(source, target, false); target.append(PROP_INITIATOR, source.getInitiator().name()); target.append(PROP_INITIATOR_ID, source.getInitiatorId()); target.append(PROP_TARGET, source.getTarget().name()); target.append(PROP_TARGET_ID, source.getTargetId()); target.append(PROP_COMMAND_TOKEN, source.getCommandToken()); target.append(PROP_STATUS, source.getStatus().name()); Document params = new Document(); for (String key : source.getParameterValues().keySet()) { params.append(key, source.getParameterValues().get(key)); } target.append(PROP_PARAMETER_VALUES, params); }
String value = invocation.getParameterValues().get(parameter.getName()); try { switch (parameter.getType()) {
@Override public void deliverCommand(IDeviceCommunication communication, IDeviceCommandInvocation invocation) throws SiteWhereException { LOGGER.debug("Command processing strategy handling invocation."); IDeviceCommand command = SiteWhere.getServer().getDeviceManagement(getTenant()) .getDeviceCommandByToken(invocation.getCommandToken()); if (command != null) { IDeviceCommandExecution execution = getCommandExecutionBuilder().createExecution(command, invocation); List<IDeviceAssignment> assignments = getCommandTargetResolver().resolveTargets(invocation); for (IDeviceAssignment assignment : assignments) { IDevice device = SiteWhere.getServer().getDeviceManagement(getTenant()) .getDeviceForAssignment(assignment); if (device == null) { throw new SiteWhereException("Targeted assignment references device that does not exist."); } IDeviceNestingContext nesting = NestedDeviceSupport.calculateNestedDeviceInformation(device, getTenant()); communication.getOutboundCommandRouter().routeCommand(execution, nesting, assignment); } } else { throw new SiteWhereException("Invalid command referenced from invocation."); } }
.addDeviceCommandInvocations(assignment.getId(), request).get(0); updated.getMetadata().put(IBatchCommandInvocationRequest.META_INVOCATION_EVENT_ID, invocation.getId().toString());