@Override public KapuaAppProperties unmarshal(String v) throws Exception { return REQUEST_MESSAGE_FACTORY.newAppProperties(v); } }
public KapuaRequestPayload newRequestPayload() { return KAPUA_REQUEST_MESSAGE_FACTORY.newRequestPayload(); } }
public KapuaRequestMessage<?, ?> newRequestMessage() { return KAPUA_REQUEST_MESSAGE_FACTORY.newRequestMessage(); }
Device device = DEVICE_REGISTRY_SERVICE.find(requestMessage.getScopeId(), requestMessage.getDeviceId()); if (device == null) { throw new KapuaEntityNotFoundException(Device.TYPE, requestMessage.getDeviceId()); Translator tKapuaToClient = Translator.getTranslatorFor(requestMessage.getRequestClass(), deviceCall.getBaseMessageClass()); DeviceRequestMessage deviceRequestMessage = (DeviceRequestMessage) tKapuaToClient.translate(requestMessage); switch (requestMessage.getChannel().getMethod()) { case CREATE: { responseMessage = deviceCall.create(deviceRequestMessage, timeout); Translator tClientToKapua = Translator.getTranslatorFor(deviceCall.getBaseMessageClass(), requestMessage.getResponseClass()); return (RS) tClientToKapua.translate(responseMessage);
protected KapuaId createManagementOperation(KapuaId scopeId, KapuaId deviceId, KapuaId operationId, int totalCheckpoints, KapuaRequestMessage<?, ?> requestMessage) throws KapuaException { DeviceManagementOperationCreator deviceManagementOperationCreator = DEVICE_MANAGEMENT_OPERATION_FACTORY.newCreator(scopeId); deviceManagementOperationCreator.setDeviceId(deviceId); deviceManagementOperationCreator.setOperationId(operationId); deviceManagementOperationCreator.setStartedOn(new Date()); deviceManagementOperationCreator.setAppId(requestMessage.getChannel().getAppName().getValue()); deviceManagementOperationCreator.setAction(requestMessage.getChannel().getMethod()); deviceManagementOperationCreator.setResource(!requestMessage.getChannel().getSemanticParts().isEmpty() ? requestMessage.getChannel().getSemanticParts().get(0) : null); deviceManagementOperationCreator.setStatus(OperationStatus.RUNNING); deviceManagementOperationCreator.setInputProperties(extractInputProperties(requestMessage)); DeviceManagementOperation deviceManagementOperation = KapuaSecurityUtils.doPrivileged(() -> DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.create(deviceManagementOperationCreator)); return deviceManagementOperation.getId(); }
/** * Creates a {@link org.eclipse.kapua.service.device.registry.event.DeviceEvent} extracting data from the given {@link KapuaRequestMessage} and {@link KapuaResponseMessage}. * <p> * This operation is performed using {@link KapuaSecurityUtils#doPrivileged(ThrowingRunnable)} since {@link org.eclipse.kapua.service.device.registry.event.DeviceEventDomain} isn't a required * permission to use any of the Device Management Services. * * @param scopeId The scopeId in which to create the {@link org.eclipse.kapua.service.device.registry.event.DeviceEvent} * @param deviceId The {@link org.eclipse.kapua.service.device.registry.Device} id for which the {@link org.eclipse.kapua.service.device.registry.event.DeviceEvent} is created * @param requestMessage The {@link KapuaRequestMessage} of the DeviceManagementService operation from which to extract data. * @param responseMessage The {@link KapuaResponseMessage} of the DeviceManagementService operation from which to extract data. * @throws KapuaException If the creation of the {@link org.eclipse.kapua.service.device.registry.event.DeviceEvent} fails for some reasons * @since 1.0.0 */ protected void createDeviceEvent(KapuaId scopeId, KapuaId deviceId, KapuaRequestMessage<?, ?> requestMessage, KapuaResponseMessage responseMessage) throws KapuaException { DeviceEventCreator deviceEventCreator = DEVICE_EVENT_FACTORY.newCreator( scopeId, deviceId, responseMessage.getReceivedOn(), requestMessage.getChannel().getAppName().getValue()); deviceEventCreator.setPosition(responseMessage.getPosition()); deviceEventCreator.setSentOn(responseMessage.getSentOn()); deviceEventCreator.setAction(requestMessage.getChannel().getMethod()); deviceEventCreator.setResponseCode(responseMessage.getResponseCode()); deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString()); KapuaSecurityUtils.doPrivileged(() -> DEVICE_EVENT_SERVICE.create(deviceEventCreator)); }
private List<DeviceManagementOperationProperty> extractInputProperties(KapuaRequestMessage<?, ?> requestMessage) { List<DeviceManagementOperationProperty> inputProperties = new ArrayList<>(); Map<String, Object> properties = requestMessage.getPayload().getMetrics(); properties.forEach((k, v) -> { if (v != null) { inputProperties.add( DEVICE_MANAGEMENT_OPERATION_FACTORY.newStepProperty( k, ObjectTypeConverter.toString(v.getClass()), ObjectValueConverter.toString(v)) ); } }); return inputProperties; }
public KapuaRequestChannel newRequestChannel() { return KAPUA_REQUEST_MESSAGE_FACTORY.newRequestChannel(); }