Search in sources :

Example 1 with KuraRequestChannel

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);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Device(org.eclipse.kapua.service.device.registry.Device) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 2 with KuraRequestChannel

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;
}
Also used : ArrayList(java.util.ArrayList) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)

Example 3 with 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;
}
Also used : ArrayList(java.util.ArrayList) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)

Example 4 with 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);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Device(org.eclipse.kapua.service.device.registry.Device) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 5 with KuraRequestChannel

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;
}
Also used : KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)

Aggregations

KuraRequestChannel (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)12 KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)7 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)6 KuraRequestMessage (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage)6 Account (org.eclipse.kapua.service.account.Account)5 AccountService (org.eclipse.kapua.service.account.AccountService)5 Device (org.eclipse.kapua.service.device.registry.Device)5 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)2 Random (java.util.Random)1 KapuaException (org.eclipse.kapua.KapuaException)1 DeviceCall (org.eclipse.kapua.service.device.call.DeviceCall)1 DeviceCallFactory (org.eclipse.kapua.service.device.call.DeviceCallFactory)1 KuraMqttDeviceCallException (org.eclipse.kapua.service.device.call.kura.exception.KuraMqttDeviceCallException)1 KuraResponseMessage (org.eclipse.kapua.service.device.call.message.app.response.kura.KuraResponseMessage)1 Translator (org.eclipse.kapua.translator.Translator)1 TransportFacade (org.eclipse.kapua.transport.TransportFacade)1 TransportMessage (org.eclipse.kapua.transport.message.TransportMessage)1 Ignore (org.junit.Ignore)1