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