use of org.eclipse.kapua.service.device.management.bundle.DeviceBundle in project kapua by eclipse.
the class GwtDeviceManagementServiceImpl method findBundles.
//
// Bundles
//
@Override
public ListLoadResult<GwtGroupedNVPair> findBundles(GwtDevice device) throws GwtKapuaException {
List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
try {
// get the configuration
KapuaLocator locator = KapuaLocator.getInstance();
DeviceBundleManagementService deviceBundleManagementService = locator.getService(DeviceBundleManagementService.class);
KapuaId scopeId = KapuaEid.parseShortId(device.getScopeId());
KapuaId id = KapuaEid.parseShortId(device.getId());
DeviceBundles bundles = deviceBundleManagementService.get(scopeId, id, null);
for (DeviceBundle bundle : bundles.getBundles()) {
GwtGroupedNVPair pair = new GwtGroupedNVPair();
pair.setId(String.valueOf(bundle.getId()));
pair.setName(bundle.getName());
pair.setStatus(toStateString(bundle));
pair.setVersion(bundle.getVersion());
pairs.add(pair);
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return new BaseListLoadResult<GwtGroupedNVPair>(pairs);
}
use of org.eclipse.kapua.service.device.management.bundle.DeviceBundle 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);
}
}
Aggregations