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;
}
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;
}
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;
}
Aggregations