Search in sources :

Example 1 with DevicePackage

use of org.eclipse.kapua.service.device.management.packages.model.DevicePackage 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);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageBundleInfo(org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo) DevicePackage(org.eclipse.kapua.service.device.management.packages.model.DevicePackage) KuraBundleInfo(org.eclipse.kapua.service.device.call.kura.model.deploy.KuraBundleInfo) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException) DevicePackages(org.eclipse.kapua.service.device.management.packages.model.DevicePackages) DevicePackageFactory(org.eclipse.kapua.service.device.management.packages.DevicePackageFactory) StringWriter(java.io.StringWriter) DevicePackageBundleInfos(org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KuraDeploymentPackage(org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackage)

Example 2 with DevicePackage

use of org.eclipse.kapua.service.device.management.packages.model.DevicePackage in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method findDevicePackages.

// 
// Packages
// 
@Override
public List<GwtDeploymentPackage> findDevicePackages(String scopeShortId, String deviceShortId) throws GwtKapuaException {
    List<GwtDeploymentPackage> gwtPkgs = new ArrayList<GwtDeploymentPackage>();
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        DevicePackageManagementService deviceManagementService = locator.getService(DevicePackageManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(scopeShortId);
        KapuaId deviceId = KapuaEid.parseShortId(deviceShortId);
        DevicePackages deploymentPackages = deviceManagementService.getInstalled(scopeId, deviceId, null);
        for (DevicePackage deploymentPackage : deploymentPackages.getPackages()) {
            GwtDeploymentPackage gwtPkg = new GwtDeploymentPackage();
            gwtPkg.setName(deploymentPackage.getName());
            gwtPkg.setVersion(deploymentPackage.getVersion());
            DevicePackageBundleInfos devicePackageBundleInfos = deploymentPackage.getBundleInfos();
            if (devicePackageBundleInfos != null) {
                List<GwtBundleInfo> gwtBundleInfos = new ArrayList<GwtBundleInfo>();
                for (DevicePackageBundleInfo bundleInfo : devicePackageBundleInfos.getBundlesInfos()) {
                    GwtBundleInfo gwtBundleInfo = new GwtBundleInfo();
                    gwtBundleInfo.setName(bundleInfo.getName());
                    gwtBundleInfo.setVersion(bundleInfo.getVersion());
                    gwtBundleInfos.add(gwtBundleInfo);
                }
                gwtPkg.setBundleInfos(gwtBundleInfos);
            }
            gwtPkgs.add(gwtPkg);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtPkgs;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtDeploymentPackage(org.eclipse.kapua.app.console.shared.model.GwtDeploymentPackage) ArrayList(java.util.ArrayList) DevicePackageBundleInfo(org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo) DevicePackage(org.eclipse.kapua.service.device.management.packages.model.DevicePackage) DevicePackages(org.eclipse.kapua.service.device.management.packages.model.DevicePackages) DevicePackageManagementService(org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService) DevicePackageBundleInfos(org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos) KapuaId(org.eclipse.kapua.model.id.KapuaId) GwtBundleInfo(org.eclipse.kapua.app.console.shared.model.GwtBundleInfo)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 DevicePackage (org.eclipse.kapua.service.device.management.packages.model.DevicePackage)2 DevicePackageBundleInfo (org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo)2 DevicePackageBundleInfos (org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos)2 DevicePackages (org.eclipse.kapua.service.device.management.packages.model.DevicePackages)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 KapuaException (org.eclipse.kapua.KapuaException)1 GwtBundleInfo (org.eclipse.kapua.app.console.shared.model.GwtBundleInfo)1 GwtDeploymentPackage (org.eclipse.kapua.app.console.shared.model.GwtDeploymentPackage)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 KuraBundleInfo (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraBundleInfo)1 KuraDeploymentPackage (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackage)1 DevicePackageFactory (org.eclipse.kapua.service.device.management.packages.DevicePackageFactory)1 DevicePackageManagementService (org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1