From 72edb6c3234438b0f42d84d2119737a09bdbe0b4 Mon Sep 17 00:00:00 2001 From: shamalka Date: Fri, 12 Feb 2021 08:51:29 +0530 Subject: [PATCH] Accept multiple device status in store API --- .../common/services/SubscriptionManager.java | 2 +- .../core/impl/SubscriptionManagerImpl.java | 2 +- .../services/SubscriptionManagementAPI.java | 2 +- .../impl/SubscriptionManagementAPIImpl.java | 2 +- .../carbon/device/mgt/core/dao/DeviceDAO.java | 4 +- .../dao/impl/device/GenericDeviceDAOImpl.java | 49 ++++++++++++------- .../dao/impl/device/OracleDeviceDAOImpl.java | 40 ++++++++------- .../impl/device/PostgreSQLDeviceDAOImpl.java | 40 ++++++++------- .../impl/device/SQLServerDeviceDAOImpl.java | 40 ++++++++------- .../DeviceManagementProviderService.java | 2 +- .../DeviceManagementProviderServiceImpl.java | 2 +- 11 files changed, 105 insertions(+), 80 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 2082b80a0a..9d9e94c183 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 @@ -134,7 +134,7 @@ public interface SubscriptionManager { * @throws {@link ApplicationManagementException} Exception of the application management */ PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, - String status) throws ApplicationManagementException; + List status) throws ApplicationManagementException; /*** * This method used to get category details. 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 9f25979104..ea3c24db24 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 @@ -1214,7 +1214,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, String status) + public PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, List status) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); DeviceManagementProviderService deviceManagementProviderService = HelperUtil 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 f885d79c86..75a4522d68 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 @@ -355,7 +355,7 @@ public interface SubscriptionManagementAPI { @ApiParam( name = "status", value = "Provide the device status details, such as active or inactive.") - @QueryParam("status") String status + @QueryParam("status") List status ); @GET 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 13a2afb8cd..984f689d07 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 @@ -278,7 +278,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @QueryParam("offset") int offset, @DefaultValue("5") @QueryParam("limit") int limit, - @QueryParam("status") String status) { + @QueryParam("status") List status) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); PaginationResult subscribedDeviceDetails = subscriptionManager 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 2c1df83ad9..5fac4c9410 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 @@ -647,7 +647,7 @@ public interface DeviceDAO { * @throws DeviceManagementDAOException if connections establishment fails. */ List getSubscribedDevices(int offsetValue, int limitValue, List deviceIds, - int tenantId, String status) throws DeviceManagementDAOException; + int tenantId, List status) throws DeviceManagementDAOException; /** * @param deviceIds device ids of the subscribed devices. @@ -656,7 +656,7 @@ public interface DeviceDAO { * @return number of subscribed device count. * @throws DeviceManagementDAOException if error occurred while processing the SQL statement. */ - int getSubscribedDeviceCount(List deviceIds, int tenantId, String status) + int getSubscribedDeviceCount(List deviceIds, int tenantId, List status) throws DeviceManagementDAOException; /** 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 52c5d9d53e..40e3996cbc 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 @@ -878,7 +878,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { @Override public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, String status) + List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { Connection conn; @@ -894,18 +894,18 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + "DM_DEVICE.DEVICE_TYPE_ID, " + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " - + "DM_ENROLMENT.ID AS ENROLMENT_ID, " - + "DM_ENROLMENT.OWNER, " - + "DM_ENROLMENT.OWNERSHIP, " - + "DM_ENROLMENT.DATE_OF_ENROLMENT, " - + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " - + "DM_ENROLMENT.STATUS, " - + "DM_ENROLMENT.IS_TRANSFERRED, " + + "e.ID AS ENROLMENT_ID, " + + "e.OWNER, " + + "e.OWNERSHIP, " + + "e.DATE_OF_ENROLMENT, " + + "e.DATE_OF_LAST_UPDATE, " + + "e.STATUS, " + + "e.IS_TRANSFERRED, " + "device_types.NAME AS DEVICE_TYPE " + "FROM DM_DEVICE " - + "INNER JOIN DM_ENROLMENT ON " - + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " - + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN DM_ENROLMENT e ON " + + "DM_DEVICE.ID = e.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = e.TENANT_ID " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "WHERE DM_DEVICE.ID IN (", @@ -914,8 +914,13 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); +// if (status != null && !status.isEmpty()) { +// query = query + " AND DM_ENROLMENT.STATUS=?"; +// isStatusProvided = true; +// } + if (status != null && !status.isEmpty()) { - query = query + " AND DM_ENROLMENT.STATUS=?"; + query += buildStatusQuery(status); isStatusProvided = true; } @@ -929,7 +934,9 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setInt(index++, tenantId); if (isStatusProvided) { - ps.setString(index++, status); + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } ps.setInt(index++, offsetValue); ps.setInt(index, limitValue); @@ -951,7 +958,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public int getSubscribedDeviceCount(List deviceIds, int tenantId, String status) + public int getSubscribedDeviceCount(List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { try { Connection conn = this.getConnection(); @@ -967,8 +974,12 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); - if (!StringUtils.isBlank(status)) { - query = query + " AND e.STATUS = ?"; +// if (!StringUtils.isBlank(status)) { +// query = query + " AND e.STATUS = ?"; +// } + + if (status != null && !status.isEmpty()) { + query += buildStatusQuery(status); } try (PreparedStatement ps = conn.prepareStatement(query)) { @@ -977,8 +988,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); - if (!StringUtils.isBlank(status)) { - ps.setString(index, status); + if (status != null && !status.isEmpty()) { + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } try (ResultSet rs = ps.executeQuery()) { 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 e918cae3ca..b143136ef9 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 @@ -848,7 +848,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { @Override public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, String status) + List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { Connection conn; @@ -864,18 +864,18 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + "DM_DEVICE.DEVICE_TYPE_ID, " + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " - + "DM_ENROLMENT.ID AS ENROLMENT_ID, " - + "DM_ENROLMENT.OWNER, " - + "DM_ENROLMENT.OWNERSHIP, " - + "DM_ENROLMENT.DATE_OF_ENROLMENT, " - + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " - + "DM_ENROLMENT.STATUS, " - + "DM_ENROLMENT.IS_TRANSFERRED, " + + "e.ID AS ENROLMENT_ID, " + + "e.OWNER, " + + "e.OWNERSHIP, " + + "e.DATE_OF_ENROLMENT, " + + "e.DATE_OF_LAST_UPDATE, " + + "e.STATUS, " + + "e.IS_TRANSFERRED, " + "device_types.NAME AS DEVICE_TYPE " + "FROM DM_DEVICE " - + "INNER JOIN DM_ENROLMENT ON " - + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " - + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN DM_ENROLMENT e ON " + + "DM_DEVICE.ID = e.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = e.TENANT_ID " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "WHERE DM_DEVICE.ID IN (", @@ -885,7 +885,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND DM_ENROLMENT.STATUS=?"; + query += buildStatusQuery(status); isStatusProvided = true; } @@ -899,7 +899,9 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setInt(index++, tenantId); if (isStatusProvided) { - ps.setString(index++, status); + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } ps.setInt(index++, offsetValue); ps.setInt(index, limitValue); @@ -921,7 +923,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public int getSubscribedDeviceCount(List deviceIds, int tenantId, String status) + public int getSubscribedDeviceCount(List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { try { Connection conn = this.getConnection(); @@ -937,8 +939,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); - if (!StringUtils.isBlank(status)) { - query = query + " AND e.STATUS = ?"; + if (status != null && !status.isEmpty()) { + query += buildStatusQuery(status); } try (PreparedStatement ps = conn.prepareStatement(query)) { @@ -947,8 +949,10 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); - if (!StringUtils.isBlank(status)) { - ps.setString(index, status); + if (status != null && !status.isEmpty()) { + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } try (ResultSet rs = ps.executeQuery()) { 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 49522ba74c..4a7560f9f3 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 @@ -828,7 +828,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { @Override public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, String status) + List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { Connection conn; @@ -844,18 +844,18 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + "DM_DEVICE.DEVICE_TYPE_ID, " + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " - + "DM_ENROLMENT.ID AS ENROLMENT_ID, " - + "DM_ENROLMENT.OWNER, " - + "DM_ENROLMENT.OWNERSHIP, " - + "DM_ENROLMENT.DATE_OF_ENROLMENT, " - + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " - + "DM_ENROLMENT.STATUS, " - + "DM_ENROLMENT.IS_TRANSFERRED, " + + "e.ID AS ENROLMENT_ID, " + + "e.OWNER, " + + "e.OWNERSHIP, " + + "e.DATE_OF_ENROLMENT, " + + "e.DATE_OF_LAST_UPDATE, " + + "e.STATUS, " + + "e.IS_TRANSFERRED, " + "device_types.NAME AS DEVICE_TYPE " + "FROM DM_DEVICE " - + "INNER JOIN DM_ENROLMENT ON " - + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " - + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN DM_ENROLMENT e ON " + + "DM_DEVICE.ID = e.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = e.TENANT_ID " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "WHERE DM_DEVICE.ID IN (", @@ -865,7 +865,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND DM_ENROLMENT.STATUS=?"; + query += buildStatusQuery(status); isStatusProvided = true; } @@ -879,7 +879,9 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setInt(index++, tenantId); if (isStatusProvided) { - ps.setString(index++, status); + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } ps.setInt(index++, offsetValue); ps.setInt(index, limitValue); @@ -901,7 +903,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public int getSubscribedDeviceCount(List deviceIds, int tenantId, String status) + public int getSubscribedDeviceCount(List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { try { Connection conn = this.getConnection(); @@ -917,8 +919,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); - if (!StringUtils.isBlank(status)) { - query = query + " AND e.STATUS = ?"; + if (status != null && !status.isEmpty()) { + query += buildStatusQuery(status); } try (PreparedStatement ps = conn.prepareStatement(query)) { @@ -927,8 +929,10 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); - if (!StringUtils.isBlank(status)) { - ps.setString(index, status); + if (status != null && !status.isEmpty()) { + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } try (ResultSet rs = ps.executeQuery()) { 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 d56407276d..11112c4655 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 @@ -694,7 +694,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { @Override public List getSubscribedDevices(int offsetValue, int limitValue, - List deviceIds, int tenantId, String status) + List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { Connection conn; @@ -710,18 +710,18 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + "DM_DEVICE.DEVICE_TYPE_ID, " + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " - + "DM_ENROLMENT.ID AS ENROLMENT_ID, " - + "DM_ENROLMENT.OWNER, " - + "DM_ENROLMENT.OWNERSHIP, " - + "DM_ENROLMENT.DATE_OF_ENROLMENT, " - + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " - + "DM_ENROLMENT.STATUS, " - + "DM_ENROLMENT.IS_TRANSFERRED, " + + "e.ID AS ENROLMENT_ID, " + + "e.OWNER, " + + "e.OWNERSHIP, " + + "e.DATE_OF_ENROLMENT, " + + "e.DATE_OF_LAST_UPDATE, " + + "e.STATUS, " + + "e.IS_TRANSFERRED, " + "device_types.NAME AS DEVICE_TYPE " + "FROM DM_DEVICE " - + "INNER JOIN DM_ENROLMENT ON " - + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " - + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN DM_ENROLMENT e ON " + + "DM_DEVICE.ID = e.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = e.TENANT_ID " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "WHERE DM_DEVICE.ID IN (", @@ -731,7 +731,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND DM_ENROLMENT.STATUS=?"; + query += buildStatusQuery(status); isStatusProvided = true; } @@ -745,7 +745,9 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setInt(index++, tenantId); if (isStatusProvided) { - ps.setString(index++, status); + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } ps.setInt(index++, offsetValue); ps.setInt(index, limitValue); @@ -1034,7 +1036,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public int getSubscribedDeviceCount(List deviceIds, int tenantId, String status) + public int getSubscribedDeviceCount(List deviceIds, int tenantId, List status) throws DeviceManagementDAOException { try { Connection conn = this.getConnection(); @@ -1050,8 +1052,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); - if (!StringUtils.isBlank(status)) { - query = query + " AND e.STATUS = ?"; + if (status != null && !status.isEmpty()) { + query += buildStatusQuery(status); } try (PreparedStatement ps = conn.prepareStatement(query)) { @@ -1060,8 +1062,10 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } ps.setInt(index++, tenantId); - if (!StringUtils.isBlank(status)) { - ps.setString(index, status); + if (status != null && !status.isEmpty()) { + for (String deviceStatus : status) { + ps.setString(index++, deviceStatus); + } } try (ResultSet rs = ps.executeQuery()) { 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 efc4c930e3..04413340dc 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 @@ -884,7 +884,7 @@ public interface DeviceManagementProviderService { * @throws DeviceManagementException if any service level or DAO level error occurs. */ PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue, - List devicesIds, String status) throws DeviceManagementException; + 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 0bbbb8a607..0e862f3b6d 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 @@ -4084,7 +4084,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue, List devicesIds, - String status) throws DeviceManagementException { + List status) throws DeviceManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) {