Improve scope in device subscription view API

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent b5a86d8e79
commit c3349a89a4

@ -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, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * 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. * under the License.
*/ */
package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import java.sql.Timestamp; import java.sql.Timestamp;

@ -116,9 +116,9 @@ public interface SubscriptionManager {
* @param limitValue limit * @param limitValue limit
* @param appUUID application release UUID * @param appUUID application release UUID
* @return {@link PaginationResult} * @return {@link PaginationResult}
* @throws ApplicationManagementException if values are incorrect for offset and limit or couldn't find an * @throws ApplicationManagementException if offset or limit contains incorrect values, if it couldn't find an
* application release for given UUID or error occurred while getting device details of subscribed device ids or * application release for given UUID, if an error occurred while getting device details of subscribed device ids,
* getting subscription details of given application release UUID. * if an error occurred while getting subscription details of given application release UUID.
*/ */
PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID) PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID)
throws ApplicationManagementException; throws ApplicationManagementException;

@ -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 <T> void validateRequest(List<T> params, String subType, String action) throws BadRequestException { private <T> void validateRequest(List<T> params, String subType, String action) throws BadRequestException {
if (params.isEmpty()) { if (params.isEmpty()) {
String msg = "In order to install application release, you should provide list of subscribers. " 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. * This method perform given action (i.e APP INSTALL or APP UNINSTALL) on given set of devices.
* *
* @param deviceType Application supported device type. * @param deviceType Application supported device type.
@ -425,7 +434,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
return applicationInstallResponse; return applicationInstallResponse;
} }
/*** /**
* Filter given devices and davide given list of device into two sets, those are already application installed * Filter given devices and davide given list of device into two sets, those are already application installed
* devices and application installable devices. * devices and application installable devices.
* *
@ -470,6 +479,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
return subscribingDeviceIdHolder; 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<String> getApplicationCategories(int id) throws ApplicationManagementException { private List<String> getApplicationCategories(int id) throws ApplicationManagementException {
List<String> categories; List<String> categories;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); 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<Activity> activities, private void updateSubscriptions(int applicationReleaseId, List<Activity> activities,
SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> params, String subType, SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> params, String subType,
String action) throws ApplicationManagementException { 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) private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
@ -941,7 +979,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId);
if (applicationDTO == null) { 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); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }

@ -67,8 +67,8 @@ import java.util.List;
@org.wso2.carbon.apimgt.annotations.api.Scope( @org.wso2.carbon.apimgt.annotations.api.Scope(
name = "View Application Subscriptions", name = "View Application Subscriptions",
description = "View Application Subscriptions.", description = "View Application Subscriptions.",
key = "perm:app:subscription:view", key = "perm:admin:app:subscription:view",
permissions = {"/app-mgt/store/subscription/view"} permissions = {"/app-mgt/store/admin/subscription/view"}
) )
} }
) )

@ -18,45 +18,24 @@
package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin; 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.Log;
import org.apache.commons.logging.LogFactory; 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.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; 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.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.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.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.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 org.wso2.carbon.device.mgt.common.PaginationResult;
import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue; import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; 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. * Implementation of Subscription Management related APIs.

@ -156,6 +156,7 @@
<Scope>perm:admin:app:review:view</Scope> <Scope>perm:admin:app:review:view</Scope>
<Scope>perm:admin:app:publisher:update</Scope> <Scope>perm:admin:app:publisher:update</Scope>
<Scope>perm:admin:app:review:update</Scope> <Scope>perm:admin:app:review:update</Scope>
<Scope>perm:admin:app:subscription:view</Scope>
<Scope>perm:device-types:types</Scope> <Scope>perm:device-types:types</Scope>
<Scope>perm:enterprise:modify</Scope> <Scope>perm:enterprise:modify</Scope>
<Scope>perm:enterprise:view</Scope> <Scope>perm:enterprise:view</Scope>
@ -255,7 +256,7 @@
<Scope>perm:device:enroll</Scope> <Scope>perm:device:enroll</Scope>
<Scope>perm:geo-service:analytics-view</Scope> <Scope>perm:geo-service:analytics-view</Scope>
<Scope>perm:geo-service:alerts-manage</Scope> <Scope>perm:geo-service:alerts-manage</Scope>
<Scope>appm:rea</Scope> <Scope>appm:read</Scope>
<Scope>perm:devices:permanent-delete</Scope> <Scope>perm:devices:permanent-delete</Scope>
</Scopes> </Scopes>
<SSOConfiguration> <SSOConfiguration>

Loading…
Cancel
Save