public JsonGenericRequestMessage(GenericRequestMessage genericRequestMessage) { setId(genericRequestMessage.getId()); setScopeId(genericRequestMessage.getScopeId()); setDeviceId(genericRequestMessage.getDeviceId()); setClientId(genericRequestMessage.getClientId()); setReceivedOn(genericRequestMessage.getReceivedOn()); setSentOn(genericRequestMessage.getSentOn()); setCapturedOn(genericRequestMessage.getCapturedOn()); setPosition(genericRequestMessage.getPosition()); setChannel(genericRequestMessage.getChannel()); setPayload(genericRequestMessage.getPayload()); }
/** * Sends a request message to a device. * This call is generally used to perform remote management of resources * attached to the device such sensors and registries. * * @param scopeId The {@link ScopeId} of the {@link Device}. * @param deviceId The {@link Device} ID. * @param timeout The timeout of the request execution * @param requestMessage The input request * @return The response output. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. */ @POST @Consumes({MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_XML}) @ApiOperation(nickname = "deviceRequestSend", value = "Sends a request", notes = "Sends a request message to a device", response = DeviceCommandOutput.class) public GenericResponseMessage sendRequest( @ApiParam(value = "The ScopeId of the device", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The id of the device", required = true) @PathParam("deviceId") EntityId deviceId, @ApiParam(value = "The timeout of the request execution") @QueryParam("timeout") Long timeout, @ApiParam(value = "The input request", required = true) GenericRequestMessage requestMessage) throws Exception { requestMessage.setScopeId(scopeId); requestMessage.setDeviceId(deviceId); return requestService.exec(requestMessage, timeout); } }
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); Actions action; switch (requestInput.getChannel().getMethod()) { case EXECUTE: action = Actions.execute; throw new KapuaRuntimeException(KapuaErrorCodes.OPERATION_NOT_SUPPORTED); authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, action, requestInput.getScopeId())); genericRequestChannel.setAppName(requestInput.getChannel().getAppName()); genericRequestChannel.setVersion(requestInput.getChannel().getVersion()); genericRequestChannel.setMethod(requestInput.getChannel().getMethod()); genericRequestChannel.setResources(requestInput.getChannel().getResources()); genericRequestPayload.setMetrics(requestInput.getPayload().getMetrics()); genericRequestPayload.setBody(requestInput.getPayload().getBody()); genericRequestMessage.setScopeId(requestInput.getScopeId()); genericRequestMessage.setDeviceId(requestInput.getDeviceId()); genericRequestMessage.setCapturedOn(new Date()); genericRequestMessage.setChannel(genericRequestChannel); genericRequestMessage.setPayload(genericRequestPayload); genericRequestMessage.setPosition(requestInput.getPosition()); .newCreator(requestInput.getScopeId(), requestInput.getDeviceId(), responseMessage.getReceivedOn(), requestInput.getChannel().getAppName().getValue()); deviceEventCreator.setPosition(responseMessage.getPosition()); deviceEventCreator.setSentOn(responseMessage.getSentOn());
genericRequestMessage.setId(jsonGenericRequestMessage.getId()); genericRequestMessage.setScopeId(scopeId); genericRequestMessage.setDeviceId(jsonGenericRequestMessage.getDeviceId()); genericRequestMessage.setClientId(jsonGenericRequestMessage.getClientId()); genericRequestMessage.setReceivedOn(jsonGenericRequestMessage.getReceivedOn()); genericRequestMessage.setSentOn(jsonGenericRequestMessage.getSentOn()); genericRequestMessage.setCapturedOn(jsonGenericRequestMessage.getCapturedOn()); genericRequestMessage.setPosition(jsonGenericRequestMessage.getPosition()); genericRequestMessage.setChannel(jsonGenericRequestMessage.getChannel()); genericRequestMessage.setPayload(kapuaDataPayload);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); Actions action; switch (requestInput.getChannel().getMethod()) { case EXECUTE: action = Actions.execute; throw new KapuaRuntimeException(KapuaErrorCodes.OPERATION_NOT_SUPPORTED); authorizationService.checkPermission(permissionFactory.newPermission(DEVICE_MANAGEMENT_DOMAIN, action, requestInput.getScopeId())); genericRequestChannel.setAppName(requestInput.getChannel().getAppName()); genericRequestChannel.setVersion(requestInput.getChannel().getVersion()); genericRequestChannel.setMethod(requestInput.getChannel().getMethod()); genericRequestChannel.setResources(requestInput.getChannel().getResources()); genericRequestPayload.setMetrics(requestInput.getPayload().getMetrics()); genericRequestPayload.setBody(requestInput.getPayload().getBody()); genericRequestMessage.setScopeId(requestInput.getScopeId()); genericRequestMessage.setDeviceId(requestInput.getDeviceId()); genericRequestMessage.setCapturedOn(new Date()); genericRequestMessage.setChannel(genericRequestChannel); genericRequestMessage.setPayload(genericRequestPayload); genericRequestMessage.setPosition(requestInput.getPosition()); .newCreator(requestInput.getScopeId(), requestInput.getDeviceId(), responseMessage.getReceivedOn(), requestInput.getChannel().getAppName().getValue()); deviceEventCreator.setPosition(responseMessage.getPosition()); deviceEventCreator.setSentOn(responseMessage.getSentOn());
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); Actions action; switch (requestInput.getChannel().getMethod()) { case EXECUTE: action = Actions.execute; throw new KapuaRuntimeException(KapuaErrorCodes.OPERATION_NOT_SUPPORTED); authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, action, requestInput.getScopeId())); genericRequestChannel.setAppName(requestInput.getChannel().getAppName()); genericRequestChannel.setVersion(requestInput.getChannel().getVersion()); genericRequestChannel.setMethod(requestInput.getChannel().getMethod()); genericRequestChannel.setResources(requestInput.getChannel().getResources()); genericRequestPayload.setMetrics(requestInput.getPayload().getMetrics()); genericRequestPayload.setBody(requestInput.getPayload().getBody()); genericRequestMessage.setScopeId(requestInput.getScopeId()); genericRequestMessage.setDeviceId(requestInput.getDeviceId()); genericRequestMessage.setCapturedOn(new Date()); genericRequestMessage.setChannel(genericRequestChannel); genericRequestMessage.setPayload(genericRequestPayload); genericRequestMessage.setPosition(requestInput.getPosition()); .newCreator(requestInput.getScopeId(), requestInput.getDeviceId(), responseMessage.getReceivedOn(), requestInput.getChannel().getAppName().getValue()); deviceEventCreator.setPosition(responseMessage.getPosition()); deviceEventCreator.setSentOn(responseMessage.getSentOn());