From 74c4f1004af175297feddb149aad76d24fed0636 Mon Sep 17 00:00:00 2001 From: MalshaPiumini Date: Tue, 16 Mar 2021 14:39:02 +0530 Subject: [PATCH 1/5] Device search in store uninstall modal --- .../common/services/SubscriptionManager.java | 6 ++-- .../core/impl/SubscriptionManagerImpl.java | 15 ++++---- .../services/SubscriptionManagementAPI.java | 23 ++++++++++++ .../impl/SubscriptionManagementAPIImpl.java | 17 +++++++-- .../carbon/device/mgt/core/dao/DeviceDAO.java | 13 ++++--- .../dao/impl/device/GenericDeviceDAOImpl.java | 36 ++++++++++++++++--- .../dao/impl/device/OracleDeviceDAOImpl.java | 34 ++++++++++++++++-- .../impl/device/PostgreSQLDeviceDAOImpl.java | 34 ++++++++++++++++-- .../impl/device/SQLServerDeviceDAOImpl.java | 32 +++++++++++++++-- .../DeviceManagementProviderService.java | 9 +++-- .../DeviceManagementProviderServiceImpl.java | 6 ++-- 11 files changed, 183 insertions(+), 42 deletions(-) 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 9d9e94c183..c1c0155087 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 @@ -22,6 +22,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDT import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.SubscriptionManagementException; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.util.List; @@ -127,13 +128,12 @@ public interface SubscriptionManager { * This method used to get the app id ,device ids and pass them to DM service method. * * @param appUUID UUID of the application release. - * @param offsetValue offset value for get paginated request. - * @param limitValue limit value for get paginated request. + * @param request paginated request object. * @param status status of the devices. * @return deviceDetails - device details for given application release. * @throws {@link ApplicationManagementException} Exception of the application management */ - PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, + PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, List status) 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 19008cbb0d..c81b4aa125 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 @@ -65,10 +65,7 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.HelperUtil; import org.wso2.carbon.device.application.mgt.core.util.OAuthUtils; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.MDMAppConstants; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.App; import org.wso2.carbon.device.mgt.common.app.mgt.MobileAppTypes; import org.wso2.carbon.device.mgt.common.app.mgt.android.CustomApplication; @@ -88,7 +85,6 @@ import org.wso2.carbon.device.mgt.core.util.MDMIOSOperationUtil; import org.wso2.carbon.device.mgt.core.util.MDMWindowsOperationUtil; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.device.mgt.common.PaginationResult; import javax.ws.rs.core.MediaType; import java.io.BufferedReader; @@ -1223,7 +1219,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, List status) + public PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, List status) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); DeviceManagementProviderService deviceManagementProviderService = HelperUtil @@ -1262,8 +1258,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } //pass the device id list to device manager service method try { - PaginationResult deviceDetails = deviceManagementProviderService - .getAppSubscribedDevices(offsetValue, limitValue, deviceIdList, status); + PaginationResult deviceDetails = deviceManagementProviderService.getAppSubscribedDevices + (request, deviceIdList, status); if (deviceDetails == null) { String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList; @@ -1344,6 +1340,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { @Override public PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID) throws ApplicationManagementException { + PaginationRequest request = new PaginationRequest(offsetValue, limitValue); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); @@ -1378,7 +1375,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { try { //pass the device id list to device manager service method PaginationResult paginationResult = deviceManagementProviderService - .getAppSubscribedDevices(offsetValue, limitValue, deviceIdList, null); + .getAppSubscribedDevices(request, deviceIdList, null); List deviceSubscriptionDataList = new ArrayList<>(); if (!paginationResult.getData().isEmpty()) { 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/SubscriptionManagementAPI.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/SubscriptionManagementAPI.java index 75a4522d68..871066e39b 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/SubscriptionManagementAPI.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/SubscriptionManagementAPI.java @@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import javax.validation.Valid; +import javax.validation.constraints.Size; import javax.ws.rs.Path; import javax.ws.rs.Consumes; import javax.ws.rs.Produces; @@ -337,6 +338,28 @@ public interface SubscriptionManagementAPI { response = ErrorResponse.class) }) Response getAppInstalledDevices( + @ApiParam( + name = "name", + value = "The device name. For example, Nexus devices can have names, suhc as shamu, bullhead or angler.", + required = false) + @Size(max = 45) + String name, + @ApiParam( + name = "user", + value = "The username of the owner of the device.", + required = false) + @QueryParam("user") + String user, + @ApiParam( + name = "ownership", + allowableValues = "BYOD, COPE", + value = "Provide the ownership status of the device. The following values can be assigned:\n" + + "- BYOD: Bring Your Own Device\n" + + "- COPE: Corporate-Owned, Personally-Enabled", + required = false) + @QueryParam("ownership") + @Size(max = 45) + String ownership, @ApiParam( name="uuid", value="uuid of the application release.", 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java index 984f689d07..ab7905e1d0 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java @@ -33,6 +33,7 @@ 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.RoleList; import org.wso2.carbon.device.application.mgt.common.DeviceGroupList; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; @@ -273,6 +274,9 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Produces("application/json") @Path("/{uuid}/devices") public Response getAppInstalledDevices( + @QueryParam("name") String name, + @QueryParam("user") String user, + @QueryParam("ownership") String ownership, @PathParam("uuid") String uuid, @DefaultValue("0") @QueryParam("offset") int offset, @@ -281,8 +285,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @QueryParam("status") List status) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - PaginationResult subscribedDeviceDetails = subscriptionManager - .getAppInstalledDevices(offset, limit, uuid, status); + PaginationRequest request = new PaginationRequest(offset, limit); + if (name != null && !name.isEmpty()) { + request.setDeviceName(name); + } + if (user != null && !user.isEmpty()) { + request.setOwner(user); + } + if (ownership != null && !ownership.isEmpty()) { + request.setOwnership(ownership); + } + PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid, status); DeviceList devices = new DeviceList(); devices.setList((List) subscribedDeviceDetails.getData()); devices.setCount(subscribedDeviceDetails.getRecordsTotal()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 38ef50a923..620faf898f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -651,16 +651,15 @@ public interface DeviceDAO { /** * This method is used to get the details of subscribed devices. * - * @param deviceIds device ids of the subscribed devices. - * @param tenantId Id of the current tenant. - * @param offsetValue offset value for get paginated request. - * @param limitValue limit value for get paginated request. - * @param status status of the devices. + * @param deviceIds device ids of the subscribed devices. + * @param tenantId Id of the current tenant. + * @param request paginated request object. + * @param status status of the devices. * @return devices - subscribed device details list * @throws DeviceManagementDAOException if connections establishment fails. */ - List getSubscribedDevices(int offsetValue, int limitValue, List deviceIds, - int tenantId, List status) throws DeviceManagementDAOException; + List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, + List status) throws DeviceManagementDAOException; /** * @param deviceIds device ids of the subscribed devices. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 07a2882b3d..f7bbfac380 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -877,16 +877,24 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, + List status) throws DeviceManagementDAOException { Connection conn; - + int limitValue = request.getRowCount(); + int offsetValue = request.getStartIndex(); + String name = request.getDeviceName(); + String user = request.getOwner(); + String ownership = request.getOwnership(); try { conn = this.getConnection(); int index = 1; boolean isStatusProvided = false; + boolean isDeviceNameProvided = false; + boolean isOwnerProvided = false; + boolean isOwnershipProvided = false; + StringJoiner joiner = new StringJoiner(",", "SELECT " + "DM_DEVICE.ID AS DEVICE_ID, " @@ -914,6 +922,18 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); + if (name != null && !name.isEmpty()) { + query += " AND DM_DEVICE.NAME LIKE ?"; + isDeviceNameProvided = true; + } + if (ownership != null && !ownership.isEmpty()) { + query += " AND e.OWNERSHIP = ?"; + isOwnershipProvided = true; + } + if (user != null && !user.isEmpty()) { + query += " AND e.OWNER = ?"; + isOwnerProvided = true; + } if (status != null && !status.isEmpty()) { query += buildStatusQuery(status); isStatusProvided = true; @@ -926,8 +946,16 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { for (Integer deviceId : deviceIds) { ps.setObject(index++, deviceId); } - ps.setInt(index++, tenantId); + if (isDeviceNameProvided) { + ps.setString(index++, name + "%"); + } + if (isOwnershipProvided) { + ps.setString(index++, ownership); + } + if (isOwnerProvided) { + ps.setString(index++, user); + } if (isStatusProvided) { for (String deviceStatus : status) { ps.setString(index++, deviceStatus); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index b143136ef9..201a0ba169 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -847,16 +847,23 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, + List status) throws DeviceManagementDAOException { Connection conn; - + int limitValue = request.getRowCount(); + int offsetValue = request.getStartIndex(); + String name = request.getDeviceName(); + String user = request.getOwner(); + String ownership = request.getOwnership(); try { conn = this.getConnection(); int index = 1; boolean isStatusProvided = false; + boolean isDeviceNameProvided = false; + boolean isOwnerProvided = false; + boolean isOwnershipProvided = false; StringJoiner joiner = new StringJoiner(",", "SELECT " + "DM_DEVICE.ID AS DEVICE_ID, " @@ -884,6 +891,18 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); + if (name != null && !name.isEmpty()) { + query += " AND DM_DEVICE.NAME LIKE ?"; + isDeviceNameProvided = true; + } + if (ownership != null && !ownership.isEmpty()) { + query += " AND e.OWNERSHIP = ?"; + isOwnershipProvided = true; + } + if (user != null && !user.isEmpty()) { + query += " AND e.OWNER = ?"; + isOwnerProvided = true; + } if (status != null && !status.isEmpty()) { query += buildStatusQuery(status); isStatusProvided = true; @@ -898,6 +917,15 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); + if (isDeviceNameProvided) { + ps.setString(index++, name + "%"); + } + if (isOwnershipProvided) { + ps.setString(index++, ownership); + } + if (isOwnerProvided) { + ps.setString(index++, user); + } if (isStatusProvided) { for (String deviceStatus : status) { ps.setString(index++, deviceStatus); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 4a7560f9f3..9234ff6f43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -827,16 +827,23 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, + List status) throws DeviceManagementDAOException { Connection conn; - + int limitValue = request.getRowCount(); + int offsetValue = request.getStartIndex(); + String name = request.getDeviceName(); + String user = request.getOwner(); + String ownership = request.getOwnership(); try { conn = this.getConnection(); int index = 1; boolean isStatusProvided = false; + boolean isDeviceNameProvided = false; + boolean isOwnerProvided = false; + boolean isOwnershipProvided = false; StringJoiner joiner = new StringJoiner(",", "SELECT " + "DM_DEVICE.ID AS DEVICE_ID, " @@ -864,6 +871,18 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); + if (name != null && !name.isEmpty()) { + query += " AND DM_DEVICE.NAME LIKE ?"; + isDeviceNameProvided = true; + } + if (ownership != null && !ownership.isEmpty()) { + query += " AND e.OWNERSHIP = ?"; + isOwnershipProvided = true; + } + if (user != null && !user.isEmpty()) { + query += " AND e.OWNER = ?"; + isOwnerProvided = true; + } if (status != null && !status.isEmpty()) { query += buildStatusQuery(status); isStatusProvided = true; @@ -878,6 +897,15 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); + if (isDeviceNameProvided) { + ps.setString(index++, name + "%"); + } + if (isOwnershipProvided) { + ps.setString(index++, ownership); + } + if (isOwnerProvided) { + ps.setString(index++, user); + } if (isStatusProvided) { for (String deviceStatus : status) { ps.setString(index++, deviceStatus); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index 11112c4655..a27191fe32 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -693,16 +693,23 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(int offsetValue, int limitValue, + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { Connection conn; - + int limitValue = request.getRowCount(); + int offsetValue = request.getStartIndex(); + String name = request.getDeviceName(); + String user = request.getOwner(); + String ownership = request.getOwnership(); try { conn = this.getConnection(); int index = 1; boolean isStatusProvided = false; + boolean isDeviceNameProvided = false; + boolean isOwnerProvided = false; + boolean isOwnershipProvided = false; StringJoiner joiner = new StringJoiner(",", "SELECT " + "DM_DEVICE.ID AS DEVICE_ID, " @@ -730,6 +737,18 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); + if (name != null && !name.isEmpty()) { + query += " AND DM_DEVICE.NAME LIKE ?"; + isDeviceNameProvided = true; + } + if (ownership != null && !ownership.isEmpty()) { + query += " AND e.OWNERSHIP = ?"; + isOwnershipProvided = true; + } + if (user != null && !user.isEmpty()) { + query += " AND e.OWNER = ?"; + isOwnerProvided = true; + } if (status != null && !status.isEmpty()) { query += buildStatusQuery(status); isStatusProvided = true; @@ -744,6 +763,15 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); + if (isDeviceNameProvided) { + ps.setString(index++, name + "%"); + } + if (isOwnershipProvided) { + ps.setString(index++, ownership); + } + if (isOwnerProvided) { + ps.setString(index++, user); + } if (isStatusProvided) { for (String deviceStatus : status) { ps.setString(index++, deviceStatus); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index fb3dd19527..d5f31c1546 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -905,14 +905,13 @@ public interface DeviceManagementProviderService { * This method retrieves a list of subscribed devices. * * @param devicesIds devices ids of the subscribed devices. - * @param offsetValue offset value for get paginated request. - * @param limitValue limit value for get paginated request. - * @param status status of the devices. + * @param request paginated request object. + * @param status status of the devices. * @return {@link PaginationResult} * @throws DeviceManagementException if any service level or DAO level error occurs. */ - PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue, - List devicesIds, List status) throws DeviceManagementException; + PaginationResult getAppSubscribedDevices(PaginationRequest request, List devicesIds, List status) + throws DeviceManagementException; /** * This method is used to get a list of applications installed in all enrolled devices diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 7456111973..343acf2602 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -4156,9 +4156,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue, List devicesIds, + public PaginationResult getAppSubscribedDevices(PaginationRequest request, List devicesIds, List status) throws DeviceManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) { log.debug("Getting all devices details for device ids: " + devicesIds); @@ -4167,8 +4166,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List subscribedDeviceDetails; try { DeviceManagementDAOFactory.openConnection(); - subscribedDeviceDetails = deviceDAO - .getSubscribedDevices(offsetValue, limitValue, devicesIds, tenantId, status); + subscribedDeviceDetails = deviceDAO.getSubscribedDevices(request, devicesIds, tenantId, status); if (subscribedDeviceDetails.isEmpty()) { paginationResult.setData(new ArrayList<>()); paginationResult.setRecordsFiltered(0); From c2940a4568b55d0003f26b6d87447c92a9ee38a0 Mon Sep 17 00:00:00 2001 From: MalshaPiumini Date: Wed, 17 Mar 2021 15:25:02 +0530 Subject: [PATCH 2/5] Device search in store subscription details page --- .../common/services/SubscriptionManager.java | 7 +-- .../mgt/core/dao/SubscriptionDAO.java | 2 +- .../GenericSubscriptionDAOImpl.java | 11 +++- .../mgt/core/impl/ApplicationManagerImpl.java | 4 +- .../core/impl/SubscriptionManagerImpl.java | 13 ++--- .../admin/SubscriptionManagementAdminAPI.java | 21 ++++++++ .../impl/SubscriptionManagementAPIImpl.java | 32 ++++++++++++ .../SubscriptionManagementAdminAPIImpl.java | 51 ++++++++++++++++++- 8 files changed, 127 insertions(+), 14 deletions(-) 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 c1c0155087..1073015a73 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 @@ -152,14 +152,15 @@ public interface SubscriptionManager { /** * This method is responsible to provide application subscription data for given application release UUID. * - * @param offsetValue offset - * @param limitValue limit + * @param request paginated request object. + * @param status status of the devices. + * @param actionStatus status of the operation. * @param appUUID application release UUID * @return {@link PaginationResult} * @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) + PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, List status,String actionStatus) 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/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 4b99420e50..0dbd746912 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -81,7 +81,7 @@ public interface SubscriptionDAO { void addGroupSubscriptions(int tenantId, String subscribedBy, List groups, int releaseId, String action) throws ApplicationManagementDAOException; - List getDeviceSubscriptions(int appReleaseId, int tenantId) throws + List getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws ApplicationManagementDAOException; Map getDeviceSubscriptions(List deviceIds, int appReleaseId, int tenantId) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 576eec9a6c..96a2746022 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -332,12 +332,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getDeviceSubscriptions(int appReleaseId, int tenantId) throws + public List getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Getting device subscriptions for the application release id " + appReleaseId + " from the database"); } + boolean isActionStatusProvided = false; String sql = "SELECT " + "DS.ID AS ID, " + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, " @@ -350,11 +351,19 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "DS.DM_DEVICE_ID AS DEVICE_ID " + "FROM AP_DEVICE_SUBSCRIPTION DS " + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?"; + + if (actionStatus != null && !actionStatus.isEmpty()) { + sql += " AND DS.STATUS= ?"; + isActionStatusProvided = true; + } try { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, appReleaseId); stmt.setInt(2, tenantId); + if(isActionStatusProvided){ + stmt.setString(3, actionStatus); + } try (ResultSet rs = stmt.executeQuery()) { if (log.isDebugEnabled()) { log.debug("Successfully retrieved device subscriptions for application release id " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 2cebd98c61..80706aef41 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -1445,7 +1445,7 @@ ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ForbiddenException(msg); } - if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId).isEmpty()) { + if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null).isEmpty()) { String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + " either subscribed to device/s or it had subscribed to device/s. Therefore you are not " + "permitted to delete the application release."; @@ -1580,7 +1580,7 @@ ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.beginDBTransaction(); List deviceSubscriptionDTOS = subscriptionDAO - .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); + .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null); if (!deviceSubscriptionDTOS.isEmpty()) { String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + " either subscribed to device/s or it had subscribed to device/s. Therefore you " 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 c81b4aa125..d11fb4090f 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 @@ -377,7 +377,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (applicationDTO != null) { List deviceSubscriptionDTOS = this.subscriptionDAO .getDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), - tenantId); + tenantId, null); AtomicBoolean isAppSubscribable = new AtomicBoolean(true); for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) { @@ -1231,7 +1231,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); List deviceSubscriptionDTOS = subscriptionDAO - .getDeviceSubscriptions(applicationReleaseId, tenantId); + .getDeviceSubscriptions(applicationReleaseId, tenantId, null); if (deviceSubscriptionDTOS.isEmpty()) { PaginationResult paginationResult = new PaginationResult(); paginationResult.setData(new ArrayList<>()); @@ -1338,9 +1338,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID) + public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, List status,String actionStatus) throws ApplicationManagementException { - PaginationRequest request = new PaginationRequest(offsetValue, limitValue); + int limitValue = request.getRowCount(); + int offsetValue = request.getStartIndex(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); @@ -1362,7 +1363,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); List deviceSubscriptionDTOS = subscriptionDAO - .getDeviceSubscriptions(applicationReleaseId, tenantId); + .getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus); if (deviceSubscriptionDTOS.isEmpty()) { PaginationResult paginationResult = new PaginationResult(); paginationResult.setData(new ArrayList<>()); @@ -1375,7 +1376,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { try { //pass the device id list to device manager service method PaginationResult paginationResult = deviceManagementProviderService - .getAppSubscribedDevices(request, deviceIdList, null); + .getAppSubscribedDevices(request, deviceIdList, status); List deviceSubscriptionDataList = new ArrayList<>(); if (!paginationResult.getData().isEmpty()) { 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 7c47b1f7cf..2cb9d63b21 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 @@ -31,6 +31,7 @@ import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; +import javax.validation.constraints.Size; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -111,6 +112,26 @@ public interface SubscriptionManagementAdminAPI { response = ErrorResponse.class) }) Response getAppInstalledDevices( + @ApiParam( + name = "name", + value = "The device name. For example, Nexus devices can have names, suhc as shamu, bullhead or angler.", + required = false) + @Size(max = 45) + String name, + @ApiParam( + name = "user", + value = "The username of the owner of the device.", + required = false) + @QueryParam("user") + String user, + @ApiParam( + name = "actionStatus", + value = "Provide the action status details") + @QueryParam("actionStatus") String actionStatus, + @ApiParam( + name = "status", + value = "Provide the device status details, such as active or inactive.") + @QueryParam("status") List status, @ApiParam( name = "uuid", value = "uuid of the application release.", 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java index ab7905e1d0..6d13e94a6f 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java @@ -295,6 +295,38 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ if (ownership != null && !ownership.isEmpty()) { request.setOwnership(ownership); } +// if (status != null && !status.isEmpty()) { +// boolean isStatusEmpty = true; +// for (String statusString : status){ +// if (StringUtils.isNotBlank(statusString)){ +// isStatusEmpty = false; +// break; +// } +// } +// if (!isStatusEmpty) { +// for (String status_ : status) { +// switch (status_) { +// case "ACTIVE": +// case "INACTIVE": +// case "UNCLAIMED": +// case "UNREACHABLE": +// case "SUSPENDED": +// case "DISENROLLMENT_REQUESTED": +// case "REMOVED": +// case "BLOCKED": +// case "CREATED": +// break; +// default: +// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + +// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + +// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; +// log.error(msg); +// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); +// } +// } +// request.setStatusList(status); +// } +// } PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid, status); DeviceList devices = new DeviceList(); devices.setList((List) subscribedDeviceDetails.getData()); 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 2462556570..56c7e94646 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,16 +18,21 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin; +import io.swagger.annotations.ApiParam; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpStatus; 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.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import javax.validation.constraints.Size; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -36,6 +41,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import java.util.List; /** * Implementation of Subscription Management related APIs. @@ -51,6 +57,10 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen @Produces("application/json") @Path("/{uuid}") public Response getAppInstalledDevices( + @QueryParam("name") String name, + @QueryParam("user") String user, + @QueryParam("actionStatus") String actionStatus, + @QueryParam("status") List status, @PathParam("uuid") String uuid, @DefaultValue("0") @QueryParam("offset") int offset, @@ -58,9 +68,48 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen @QueryParam("limit") int limit) { try { + PaginationRequest request = new PaginationRequest(offset, limit); + if (name != null && !name.isEmpty()) { + request.setDeviceName(name); + } + if (user != null && !user.isEmpty()) { + request.setOwner(user); + } +// if (status != null && !status.isEmpty()) { +// boolean isStatusEmpty = true; +// for (String statusString : status){ +// if (StringUtils.isNotBlank(statusString)){ +// isStatusEmpty = false; +// break; +// } +// } +// if (!isStatusEmpty) { +// for (String status_ : status) { +// switch (status_) { +// case "ACTIVE": +// case "INACTIVE": +// case "UNCLAIMED": +// case "UNREACHABLE": +// case "SUSPENDED": +// case "DISENROLLMENT_REQUESTED": +// case "REMOVED": +// case "BLOCKED": +// case "CREATED": +// break; +// default: +// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + +// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + +// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; +// log.error(msg); +// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); +// } +// } +// request.setStatusList(status); +// } +// } SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); PaginationResult subscriptionData = subscriptionManager - .getAppSubscriptionDetails(offset, limit, uuid); + .getAppSubscriptionDetails(request, uuid, status, actionStatus); return Response.status(Response.Status.OK).entity(subscriptionData).build(); } catch (NotFoundException e) { String msg = "Application with application release UUID: " + uuid + " is not found"; From 605168e770488c7b7890d63e3fbe772f2f382a48 Mon Sep 17 00:00:00 2001 From: MalshaPiumini Date: Wed, 17 Mar 2021 18:37:14 +0530 Subject: [PATCH 3/5] Code modified --- .../common/services/SubscriptionManager.java | 6 +- .../core/impl/SubscriptionManagerImpl.java | 10 +-- .../impl/SubscriptionManagementAPIImpl.java | 66 +++++++------- .../SubscriptionManagementAdminAPIImpl.java | 89 ++++++++++++------- .../carbon/device/mgt/core/dao/DeviceDAO.java | 5 +- .../dao/impl/device/GenericDeviceDAOImpl.java | 4 +- .../dao/impl/device/OracleDeviceDAOImpl.java | 4 +- .../impl/device/PostgreSQLDeviceDAOImpl.java | 4 +- .../impl/device/SQLServerDeviceDAOImpl.java | 4 +- .../DeviceManagementProviderService.java | 2 +- .../DeviceManagementProviderServiceImpl.java | 7 +- 11 files changed, 109 insertions(+), 92 deletions(-) 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 1073015a73..5951433c14 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 @@ -133,8 +133,7 @@ public interface SubscriptionManager { * @return deviceDetails - device details for given application release. * @throws {@link ApplicationManagementException} Exception of the application management */ - PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, - List status) throws ApplicationManagementException; + PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID) throws ApplicationManagementException; /*** * This method used to get category details. @@ -153,7 +152,6 @@ public interface SubscriptionManager { * This method is responsible to provide application subscription data for given application release UUID. * * @param request paginated request object. - * @param status status of the devices. * @param actionStatus status of the operation. * @param appUUID application release UUID * @return {@link PaginationResult} @@ -161,6 +159,6 @@ public interface SubscriptionManager { * 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(PaginationRequest request, String appUUID, List status,String actionStatus) + PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus) 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 d11fb4090f..94559782b3 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 @@ -1219,7 +1219,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, List status) + public PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); DeviceManagementProviderService deviceManagementProviderService = HelperUtil @@ -1259,7 +1259,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { //pass the device id list to device manager service method try { PaginationResult deviceDetails = deviceManagementProviderService.getAppSubscribedDevices - (request, deviceIdList, status); + (request, deviceIdList); if (deviceDetails == null) { String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList; @@ -1338,7 +1338,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, List status,String actionStatus) + public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus) throws ApplicationManagementException { int limitValue = request.getRowCount(); int offsetValue = request.getStartIndex(); @@ -1375,8 +1375,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { .collect(Collectors.toList()); try { //pass the device id list to device manager service method - PaginationResult paginationResult = deviceManagementProviderService - .getAppSubscribedDevices(request, deviceIdList, status); + PaginationResult paginationResult = deviceManagementProviderService.getAppSubscribedDevices + (request, deviceIdList); List deviceSubscriptionDataList = new ArrayList<>(); if (!paginationResult.getData().isEmpty()) { 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java index 6d13e94a6f..820e6bcd5c 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java @@ -295,39 +295,39 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ if (ownership != null && !ownership.isEmpty()) { request.setOwnership(ownership); } -// if (status != null && !status.isEmpty()) { -// boolean isStatusEmpty = true; -// for (String statusString : status){ -// if (StringUtils.isNotBlank(statusString)){ -// isStatusEmpty = false; -// break; -// } -// } -// if (!isStatusEmpty) { -// for (String status_ : status) { -// switch (status_) { -// case "ACTIVE": -// case "INACTIVE": -// case "UNCLAIMED": -// case "UNREACHABLE": -// case "SUSPENDED": -// case "DISENROLLMENT_REQUESTED": -// case "REMOVED": -// case "BLOCKED": -// case "CREATED": -// break; -// default: -// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + -// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + -// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; -// log.error(msg); -// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); -// } -// } -// request.setStatusList(status); -// } -// } - PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid, status); + if (status != null && !status.isEmpty()) { + boolean isStatusEmpty = true; + for (String statusString : status) { + if (StringUtils.isNotBlank(statusString)) { + isStatusEmpty = false; + break; + } + } + if (!isStatusEmpty) { + for (String status_ : status) { + switch (status_) { + case "ACTIVE": + case "INACTIVE": + case "UNCLAIMED": + case "UNREACHABLE": + case "SUSPENDED": + case "DISENROLLMENT_REQUESTED": + case "REMOVED": + case "BLOCKED": + case "CREATED": + break; + default: + String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + + "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + + "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + } + request.setStatusList(status); + } + } + PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid); DeviceList devices = new DeviceList(); devices.setList((List) subscribedDeviceDetails.getData()); devices.setCount(subscribedDeviceDetails.getRecordsTotal()); 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 56c7e94646..5536fc46d8 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 @@ -75,41 +75,62 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen if (user != null && !user.isEmpty()) { request.setOwner(user); } -// if (status != null && !status.isEmpty()) { -// boolean isStatusEmpty = true; -// for (String statusString : status){ -// if (StringUtils.isNotBlank(statusString)){ -// isStatusEmpty = false; -// break; -// } -// } -// if (!isStatusEmpty) { -// for (String status_ : status) { -// switch (status_) { -// case "ACTIVE": -// case "INACTIVE": -// case "UNCLAIMED": -// case "UNREACHABLE": -// case "SUSPENDED": -// case "DISENROLLMENT_REQUESTED": -// case "REMOVED": -// case "BLOCKED": -// case "CREATED": -// break; -// default: -// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + -// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + -// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; -// log.error(msg); -// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); -// } -// } -// request.setStatusList(status); -// } -// } + if (status != null && !status.isEmpty()) { + boolean isStatusEmpty = true; + for (String statusString : status) { + if (StringUtils.isNotBlank(statusString)) { + isStatusEmpty = false; + break; + } + } + if (!isStatusEmpty) { + for (String status_ : status) { + switch (status_) { + case "ACTIVE": + case "INACTIVE": + case "UNCLAIMED": + case "UNREACHABLE": + case "SUSPENDED": + case "DISENROLLMENT_REQUESTED": + case "REMOVED": + case "BLOCKED": + case "CREATED": + break; + default: + String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types " + + "are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + + "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + } + request.setStatusList(status); + } + } + + if (actionStatus != null && !actionStatus.isEmpty()) { + if (StringUtils.isNotBlank(actionStatus)) { + switch (actionStatus) { + case "PENDING": + case "ERROR": + case "IN_PROGRESS": + case "NOTNOW": + case "COMPLETED": + case "REPEATED": + break; + default: + String msg = "Invalid enrollment action status type: " + actionStatus + ". " + + "\nValid action status types are PENDING | ERROR | IN_PROGRESS | NOTNOW | " + + "COMPLETED | REPEATED"; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + } + } + SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - PaginationResult subscriptionData = subscriptionManager - .getAppSubscriptionDetails(request, uuid, status, actionStatus); + PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails + (request, uuid, actionStatus); return Response.status(Response.Status.OK).entity(subscriptionData).build(); } catch (NotFoundException e) { String msg = "Application with application release UUID: " + uuid + " is not found"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 620faf898f..82aded2490 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -654,12 +654,11 @@ public interface DeviceDAO { * @param deviceIds device ids of the subscribed devices. * @param tenantId Id of the current tenant. * @param request paginated request object. - * @param status status of the devices. * @return devices - subscribed device details list * @throws DeviceManagementDAOException if connections establishment fails. */ - List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, - List status) throws DeviceManagementDAOException; + List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId) + throws DeviceManagementDAOException; /** * @param deviceIds device ids of the subscribed devices. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index f7bbfac380..0644fe56b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -877,12 +877,12 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, - List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId) throws DeviceManagementDAOException { Connection conn; int limitValue = request.getRowCount(); int offsetValue = request.getStartIndex(); + List status = request.getStatusList(); String name = request.getDeviceName(); String user = request.getOwner(); String ownership = request.getOwnership(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index 201a0ba169..07cee11440 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -847,12 +847,12 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, - List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId) throws DeviceManagementDAOException { Connection conn; int limitValue = request.getRowCount(); int offsetValue = request.getStartIndex(); + List status = request.getStatusList(); String name = request.getDeviceName(); String user = request.getOwner(); String ownership = request.getOwnership(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 9234ff6f43..20b0364253 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -827,12 +827,12 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId, - List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId) throws DeviceManagementDAOException { Connection conn; int limitValue = request.getRowCount(); int offsetValue = request.getStartIndex(); + List status = request.getStatusList(); String name = request.getDeviceName(); String user = request.getOwner(); String ownership = request.getOwnership(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index a27191fe32..77b561dde7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -693,12 +693,12 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getSubscribedDevices(PaginationRequest request, - List deviceIds, int tenantId, List status) + public List getSubscribedDevices(PaginationRequest request, List deviceIds, int tenantId) throws DeviceManagementDAOException { Connection conn; int limitValue = request.getRowCount(); int offsetValue = request.getStartIndex(); + List status = request.getStatusList(); String name = request.getDeviceName(); String user = request.getOwner(); String ownership = request.getOwnership(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index d5f31c1546..157fed7c5d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -910,7 +910,7 @@ public interface DeviceManagementProviderService { * @return {@link PaginationResult} * @throws DeviceManagementException if any service level or DAO level error occurs. */ - PaginationResult getAppSubscribedDevices(PaginationRequest request, List devicesIds, List status) + PaginationResult getAppSubscribedDevices(PaginationRequest request, List devicesIds) throws DeviceManagementException; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 343acf2602..4959c282c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -4156,8 +4156,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getAppSubscribedDevices(PaginationRequest request, List devicesIds, - List status) throws DeviceManagementException { + public PaginationResult getAppSubscribedDevices(PaginationRequest request, List devicesIds) throws DeviceManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) { log.debug("Getting all devices details for device ids: " + devicesIds); @@ -4166,14 +4165,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List subscribedDeviceDetails; try { DeviceManagementDAOFactory.openConnection(); - subscribedDeviceDetails = deviceDAO.getSubscribedDevices(request, devicesIds, tenantId, status); + subscribedDeviceDetails = deviceDAO.getSubscribedDevices(request, devicesIds, tenantId); if (subscribedDeviceDetails.isEmpty()) { paginationResult.setData(new ArrayList<>()); paginationResult.setRecordsFiltered(0); paginationResult.setRecordsTotal(0); return paginationResult; } - int count = deviceDAO.getSubscribedDeviceCount(devicesIds, tenantId, status); + int count = deviceDAO.getSubscribedDeviceCount(devicesIds, tenantId, request.getStatusList()); paginationResult.setRecordsFiltered(count); paginationResult.setRecordsTotal(count); } catch (DeviceManagementDAOException e) { From 645fc43136ab2eb2cfee7d2f04e38dcc9aaf4df0 Mon Sep 17 00:00:00 2001 From: MalshaPiumini Date: Thu, 18 Mar 2021 17:20:30 +0530 Subject: [PATCH 4/5] Added validations --- .../common/services/SubscriptionManager.java | 1 - .../impl/SubscriptionManagementAPIImpl.java | 26 +---- .../SubscriptionManagementAdminAPIImpl.java | 43 +------- .../impl/util/RequestValidationUtil.java | 102 ++++++++++++++++++ .../mgt/store/api/util/Constants.java | 101 +++++++++++++++++ 5 files changed, 211 insertions(+), 62 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/util/RequestValidationUtil.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/util/Constants.java 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 5951433c14..12ca873701 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 @@ -129,7 +129,6 @@ public interface SubscriptionManager { * * @param appUUID UUID of the application release. * @param request paginated request object. - * @param status status of the devices. * @return deviceDetails - device details for given application release. * @throws {@link ApplicationManagementException} Exception of the application management */ 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java index 820e6bcd5c..ff6144dcb5 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java @@ -33,6 +33,7 @@ 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.RoleList; import org.wso2.carbon.device.application.mgt.common.DeviceGroupList; +import org.wso2.carbon.device.application.mgt.store.api.services.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; @@ -293,6 +294,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ request.setOwner(user); } if (ownership != null && !ownership.isEmpty()) { + RequestValidationUtil.validateOwnershipType(ownership); request.setOwnership(ownership); } if (status != null && !status.isEmpty()) { @@ -304,26 +306,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ } } if (!isStatusEmpty) { - for (String status_ : status) { - switch (status_) { - case "ACTIVE": - case "INACTIVE": - case "UNCLAIMED": - case "UNREACHABLE": - case "SUSPENDED": - case "DISENROLLMENT_REQUESTED": - case "REMOVED": - case "BLOCKED": - case "CREATED": - break; - default: - String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + - "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + - "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; - log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } - } + RequestValidationUtil.validateStatus(status); request.setStatusList(status); } } @@ -337,8 +320,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for getting application which has UUID: " + uuid - + ". Hence verify the payload"; + String msg = "User requested details are not valid"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { 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 5536fc46d8..4474ddaa81 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 @@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI; +import org.wso2.carbon.device.application.mgt.store.api.services.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; @@ -84,50 +85,15 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen } } if (!isStatusEmpty) { - for (String status_ : status) { - switch (status_) { - case "ACTIVE": - case "INACTIVE": - case "UNCLAIMED": - case "UNREACHABLE": - case "SUSPENDED": - case "DISENROLLMENT_REQUESTED": - case "REMOVED": - case "BLOCKED": - case "CREATED": - break; - default: - String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types " + - "are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + - "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; - log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } - } + RequestValidationUtil.validateStatus(status); request.setStatusList(status); } } - if (actionStatus != null && !actionStatus.isEmpty()) { if (StringUtils.isNotBlank(actionStatus)) { - switch (actionStatus) { - case "PENDING": - case "ERROR": - case "IN_PROGRESS": - case "NOTNOW": - case "COMPLETED": - case "REPEATED": - break; - default: - String msg = "Invalid enrollment action status type: " + actionStatus + ". " + - "\nValid action status types are PENDING | ERROR | IN_PROGRESS | NOTNOW | " + - "COMPLETED | REPEATED"; - log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } + RequestValidationUtil.validateStatusFiltering(actionStatus); } } - SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails (request, uuid, actionStatus); @@ -137,8 +103,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for getting application which has UUID: " + uuid - + ". Hence verify the payload"; + String msg = "User requested details are not valid"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { 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/util/RequestValidationUtil.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/util/RequestValidationUtil.java new file mode 100644 index 0000000000..f557579c77 --- /dev/null +++ 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/util/RequestValidationUtil.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.store.api.services.impl.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; +import org.wso2.carbon.device.application.mgt.store.api.util.Constants; + +import java.util.List; + +public class RequestValidationUtil { + + private static final Log log = LogFactory.getLog(RequestValidationUtil.class); + + /** + * Checks if user requested status codes are valid. + * + * @param statusList status codes upon to filter operation logs using status + */ + public static void validateStatus(List statusList) throws BadRequestException { + for (String status : statusList) { + switch (status) { + case "ACTIVE": + case "INACTIVE": + case "UNCLAIMED": + case "UNREACHABLE": + case "SUSPENDED": + case "DISENROLLMENT_REQUESTED": + case "REMOVED": + case "BLOCKED": + case "CREATED": + break; + default: + String msg = "Invalid enrollment status type: " + status + ". \nValid status types " + + "are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + + "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; + log.error(msg); + throw new BadRequestException(msg); + } + } + } + + /** + * Checks if user requested ownerships are valid. + * + * @param ownership ownerships upon to filter devices using ownership + */ + public static void validateOwnershipType(String ownership) throws BadRequestException { + switch (ownership) { + case "BYOD": + case "COPE": + case "WORK_PROFILE": + case "GOOGLE_ENTERPRISE": + case "COSU": + case "FULLY_MANAGED": + case "DEDICATED_DEVICE": + break; + default: + String msg = "Invalid ownership type received.Valid ownership types are BYOD | COPE | WORK_PROFILE |" + + "GOOGLE_ENTERPRISE | COSU | FULLY_MANAGED | DEDICATED_DEVICE"; + log.error(msg); + throw new BadRequestException(msg); + } + } + + /** + * Checks if user requested Action status codes are valid. + * + * @param status status codes upon to filter operation logs using status + */ + public static void validateStatusFiltering(String status) throws BadRequestException { + if (Constants.OperationStatus.COMPLETED.toUpperCase().equals(status) + || Constants.OperationStatus.ERROR.toUpperCase().equals(status) + || Constants.OperationStatus.NOTNOW.toUpperCase().equals(status) + || Constants.OperationStatus.REPEATED.toUpperCase().equals(status) + || Constants.OperationStatus.PENDING.toUpperCase().equals(status) + || Constants.OperationStatus.IN_PROGRESS.toUpperCase().equals(status)) { + } else { + String msg = "Invalid status type: " + status + ". \nValid status types are COMPLETED | ERROR | " + + "IN_PROGRESS | NOTNOW | PENDING | REPEATED"; + log.error(msg); + throw new BadRequestException(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/util/Constants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/util/Constants.java new file mode 100644 index 0000000000..a78c16077f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/util/Constants.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.store.api.util; + +/** + * Holds the constants used by DeviceImpl Management Admin web application. + */ +public class Constants { + + public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress"; + public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname"; + public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname"; + public static final String USER_CLAIM_CREATED = "http://wso2.org/claims/created"; + public static final String USER_CLAIM_MODIFIED = "http://wso2.org/claims/modified"; + public static final String USER_CLAIM_DEVICES = "http://wso2.org/claims/devices"; + public static final String PRIMARY_USER_STORE = "PRIMARY"; + public static final String DEFAULT_STREAM_VERSION = "1.0.0"; + public static final String SCOPE = "scope"; + public static final String JDBC_USERSTOREMANAGER = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager"; + public static final String DEFAULT_SIMPLE_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; + public static final int DEFAULT_PAGE_LIMIT = 50; + public static final String FORWARD_SLASH = "/"; + public static final String ANDROID = "android"; + public static final String ANDROID_POLICY_VALIDATOR = "io.entgra.proprietary.platform.android." + + "core.polcy.AndroidPolicyPayloadValidator"; + public static final String IOS = "ios"; + public static final String WINDOWS = "windows"; + + + public final class OperationStatus { + private OperationStatus () { throw new AssertionError(); } + public static final String COMPLETED = "completed"; + public static final String ERROR = "error"; + public static final String IN_PROGRESS = "in_progress"; + public static final String PENDING = "pending"; + public static final String NOTNOW = "notnow"; + public static final String REPEATED = "repeated"; + } + public static final String DEVICES = "devices"; + public static final String ATTRIBUTE_DISPLAY_NAME = "DisplayName"; + public static final String ATTRIBUTE_DESCRIPTION = "Description"; + public static final String EXTERNAL_DEVICE_CLAIM_DISPLAY_NAME = "Devices"; + public static final String EXTERNAL_DEVICE_CLAIM_DESCRIPTION = "Device list"; + + public final class ErrorMessages { + private ErrorMessages () { throw new AssertionError(); } + + public static final String STATUS_BAD_REQUEST_MESSAGE_DEFAULT = "Bad Request"; + + } + + public final class DeviceConstants { + private DeviceConstants () { throw new AssertionError(); } + + public static final String APPLICATION_JSON = "application/json"; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; + } + + public final class Permission { + private Permission() { throw new AssertionError(); } + + public static final String ADMIN = "/permission/admin"; + public static final String LOGIN = "/permission/admin/login"; + public static final String DEVICE_MGT = "/permission/admin/device-mgt"; + public static final String APP_MGT = "/permission/admin/app-mgt"; + } + +} From dca6b53a67cb5e693f9691333c20655c6efb1842 Mon Sep 17 00:00:00 2001 From: MalshaPiumini Date: Tue, 23 Mar 2021 14:50:36 +0530 Subject: [PATCH 5/5] Added new filter in subscription details page --- .../common/services/SubscriptionManager.java | 3 ++- .../mgt/core/dao/SubscriptionDAO.java | 2 +- .../GenericSubscriptionDAOImpl.java | 23 +++++++++++++++---- .../mgt/core/impl/ApplicationManagerImpl.java | 4 ++-- .../core/impl/SubscriptionManagerImpl.java | 10 ++++---- .../admin/SubscriptionManagementAdminAPI.java | 6 +++++ .../SubscriptionManagementAdminAPIImpl.java | 11 +++++---- .../impl/util/RequestValidationUtil.java | 14 +++++++++++ .../DeviceManagementProviderService.java | 1 - 9 files changed, 54 insertions(+), 20 deletions(-) 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 12ca873701..a535ffd389 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 @@ -152,12 +152,13 @@ public interface SubscriptionManager { * * @param request paginated request object. * @param actionStatus status of the operation. + * @param action action related to the device. * @param appUUID application release UUID * @return {@link PaginationResult} * @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(PaginationRequest request, String appUUID, String actionStatus) + PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action) 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/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 0dbd746912..d6ccbe9808 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -81,7 +81,7 @@ public interface SubscriptionDAO { void addGroupSubscriptions(int tenantId, String subscribedBy, List groups, int releaseId, String action) throws ApplicationManagementDAOException; - List getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws + List getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus, String action) throws ApplicationManagementDAOException; Map getDeviceSubscriptions(List deviceIds, int appReleaseId, int tenantId) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 96a2746022..6ac7adbf96 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -332,13 +332,15 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws + public List getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus, String action) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Getting device subscriptions for the application release id " + appReleaseId + " from the database"); } boolean isActionStatusProvided = false; + boolean isActionProvided = false; + int index = 1; String sql = "SELECT " + "DS.ID AS ID, " + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, " @@ -356,13 +358,24 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc sql += " AND DS.STATUS= ?"; isActionStatusProvided = true; } + if (action != null && !action.isEmpty()) { + sql += " AND DS.UNSUBSCRIBED= ?"; + isActionProvided = true; + } try { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); - if(isActionStatusProvided){ - stmt.setString(3, actionStatus); + stmt.setInt(index++, appReleaseId); + stmt.setInt(index++, tenantId); + if (isActionStatusProvided) { + stmt.setString(index++, actionStatus); + } + if (isActionProvided) { + if (action.equals("SUBSCRIBED")) { + stmt.setString(index, "FALSE"); + } else { + stmt.setString(index, "TRUE"); + } } try (ResultSet rs = stmt.executeQuery()) { if (log.isDebugEnabled()) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 80706aef41..05b757ba45 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -1445,7 +1445,7 @@ ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ForbiddenException(msg); } - if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null).isEmpty()) { + if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null, null).isEmpty()) { String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + " either subscribed to device/s or it had subscribed to device/s. Therefore you are not " + "permitted to delete the application release."; @@ -1580,7 +1580,7 @@ ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.beginDBTransaction(); List deviceSubscriptionDTOS = subscriptionDAO - .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null); + .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null, null); if (!deviceSubscriptionDTOS.isEmpty()) { String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + " either subscribed to device/s or it had subscribed to device/s. Therefore you " 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 94559782b3..fe590a737f 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 @@ -377,7 +377,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (applicationDTO != null) { List deviceSubscriptionDTOS = this.subscriptionDAO .getDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), - tenantId, null); + tenantId, null, null); AtomicBoolean isAppSubscribable = new AtomicBoolean(true); for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) { @@ -1231,7 +1231,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); List deviceSubscriptionDTOS = subscriptionDAO - .getDeviceSubscriptions(applicationReleaseId, tenantId, null); + .getDeviceSubscriptions(applicationReleaseId, tenantId, null, null); if (deviceSubscriptionDTOS.isEmpty()) { PaginationResult paginationResult = new PaginationResult(); paginationResult.setData(new ArrayList<>()); @@ -1338,8 +1338,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus) - throws ApplicationManagementException { + public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, + String action) throws ApplicationManagementException { int limitValue = request.getRowCount(); int offsetValue = request.getStartIndex(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -1363,7 +1363,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); List deviceSubscriptionDTOS = subscriptionDAO - .getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus); + .getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus, action); if (deviceSubscriptionDTOS.isEmpty()) { PaginationResult paginationResult = new PaginationResult(); paginationResult.setData(new ArrayList<>()); 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 2cb9d63b21..97f6f6851e 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 @@ -124,6 +124,12 @@ public interface SubscriptionManagementAdminAPI { required = false) @QueryParam("user") String user, + @ApiParam( + name = "action", + value = "The action, subscribed or unsubscribed.", + required = false) + @Size(max = 45) + @QueryParam("action") String action, @ApiParam( name = "actionStatus", value = "Provide the action status details") 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 4474ddaa81..681b3b5f38 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,11 +18,9 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin; -import io.swagger.annotations.ApiParam; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpStatus; 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.BadRequestException; @@ -33,7 +31,6 @@ import org.wso2.carbon.device.application.mgt.store.api.services.impl.util.Reque import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import javax.validation.constraints.Size; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -60,6 +57,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen public Response getAppInstalledDevices( @QueryParam("name") String name, @QueryParam("user") String user, + @QueryParam("action") String action, @QueryParam("actionStatus") String actionStatus, @QueryParam("status") List status, @PathParam("uuid") String uuid, @@ -76,6 +74,9 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen if (user != null && !user.isEmpty()) { request.setOwner(user); } + if (action != null && !action.isEmpty()) { + RequestValidationUtil.validateAction(action); + } if (status != null && !status.isEmpty()) { boolean isStatusEmpty = true; for (String statusString : status) { @@ -96,7 +97,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen } SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails - (request, uuid, actionStatus); + (request, uuid, actionStatus, action); return Response.status(Response.Status.OK).entity(subscriptionData).build(); } catch (NotFoundException e) { String msg = "Application with application release UUID: " + uuid + " is not found"; @@ -108,7 +109,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while getting app installed devices which has application release UUID of: " - + uuid; + + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } 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/util/RequestValidationUtil.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/util/RequestValidationUtil.java index f557579c77..2a59d220a4 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/util/RequestValidationUtil.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/util/RequestValidationUtil.java @@ -57,6 +57,20 @@ public class RequestValidationUtil { } } + /** + * Checks if user requested action is valid. + * + * @param action action upon to filter devices using action + */ + public static void validateAction(String action) throws BadRequestException { + if (action.equals("SUBSCRIBED") || action.equals("UNSUBSCRIBED")) { + } else { + String msg = "Invalid action type received.Valid action types are SUBSCRIBED | UNSUBSCRIBED"; + log.error(msg); + throw new BadRequestException(msg); + } + } + /** * Checks if user requested ownerships are valid. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 157fed7c5d..f084e35c3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -906,7 +906,6 @@ public interface DeviceManagementProviderService { * * @param devicesIds devices ids of the subscribed devices. * @param request paginated request object. - * @param status status of the devices. * @return {@link PaginationResult} * @throws DeviceManagementException if any service level or DAO level error occurs. */