@Override public IDeviceCommandInvocation addDeviceCommandInvocation(String assignmentToken, IDeviceCommand command, IDeviceCommandInvocationCreateRequest request) throws SiteWhereException { return delegate.addDeviceCommandInvocation(assignmentToken, command, request); }
public AssignmentScope persist(DeviceCommandInvocationCreateRequest.Builder builder) throws SiteWhereException { DeviceCommandInvocationCreateRequest request = builder.build(); IDeviceCommand command = deviceManagement.getDeviceCommandByToken(request.getCommandToken()); events.addDeviceCommandInvocation(getAssignmentToken(), command, request); return this; }
/** * Create command invocation to be associated with a device assignment. * * @param input * @param token * @return * @throws SiteWhereException */ @RequestMapping(value = "/{token}/invocations", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "Create command invocation event for assignment") @Secured({ SiteWhereRoles.REST }) @Documented(examples = { @Example(stage = Stage.Request, json = Assignments.CreateCommandInvocationRequest.class, description = "createCommandInvocationRequest.md"), @Example(stage = Stage.Response, json = Assignments.CreateCommandInvocationResponse.class, description = "createCommandInvocationResponse.md") }) public DeviceCommandInvocation createCommandInvocation(@RequestBody DeviceCommandInvocationCreateRequest request, @ApiParam(value = "Assignment token", required = true) @PathVariable String token, HttpServletRequest servletRequest) throws SiteWhereException { Tracer.start(TracerCategory.RestApiCall, "createCommandInvocation", LOGGER); try { IDeviceCommand command = assureDeviceCommand(request.getCommandToken(), servletRequest); IDeviceCommandInvocation result = SiteWhere.getServer().getDeviceEventManagement(getTenant(servletRequest)) .addDeviceCommandInvocation(token, command, request); DeviceCommandInvocationMarshalHelper helper = new DeviceCommandInvocationMarshalHelper( getTenant(servletRequest)); return helper.convert(result); } finally { Tracer.stop(LOGGER); } }
@Override public void sendCommand(String assignmentToken, String commandName, Map<String, String> parameters) throws SiteWhereException { IDeviceAssignment assignment = getDeviceManagement().getDeviceAssignmentByToken(assignmentToken); if (assignment == null) { throw new SiteWhereException("Command not executed. Assignment not found: " + assignmentToken); } IDevice device = getDeviceManagement().getDeviceForAssignment(assignment); List<IDeviceCommand> commands = getDeviceManagement().listDeviceCommands(device.getSpecificationToken(), false); IDeviceCommand match = null; for (IDeviceCommand command : commands) { if (command.getName().equals(commandName)) { match = command; } } if (match == null) { throw new SiteWhereException("Command not executed. No command found matching: " + commandName); } DeviceCommandInvocationCreateRequest create = new DeviceCommandInvocationCreateRequest(); create.setCommandToken(match.getToken()); create.setParameterValues(parameters); create.setInitiator(CommandInitiator.Script); create.setTarget(CommandTarget.Assignment); create.setTargetId(assignment.getToken()); create.setEventDate(new Date()); getDeviceEventManagement().addDeviceCommandInvocation(assignment.getToken(), match, create); }
.addDeviceCommandInvocation(assignment.getToken(), command, request); metadata = new HashMap<String, String>(); metadata.put(IBatchCommandInvocationRequest.META_INVOCATION_EVENT_ID, invocation.getId());
create.setTargetId(getAssignmentToken()); create.setEventDate(new Date()); events.addDeviceCommandInvocation(assignmentToken, command, create); LOGGER.info("Executed command invocation job."); } catch (SiteWhereException e) {