Search in sources :

Example 1 with DeviceBundleFactory

use of org.eclipse.kapua.service.device.management.bundle.DeviceBundleFactory in project kapua by eclipse.

the class TranslatorAppBundleKuraKapua method translate.

private void translate(BundleResponsePayload bundleResponsePayload, String charEncoding, KuraBundles kuraBundles) throws KapuaException {
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceBundleFactory deviceBundleFactory = locator.getFactory(DeviceBundleFactory.class);
        KuraBundle[] kuraBundleArrays = kuraBundles.getBundles();
        DeviceBundles deviceBundles = deviceBundleFactory.newBundleListResult();
        List<DeviceBundle> deviceBundlesList = deviceBundles.getBundles();
        for (KuraBundle kuraBundle : kuraBundleArrays) {
            DeviceBundle deviceBundle = deviceBundleFactory.newDeviceBundle();
            deviceBundle.setId(kuraBundle.getId());
            deviceBundle.setName(kuraBundle.getName());
            deviceBundle.setVersion(kuraBundle.getVersion());
            deviceBundle.setState(kuraBundle.getState());
            deviceBundlesList.add(deviceBundle);
        }
        StringWriter sw = new StringWriter();
        XmlUtil.marshal(deviceBundles, sw);
        byte[] requestBody = sw.toString().getBytes(charEncoding);
        bundleResponsePayload.setBody(requestBody);
    } catch (Exception e) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_BODY, e, kuraBundles);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DeviceBundles(org.eclipse.kapua.service.device.management.bundle.DeviceBundles) DeviceBundleFactory(org.eclipse.kapua.service.device.management.bundle.DeviceBundleFactory) StringWriter(java.io.StringWriter) KuraBundle(org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundle) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) DeviceBundle(org.eclipse.kapua.service.device.management.bundle.DeviceBundle) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

StringWriter (java.io.StringWriter)1 KapuaException (org.eclipse.kapua.KapuaException)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KuraBundle (org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundle)1 DeviceBundle (org.eclipse.kapua.service.device.management.bundle.DeviceBundle)1 DeviceBundleFactory (org.eclipse.kapua.service.device.management.bundle.DeviceBundleFactory)1 DeviceBundles (org.eclipse.kapua.service.device.management.bundle.DeviceBundles)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1