Search in sources :

Example 1 with KuraSnapshotIds

use of org.eclipse.kapua.service.device.call.kura.model.snapshot.KuraSnapshotIds in project kapua by eclipse.

the class TranslatorAppSnapshotKuraKapua method translate.

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

Aggregations

KapuaException (org.eclipse.kapua.KapuaException)1 KuraSnapshotIds (org.eclipse.kapua.service.device.call.kura.model.snapshot.KuraSnapshotIds)1 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)1 SnapshotResponsePayload (org.eclipse.kapua.service.device.management.configuration.snapshot.internal.SnapshotResponsePayload)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1