Search in sources :

Example 1 with DevicePackageDownloadOperation

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);
}
Also used : GwtPackageOperation(org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation) DevicePackageManagementService(org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageDownloadOperation(org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation) GwtPackageDownloadOperation(org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageDownloadOperation) ArrayList(java.util.ArrayList) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 2 with DevicePackageDownloadOperation

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageDownloadOperation(org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation) PackageResponseMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) Date(java.util.Date) PackageRequestChannel(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestChannel) DeviceCallExecutor(org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor) PackageResponsePayload(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PackageRequestMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestMessage) DevicePackageDownloadOperationImpl(org.eclipse.kapua.service.device.management.packages.model.download.internal.DevicePackageDownloadOperationImpl) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) PackageRequestPayload(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestPayload)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 DevicePackageDownloadOperation (org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GwtPackageDownloadOperation (org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageDownloadOperation)1 GwtPackageOperation (org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)1 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)1 DeviceCallExecutor (org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor)1 DevicePackageManagementService (org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService)1 PackageRequestChannel (org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestChannel)1 PackageRequestMessage (org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestMessage)1 PackageRequestPayload (org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestPayload)1 PackageResponseMessage (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage)1 PackageResponsePayload (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload)1 DevicePackageDownloadOperationImpl (org.eclipse.kapua.service.device.management.packages.model.download.internal.DevicePackageDownloadOperationImpl)1 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)1 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)1