Search in sources :

Example 1 with KuraDeviceComponentConfiguration

use of org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration 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 2 with KuraDeviceComponentConfiguration

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

the class TranslatorAppConfigurationKuraKapua method translateBody.

private void translateBody(ConfigurationResponsePayload configurationResponsePayload, String charEncoding, KuraDeviceConfiguration kuraDeviceConfiguration) throws TranslatorException {
    try {
        DeviceConfigurationImpl deviceConfiguration = new DeviceConfigurationImpl();
        for (KuraDeviceComponentConfiguration kuraDeviceCompConf : kuraDeviceConfiguration.getConfigurations()) {
            String componentId = kuraDeviceCompConf.getComponentId();
            DeviceComponentConfigurationImpl deviceComponentConfiguration = new DeviceComponentConfigurationImpl(componentId);
            deviceComponentConfiguration.setProperties(translate(kuraDeviceCompConf.getProperties()));
            // Translate also definitions when they are available
            if (kuraDeviceCompConf.getDefinition() != null) {
                deviceComponentConfiguration.setDefinition(translate(kuraDeviceCompConf.getDefinition()));
            }
            // Add to kapua configuration
            deviceConfiguration.getComponentConfigurations().add(deviceComponentConfiguration);
        }
        StringWriter sw = new StringWriter();
        XmlUtil.marshal(deviceConfiguration, sw);
        byte[] requestBody = sw.toString().getBytes(charEncoding);
        configurationResponsePayload.setBody(requestBody);
    } catch (Exception e) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_BODY, e, kuraDeviceConfiguration);
    }
}
Also used : DeviceComponentConfigurationImpl(org.eclipse.kapua.service.device.management.configuration.internal.DeviceComponentConfigurationImpl) StringWriter(java.io.StringWriter) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KuraDeviceComponentConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration) DeviceConfigurationImpl(org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

KuraDeviceComponentConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration)2 StringWriter (java.io.StringWriter)1 KapuaException (org.eclipse.kapua.KapuaException)1 KuraDeviceConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration)1 DeviceComponentConfiguration (org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration)1 DeviceComponentConfigurationImpl (org.eclipse.kapua.service.device.management.configuration.internal.DeviceComponentConfigurationImpl)1 DeviceConfigurationImpl (org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1