Search in sources :

Example 1 with KuraDeviceConfiguration

use of org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration in project kapua by eclipse.

the class TranslatorAppConfigurationKuraKapua method translate.

private ConfigurationResponsePayload translate(KuraResponsePayload kuraPayload) throws KapuaException {
    ConfigurationResponsePayload configurationResponsePayload = new ConfigurationResponsePayload();
    configurationResponsePayload.setExceptionMessage((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_MESSAGE.getValue()));
    configurationResponsePayload.setExceptionStack((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_STACK.getValue()));
    DeviceManagementSetting config = DeviceManagementSetting.getInstance();
    String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);
    if (kuraPayload.getBody() != null) {
        String body = null;
        try {
            body = new String(kuraPayload.getBody(), charEncoding);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, configurationResponsePayload.getBody());
        }
        KuraDeviceConfiguration kuraDeviceConfiguration = null;
        try {
            kuraDeviceConfiguration = XmlUtil.unmarshal(body, KuraDeviceConfiguration.class);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, body);
        }
        translateBody(configurationResponsePayload, charEncoding, kuraDeviceConfiguration);
    }
    // Return Kapua Payload
    return configurationResponsePayload;
}
Also used : KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) DeviceManagementSetting(org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting) ConfigurationResponsePayload(org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationResponsePayload) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Example 2 with KuraDeviceConfiguration

use of org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration in project kapua by eclipse.

the class TranslatorAppConfigurationKapuaKura method translate.

private KuraDeviceConfiguration translate(DeviceConfiguration kapuaDeviceConfiguration) throws KapuaException {
    KuraDeviceConfiguration kuraDeviceConfiguration = new KuraDeviceConfiguration();
    for (DeviceComponentConfiguration kapuaDeviceCompConf : kapuaDeviceConfiguration.getComponentConfigurations()) {
        KuraDeviceComponentConfiguration kuraComponentConfiguration = new KuraDeviceComponentConfiguration();
        kuraComponentConfiguration.setComponentId(kapuaDeviceCompConf.getId());
        kuraComponentConfiguration.setProperties(translate(kapuaDeviceCompConf.getProperties()));
        // Translate also definitions when they are available
        if (kapuaDeviceCompConf.getDefinition() != null) {
            kuraComponentConfiguration.setDefinition(translate(kapuaDeviceCompConf.getDefinition()));
        }
        // Add to kapua configuration
        kuraDeviceConfiguration.getConfigurations().add(kuraComponentConfiguration);
    }
    return kuraDeviceConfiguration;
}
Also used : KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) KuraDeviceComponentConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration) DeviceComponentConfiguration(org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration) KuraDeviceComponentConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration)

Example 3 with KuraDeviceConfiguration

use of org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration 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;
}
Also used : KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) DeviceConfiguration(org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration) DeviceConfigurationImpl(org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Aggregations

KuraDeviceConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration)3 KapuaException (org.eclipse.kapua.KapuaException)2 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)2 KuraDeviceComponentConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration)1 KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)1 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)1 DeviceComponentConfiguration (org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration)1 DeviceConfiguration (org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration)1 DeviceConfigurationImpl (org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl)1 ConfigurationResponsePayload (org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationResponsePayload)1