Search in sources :

Example 1 with KuraDeploymentPackages

use of org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackages in project kapua by eclipse.

the class TranslatorAppPackageKuraKapua method translate.

private PackageResponsePayload translate(KuraResponsePayload kuraResponsePayload) throws KapuaException {
    PackageResponsePayload responsePayload = new PackageResponsePayload();
    Map<String, Object> metrics = kuraResponsePayload.getMetrics();
    responsePayload.setExceptionMessage((String) metrics.get(ResponseMetrics.RESP_METRIC_EXCEPTION_MESSAGE.getValue()));
    responsePayload.setExceptionStack((String) metrics.get(ResponseMetrics.RESP_METRIC_EXCEPTION_STACK.getValue()));
    if (metrics.get(PackageMetrics.APP_METRIC_PACKAGE_OPERATION_ID.getValue()) != null) {
        responsePayload.setPackageDownloadOperationId(new KapuaEid(new BigInteger(metrics.get(PackageMetrics.APP_METRIC_PACKAGE_OPERATION_ID.getValue()).toString())));
    }
    if (metrics.get(PackageMetrics.APP_METRIC_PACKAGE_DOWNLOAD_STATUS.getValue()) != null) {
        responsePayload.setPackageDownloadOperationStatus(DevicePackageDownloadStatus.valueOf((String) metrics.get(PackageMetrics.APP_METRIC_PACKAGE_DOWNLOAD_STATUS.getValue())));
    }
    responsePayload.setPackageDownloadOperationSize((Integer) metrics.get(PackageMetrics.APP_METRIC_PACKAGE_DOWNLOAD_SIZE.getValue()));
    responsePayload.setPackageDownloadOperationProgress((Integer) metrics.get(PackageMetrics.APP_METRIC_PACKAGE_DOWNLOAD_PROGRESS.getValue()));
    String body;
    if (kuraResponsePayload.getBody() != null) {
        DeviceManagementSetting config = DeviceManagementSetting.getInstance();
        String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);
        try {
            body = new String(kuraResponsePayload.getBody(), charEncoding);
        } catch (Exception e) {
            throw new // 
            TranslatorException(// 
            TranslatorErrorCodes.INVALID_PAYLOAD, // 
            e, // 
            kuraResponsePayload.getBody());
        }
        KuraDeploymentPackages kuraDeploymentPackages = null;
        try {
            kuraDeploymentPackages = XmlUtil.unmarshal(body, KuraDeploymentPackages.class);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, body);
        }
        translate(responsePayload, charEncoding, kuraDeploymentPackages);
    }
    // Return Kapua Payload
    return responsePayload;
}
Also used : PackageResponsePayload(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload) KuraDeploymentPackages(org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackages) DeviceManagementSetting(org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting) BigInteger(java.math.BigInteger) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

BigInteger (java.math.BigInteger)1 KapuaException (org.eclipse.kapua.KapuaException)1 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)1 KuraDeploymentPackages (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackages)1 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)1 PackageResponsePayload (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1