Search in sources :

Example 1 with DeviceConfigurationImpl

use of org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl 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

StringWriter (java.io.StringWriter)1 KapuaException (org.eclipse.kapua.KapuaException)1 KuraDeviceComponentConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration)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