use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.
the class TranslatorAppCommandKapuaKura method translate.
@Override
public KuraRequestMessage translate(CommandRequestMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
kuraRequestChannel.setScope(account.getName());
kuraRequestChannel.setClientId(device.getClientId());
//
// Kura payload
KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
// return Kura Message
return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.
the class TranslatorAppBundleKapuaKura method translate.
@Override
public KuraRequestMessage translate(BundleRequestMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
kuraRequestChannel.setScope(account.getName());
kuraRequestChannel.setClientId(device.getClientId());
//
// Kura payload
KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
// Return Kura Message
return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.
the class TranslatorAppCommandKapuaKura method translate.
private KuraRequestPayload translate(CommandRequestPayload kapuaPayload) throws KapuaException {
KuraRequestPayload kuraRequestPayload = new KuraRequestPayload();
//
// Payload translation
Map<String, Object> metrics = kuraRequestPayload.getMetrics();
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_CMD).getValue(), kapuaPayload.getCommand());
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_ENVP).getValue(), kapuaPayload.getEnvironmentPairs());
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_DIR).getValue(), kapuaPayload.getWorkingDir());
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_STDIN).getValue(), kapuaPayload.getStdin());
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_TOUT).getValue(), kapuaPayload.getTimeout());
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_ASYNC).getValue(), kapuaPayload.isRunAsync());
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_PASSWORD).getValue(), kapuaPayload.getPassword());
// argument translation
int i = 0;
String[] arguments = kapuaPayload.getArguments();
if (arguments != null) {
for (String argument : arguments) {
metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_ARG).getValue() + i++, argument);
}
}
//
// Body translation
kuraRequestPayload.setBody(kapuaPayload.getBody());
// Return Kura Payload
return kuraRequestPayload;
}
use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.
the class TranslatorAppConfigurationKapuaKura method translate.
@Override
public KuraRequestMessage translate(ConfigurationRequestMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
kuraRequestChannel.setScope(account.getName());
kuraRequestChannel.setClientId(device.getClientId());
//
// Kura payload
KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
// Return Kura Message
return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.
the class TranslatorAppConfigurationKapuaKura method translate.
private KuraRequestPayload translate(ConfigurationRequestPayload kapuaPayload) throws KapuaException {
KuraRequestPayload kuraRequestPayload = new KuraRequestPayload();
if (kapuaPayload.getBody() != null) {
DeviceConfiguration kapuaDeviceConfiguration;
try {
kapuaDeviceConfiguration = XmlUtil.unmarshal(new String(kapuaPayload.getBody()), DeviceConfigurationImpl.class);
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, kapuaPayload.getBody());
}
KuraDeviceConfiguration kuraDeviceConfiguration = translate(kapuaDeviceConfiguration);
byte[] body;
try {
body = XmlUtil.marshal(kuraDeviceConfiguration).getBytes();
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, kapuaPayload.getBody());
}
kuraRequestPayload.setBody(body);
}
// Return Kura Payload
return kuraRequestPayload;
}
Aggregations