use of org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackage in project kapua by eclipse.
the class TranslatorAppPackageKuraKapua method translate.
private void translate(PackageResponsePayload packageResponsePayload, String charEncoding, KuraDeploymentPackages kuraDeploymentPackages) throws KapuaException {
try {
KuraDeploymentPackage[] deploymentPackageArray = kuraDeploymentPackages.getDeploymentPackages();
if (deploymentPackageArray != null) {
KapuaLocator locator = KapuaLocator.getInstance();
DevicePackageFactory deviceDeploymentFactory = locator.getFactory(DevicePackageFactory.class);
DevicePackages deviceDeploymentPackages = deviceDeploymentFactory.newDeviceDeploymentPackages();
for (KuraDeploymentPackage deploymentPackage : deploymentPackageArray) {
DevicePackage deviceDeploymentPackage = deviceDeploymentFactory.newDeviceDeploymentPackage();
deviceDeploymentPackage.setName(deploymentPackage.getName());
deviceDeploymentPackage.setVersion(deploymentPackage.getVersion());
DevicePackageBundleInfos devicePackageBundleInfos = deviceDeploymentPackage.getBundleInfos();
KuraBundleInfo[] bundleInfoArray = deploymentPackage.getBundleInfos();
for (KuraBundleInfo bundleInfo : bundleInfoArray) {
DevicePackageBundleInfo devicePackageBundleInfo = deviceDeploymentFactory.newDevicePackageBundleInfo();
devicePackageBundleInfo.setName(bundleInfo.getName());
devicePackageBundleInfo.setVersion(bundleInfo.getVersion());
// Add the new DevicePackageBundleInfo object to the corresponding list
devicePackageBundleInfos.getBundlesInfos().add(devicePackageBundleInfo);
}
// Add the new DeviceDeploymentPackage object to the corresponding list
deviceDeploymentPackages.getPackages().add(deviceDeploymentPackage);
}
StringWriter sw = new StringWriter();
XmlUtil.marshal(deviceDeploymentPackages, sw);
byte[] requestBody = sw.toString().getBytes(charEncoding);
packageResponsePayload.setBody(requestBody);
}
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_BODY, e, kuraDeploymentPackages);
}
}
Aggregations