From c3349a89a43f7add23b63070f10e2a32961d9f8d Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 21 Oct 2019 22:38:03 +0530 Subject: [PATCH] Improve scope in device subscription view API --- .../mgt/common/DeviceSubscriptionData.java | 4 +- .../common/services/SubscriptionManager.java | 6 +-- .../core/impl/SubscriptionManagerImpl.java | 44 +++++++++++++++++-- .../admin/SubscriptionManagementAdminAPI.java | 4 +- .../SubscriptionManagementAdminAPIImpl.java | 21 --------- .../main/resources/conf/application-mgt.xml | 3 +- 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceSubscriptionData.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceSubscriptionData.java index 9ce951afd0..3afac36acd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceSubscriptionData.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceSubscriptionData.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.application.mgt.common;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -15,6 +15,8 @@ package org.wso2.carbon.device.application.mgt.common;/* Copyright (c) 2019, Ent * under the License. */ +package org.wso2.carbon.device.application.mgt.common; + import org.wso2.carbon.device.mgt.common.Device; import java.sql.Timestamp; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index ca01ef2af6..b4b55e6edb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -116,9 +116,9 @@ public interface SubscriptionManager { * @param limitValue limit * @param appUUID application release UUID * @return {@link PaginationResult} - * @throws ApplicationManagementException if values are incorrect for offset and limit or couldn't find an - * application release for given UUID or error occurred while getting device details of subscribed device ids or - * getting subscription details of given application release UUID. + * @throws ApplicationManagementException if offset or limit contains incorrect values, if it couldn't find an + * application release for given UUID, if an error occurred while getting device details of subscribed device ids, + * if an error occurred while getting subscription details of given application release UUID. */ PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID) throws ApplicationManagementException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 5a31efe71d..9dc7a152db 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -316,6 +316,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + /** + * THis method is responsible to validate application install or uninstall request. + * + * @param params params could be either list of {@link DeviceIdentifier} or list of username or list of group + * names or list or role names. + * @param subType Subscription type. i.e DEVICE or USER or ROLE or GROUP + * @param action performing action. i.e Install or Uninstall + * @throws BadRequestException if incompatible data is found with app install/uninstall request. + */ private void validateRequest(List params, String subType, String action) throws BadRequestException { if (params.isEmpty()) { String msg = "In order to install application release, you should provide list of subscribers. " @@ -339,7 +348,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - /*** + /** * This method perform given action (i.e APP INSTALL or APP UNINSTALL) on given set of devices. * * @param deviceType Application supported device type. @@ -425,7 +434,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return applicationInstallResponse; } - /*** + /** * Filter given devices and davide given list of device into two sets, those are already application installed * devices and application installable devices. * @@ -470,6 +479,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return subscribingDeviceIdHolder; } + /** + * This method returns the application categories of a particular application + * + * @param id Application Id + * @return List of application categories. + * @throws ApplicationManagementException if error occurred while getting application categories from the DB. + */ private List getApplicationCategories(int id) throws ApplicationManagementException { List categories; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -529,6 +545,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + /** + * This method is responsible to update subscription data. + * + * @param applicationReleaseId Application release Id + * @param activities List of {@link Activity} + * @param subscribingDeviceIdHolder Subscribing device id holder. + * @param params subscribers. If subscription is performed via user, group or role, params is a list of + * {@link String} + * @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE + * @param action performing action. ie INSTALL or UNINSTALL> + * @throws ApplicationManagementException if error occurred while getting or updating subscription data. + */ private void updateSubscriptions(int applicationReleaseId, List activities, SubscribingDeviceIdHolder subscribingDeviceIdHolder, List params, String subType, String action) throws ApplicationManagementException { @@ -686,6 +714,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + /** + * This method constructs operation payload to install/uninstall an application. + * + * @param deviceType Device type + * @param application {@link Application} data. + * @param action Action is either ININSTALL or UNINSTALL + * @return {@link Operation} + * @throws ApplicationManagementException if unknown application type is found to generate operation payload or + * invalid action is found to generate operation payload. + */ private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action) throws ApplicationManagementException { try { @@ -941,7 +979,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.openDBConnection(); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId); if (applicationDTO == null) { - String msg = "Couldn't found an application with application release which has UUID " + appUUID; + String msg = "Couldn't find an application with application release which has UUID " + appUUID; log.error(msg); throw new NotFoundException(msg); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/SubscriptionManagementAdminAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/SubscriptionManagementAdminAPI.java index 2411ec3d40..904e6acdd6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/SubscriptionManagementAdminAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/SubscriptionManagementAdminAPI.java @@ -67,8 +67,8 @@ import java.util.List; @org.wso2.carbon.apimgt.annotations.api.Scope( name = "View Application Subscriptions", description = "View Application Subscriptions.", - key = "perm:app:subscription:view", - permissions = {"/app-mgt/store/subscription/view"} + key = "perm:admin:app:subscription:view", + permissions = {"/app-mgt/store/admin/subscription/view"} ) } ) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java index a34d050647..5dde7a6a37 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java @@ -18,45 +18,24 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse; -import org.wso2.carbon.device.application.mgt.common.BasicUserInfo; -import org.wso2.carbon.device.application.mgt.common.BasicUserInfoList; -import org.wso2.carbon.device.application.mgt.common.DeviceGroupList; -import org.wso2.carbon.device.application.mgt.common.DeviceList; -import org.wso2.carbon.device.application.mgt.common.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.RoleList; -import org.wso2.carbon.device.application.mgt.common.SubAction; -import org.wso2.carbon.device.application.mgt.common.SubscriptionType; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationOperationTaskException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; -import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; -import org.wso2.carbon.device.application.mgt.core.task.ScheduledAppSubscriptionTaskManager; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; -import org.wso2.carbon.device.application.mgt.store.api.services.SubscriptionManagementAPI; import org.wso2.carbon.device.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.PaginationResult; -import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; -import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.List; /** * Implementation of Subscription Management related APIs. diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 8baa364de2..a8f2325821 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -156,6 +156,7 @@ perm:admin:app:review:view perm:admin:app:publisher:update perm:admin:app:review:update + perm:admin:app:subscription:view perm:device-types:types perm:enterprise:modify perm:enterprise:view @@ -255,7 +256,7 @@ perm:device:enroll perm:geo-service:analytics-view perm:geo-service:alerts-manage - appm:rea + appm:read perm:devices:permanent-delete