use of org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation in project kapua by eclipse.
the class GwtDeviceManagementServiceImpl method getDownloadOperations.
public ListLoadResult<GwtPackageOperation> getDownloadOperations(String scopeShortId, String deviceShortId) throws GwtKapuaException {
List<GwtPackageOperation> gwtDeviceOperations = new ArrayList<GwtPackageOperation>();
try {
KapuaLocator locator = KapuaLocator.getInstance();
DevicePackageManagementService deviceManagementService = locator.getService(DevicePackageManagementService.class);
KapuaId scopeId = KapuaEid.parseShortId(scopeShortId);
KapuaId deviceId = KapuaEid.parseShortId(deviceShortId);
DevicePackageDownloadOperation downloadOperation = deviceManagementService.downloadStatus(scopeId, deviceId, null);
GwtPackageDownloadOperation gwtDownloadOperation = new GwtPackageDownloadOperation();
gwtDownloadOperation.setId(downloadOperation.getId().getShortId());
gwtDownloadOperation.setStatus(downloadOperation.getStatus().name());
gwtDownloadOperation.setSize(downloadOperation.getSize());
gwtDownloadOperation.setProgress(downloadOperation.getProgress());
gwtDeviceOperations.add(gwtDownloadOperation);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return new BaseListLoadResult<>(gwtDeviceOperations);
}
use of org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation in project kapua by eclipse.
the class DevicePackageManagementServiceImpl method downloadStatus.
@Override
public DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(deviceId, "deviceId");
//
// Check Access
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomain.DEVICE_MANAGEMENT, Actions.read, scopeId));
//
// Prepare the request
PackageRequestChannel packageRequestChannel = new PackageRequestChannel();
packageRequestChannel.setAppName(PackageAppProperties.APP_NAME);
packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION);
packageRequestChannel.setMethod(KapuaMethod.READ);
packageRequestChannel.setPackageResource(PackageResource.DOWNLOAD);
PackageRequestPayload packageRequestPayload = new PackageRequestPayload();
PackageRequestMessage packageRequestMessage = new PackageRequestMessage();
packageRequestMessage.setScopeId(scopeId);
packageRequestMessage.setDeviceId(deviceId);
packageRequestMessage.setCapturedOn(new Date());
packageRequestMessage.setPayload(packageRequestPayload);
packageRequestMessage.setChannel(packageRequestChannel);
//
// Do get
@SuppressWarnings({ "rawtypes", "unchecked" }) DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout);
PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send();
//
// Parse the response
PackageResponsePayload responsePayload = responseMessage.getPayload();
DevicePackageDownloadOperation downloadOperation = new DevicePackageDownloadOperationImpl();
downloadOperation.setId(responsePayload.getPackageDownloadOperationId());
downloadOperation.setStatus(responsePayload.getPackageDownloadOperationStatus());
downloadOperation.setSize(responsePayload.getPackageDownloadOperationSize());
downloadOperation.setProgress(responsePayload.getPackageDownloadOperationProgress());
//
// Create event
DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, deviceId, responseMessage.getReceivedOn(), PackageAppProperties.APP_NAME.getValue());
deviceEventCreator.setPosition(responseMessage.getPosition());
deviceEventCreator.setSentOn(responseMessage.getSentOn());
deviceEventCreator.setAction(KapuaMethod.READ);
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());
deviceEventService.create(deviceEventCreator);
return downloadOperation;
}
Aggregations