use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel 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.KuraRequestChannel in project kapua by eclipse.
the class TranslatorAppConfigurationKapuaKura method translate.
private KuraRequestChannel translate(ConfigurationRequestChannel kapuaChannel) throws KapuaException {
KuraRequestChannel kuraRequestChannel = new KuraRequestChannel();
kuraRequestChannel.setMessageClassification(CONTROL_MESSAGE_CLASSIFIER);
// Build appId
StringBuilder appIdSb = new StringBuilder();
appIdSb.append(propertiesDictionary.get(DeviceConfigurationAppProperties.APP_NAME).getValue()).append("-").append(propertiesDictionary.get(DeviceConfigurationAppProperties.APP_VERSION).getValue());
kuraRequestChannel.setAppId(appIdSb.toString());
kuraRequestChannel.setMethod(MethodDictionaryKapuaKura.get(kapuaChannel.getMethod()));
// Build resources
List<String> resources = new ArrayList<>();
if (kapuaChannel.getConfigurationId() == null) {
resources.add("configurations");
String componentId = kapuaChannel.getComponentId();
if (componentId != null) {
resources.add(componentId);
}
} else if (kapuaChannel.getConfigurationId() != null) {
resources.add("snapshots");
String configurationId = kapuaChannel.getConfigurationId();
if (configurationId != null) {
resources.add(configurationId);
}
}
kuraRequestChannel.setResources(resources.toArray(new String[resources.size()]));
// Return Kura Channel
return kuraRequestChannel;
}
use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel in project kapua by eclipse.
the class TranslatorAppPackageKapuaKura method translate.
private KuraRequestChannel translate(PackageRequestChannel kapuaChannel) throws KapuaException {
KuraRequestChannel kuraRequestChannel = new KuraRequestChannel();
kuraRequestChannel.setMessageClassification(CONTROL_MESSAGE_CLASSIFIER);
// Build appId
StringBuilder appIdSb = new StringBuilder();
appIdSb.append(propertiesDictionary.get(PackageAppProperties.APP_NAME).getValue()).append("-").append(propertiesDictionary.get(PackageAppProperties.APP_VERSION).getValue());
kuraRequestChannel.setAppId(appIdSb.toString());
kuraRequestChannel.setMethod(MethodDictionaryKapuaKura.get(kapuaChannel.getMethod()));
// Build resources
List<String> resources = new ArrayList<>();
if (kapuaChannel.getResource() == null) {
resources.add("packages");
} else {
switch(kapuaChannel.getResource()) {
case DOWNLOAD:
resources.add("download");
break;
case INSTALL:
resources.add("install");
break;
case UNINSTALL:
resources.add("uninstall");
break;
}
}
kuraRequestChannel.setResources(resources.toArray(new String[resources.size()]));
// Return Kura Channel
return kuraRequestChannel;
}
use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel 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.KuraRequestChannel in project kapua by eclipse.
the class TranslatorAppCommandKapuaKura method translate.
private KuraRequestChannel translate(CommandRequestChannel kapuaChannel) throws KapuaException {
KuraRequestChannel kuraRequestChannel = new KuraRequestChannel();
kuraRequestChannel.setMessageClassification(CONTROL_MESSAGE_CLASSIFIER);
// Build appId
StringBuilder appIdSb = new StringBuilder();
appIdSb.append(propertiesDictionary.get(CommandAppProperties.APP_NAME).getValue()).append("-").append(propertiesDictionary.get(CommandAppProperties.APP_VERSION).getValue());
kuraRequestChannel.setAppId(appIdSb.toString());
kuraRequestChannel.setMethod(MethodDictionaryKapuaKura.get(kapuaChannel.getMethod()));
kuraRequestChannel.setResources(new String[] { "command" });
// Return Kura Channel
return kuraRequestChannel;
}
Aggregations