@Override public List<IDeviceCommand> listDeviceCommands(String token, boolean includeDeleted) throws SiteWhereException { return delegate.listDeviceCommands(token, includeDeleted); }
@Override public ISearchResults<IDeviceCommand> listDeviceCommands(IDeviceCommandSearchCriteria criteria) throws SiteWhereException { return getDelegate().listDeviceCommands(criteria); }
/** * Generate a '.proto' file for a specification. * * @param specification * @return * @throws SiteWhereException */ public static String getProtoForSpecification(IDeviceSpecification specification, ITenant tenant) throws SiteWhereException { StringBuffer buffer = new StringBuffer(); List<IDeviceCommand> commands = SiteWhere.getServer().getDeviceManagement(tenant) .listDeviceCommands(specification.getToken(), false); generateProto(specification, commands, buffer); return buffer.toString(); }
/** * Generate a '.proto' file for a device type. * * @param deviceType * @return * @throws SiteWhereException */ public static String getProtoForDeviceType(IDeviceType deviceType, IDeviceManagement deviceManagement) throws SiteWhereException { StringBuffer buffer = new StringBuffer(); DeviceCommandSearchCriteria criteria = new DeviceCommandSearchCriteria(1, 0); criteria.setDeviceTypeId(deviceType.getId()); ISearchResults<IDeviceCommand> commands = deviceManagement.listDeviceCommands(criteria); generateProto(deviceType, commands.getResults(), buffer); return buffer.toString(); }
public DeviceCommandInvocationCreateRequest.Builder newCommandInvocation(String commandName, String target) { try { IDeviceAssignment targetAssignment = deviceManagement.getDeviceAssignmentByToken(target); if (targetAssignment == null) { throw new SiteWhereException("Target assignment not found: " + target); } IDevice targetDevice = deviceManagement.getDeviceForAssignment(targetAssignment); List<IDeviceCommand> commands = deviceManagement.listDeviceCommands(targetDevice.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); } return new DeviceCommandInvocationCreateRequest.Builder(match.getToken(), target); } catch (SiteWhereException e) { throw new RuntimeException(e); } }
@RequestMapping(value = "/{token}/commands", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "List device commands for specification") @Secured({ SiteWhereRoles.REST }) @Documented(examples = { @Example(stage = Stage.Response, json = Specifications.ListDeviceCommandsResponse.class, description = "listDeviceCommandsResponse.md") }) public ISearchResults<IDeviceCommand> listDeviceCommands( @ApiParam(value = "Token", required = true) @PathVariable String token, @ApiParam(value = "Include deleted", required = false) @RequestParam(defaultValue = "false") boolean includeDeleted, HttpServletRequest servletRequest) throws SiteWhereException { Tracer.start(TracerCategory.RestApiCall, "listDeviceCommands", LOGGER); try { List<IDeviceCommand> results = SiteWhere.getServer().getDeviceManagement(getTenant(servletRequest)) .listDeviceCommands(token, includeDeleted); Collections.sort(results, new Comparator<IDeviceCommand>() { public int compare(IDeviceCommand o1, IDeviceCommand o2) { if (o1.getName().equals(o2.getName())) { return o1.getNamespace().compareTo(o2.getNamespace()); } return o1.getName().compareTo(o2.getName()); } }); return new SearchResults<IDeviceCommand>(results); } finally { Tracer.stop(LOGGER); } }
public DeviceCommandInvocationCreateRequest.Builder newCommandInvocation(String commandName, String target) { try { IDeviceAssignment targetAssignment = deviceManagement.getDeviceAssignmentByToken(target); if (targetAssignment == null) { throw new SiteWhereException("Target assignment not found: " + target); } IDevice targetDevice = deviceManagement.getDevice(targetAssignment.getDeviceId()); DeviceCommandSearchCriteria criteria = new DeviceCommandSearchCriteria(1, 0); criteria.setDeviceTypeId(targetDevice.getDeviceTypeId()); ISearchResults<IDeviceCommand> commands = deviceManagement.listDeviceCommands(criteria); IDeviceCommand match = null; for (IDeviceCommand command : commands.getResults()) { if (command.getName().equals(commandName)) { match = command; } } if (match == null) { throw new SiteWhereException("Command not executed. No command found matching: " + commandName); } return new DeviceCommandInvocationCreateRequest.Builder(match.getToken(), target); } catch (SiteWhereException e) { throw new RuntimeException(e); } }
try { List<IDeviceCommand> results = SiteWhere.getServer().getDeviceManagement(getTenant(servletRequest)) .listDeviceCommands(token, includeDeleted); Collections.sort(results, new Comparator<IDeviceCommand>() { public int compare(IDeviceCommand o1, IDeviceCommand o2) {
@Override public void listDeviceCommands(GListDeviceCommandsRequest request, StreamObserver<GListDeviceCommandsResponse> responseObserver) { try { GrpcUtils.handleServerMethodEntry(this, DeviceManagementGrpc.getListDeviceCommandsMethod()); IDeviceCommandSearchCriteria criteria = DeviceModelConverter .asApiDeviceCommandSearchCriteria(request.getCriteria()); ISearchResults<IDeviceCommand> apiResult = getDeviceManagement().listDeviceCommands(criteria); GListDeviceCommandsResponse.Builder response = GListDeviceCommandsResponse.newBuilder(); GDeviceCommandSearchResults.Builder results = GDeviceCommandSearchResults.newBuilder(); for (IDeviceCommand apiType : apiResult.getResults()) { results.addDeviceCommands(DeviceModelConverter.asGrpcDeviceCommand(apiType)); } results.setCount(apiResult.getNumResults()); response.setResults(results.build()); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } catch (Throwable e) { GrpcUtils.handleServerMethodException(DeviceManagementGrpc.getListDeviceCommandsMethod(), e, responseObserver); } finally { GrpcUtils.handleServerMethodExit(DeviceManagementGrpc.getListDeviceCommandsMethod()); } }
@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); }
@Override public void sendCommand(IDeviceAssignment assignment, String commandName, Map<String, String> parameters) throws SiteWhereException { IDevice device = getDeviceManagement().getDevice(assignment.getDeviceId()); DeviceCommandSearchCriteria criteria = new DeviceCommandSearchCriteria(1, 0); criteria.setDeviceTypeId(device.getDeviceTypeId()); ISearchResults<IDeviceCommand> commands = getDeviceManagement().listDeviceCommands(criteria); IDeviceCommand match = null; for (IDeviceCommand command : commands.getResults()) { 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().addDeviceCommandInvocations(assignment.getId(), create); }
/** * Create the message for a specification. * * @param specification * @param tenant * @return * @throws SiteWhereException */ public static DescriptorProtos.DescriptorProto createSpecificationMessage(IDeviceSpecification specification, ITenant tenant) throws SiteWhereException { List<IDeviceCommand> commands = SiteWhere.getServer().getDeviceManagement(tenant) .listDeviceCommands(specification.getToken(), false); DescriptorProtos.DescriptorProto.Builder builder = DescriptorProtos.DescriptorProto.newBuilder(); builder.setName(ProtobufNaming.getSpecificationIdentifier(specification)); builder.addEnumType(createCommandsEnum(commands)); builder.addNestedType(createUuidMessage()); builder.addNestedType(createHeaderMessage()); for (IDeviceCommand command : commands) { builder.addNestedType(createCommandMessage(command)).build(); } return builder.build(); }
/** * Create the message for a device type. * * @param deviceType * @param tenant * @param deviceManagement * @return * @throws SiteWhereException */ public static DescriptorProtos.DescriptorProto createDeviceTypeMessage(IDeviceType deviceType, ITenant tenant, IDeviceManagement deviceManagement) throws SiteWhereException { DeviceCommandSearchCriteria criteria = new DeviceCommandSearchCriteria(1, 0); criteria.setDeviceTypeId(deviceType.getId()); ISearchResults<IDeviceCommand> commands = deviceManagement.listDeviceCommands(criteria); DescriptorProtos.DescriptorProto.Builder builder = DescriptorProtos.DescriptorProto.newBuilder(); builder.setName(ProtobufNaming.getDeviceTypeIdentifier(deviceType)); builder.addEnumType(createCommandsEnum(commands.getResults())); builder.addNestedType(createUuidMessage()); builder.addNestedType(createHeaderMessage()); for (IDeviceCommand command : commands.getResults()) { builder.addNestedType(createCommandMessage(command)).build(); } return builder.build(); }