From b8542bfffd851adae92fef1c1325c0718b30411c Mon Sep 17 00:00:00 2001 From: Gimhan-minion Date: Fri, 30 Aug 2024 01:44:40 +0530 Subject: [PATCH 1/4] Fix data type inconsistency in tag db scripts --- .../src/test/resources/sql/h2.sql | 6 +++--- .../src/main/resources/dbscripts/cdm/h2.sql | 6 +++--- .../src/main/resources/dbscripts/cdm/mssql.sql | 10 +++++----- .../src/main/resources/dbscripts/cdm/mysql.sql | 10 +++++----- .../src/main/resources/dbscripts/cdm/oracle.sql | 6 +++--- .../src/main/resources/dbscripts/cdm/postgresql.sql | 6 +++--- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql index 7ee776da58..323f52762a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql @@ -672,7 +672,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( -- DM_TAG TABLE -- CREATE TABLE IF NOT EXISTS DM_TAG ( - ID BIGINT AUTO_INCREMENT, + ID INTEGER AUTO_INCREMENT, NAME VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255) NULL, TENANT_ID INTEGER NOT NULL, @@ -683,8 +683,8 @@ CREATE TABLE IF NOT EXISTS DM_TAG ( -- DM_DEVICE_TAG_MAPPING TABLE -- CREATE TABLE IF NOT EXISTS DM_DEVICE_TAG_MAPPING ( - ENROLMENT_ID BIGINT NOT NULL, - TAG_ID BIGINT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TAG_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ENROLMENT_ID, TAG_ID, TENANT_ID), FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID), diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 7507ca0d59..6ba0077069 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -878,7 +878,7 @@ CREATE TABLE IF NOT EXISTS DM_CEA_POLICIES ( -- DM_TAG TABLE -- CREATE TABLE IF NOT EXISTS DM_TAG ( - ID BIGINT AUTO_INCREMENT, + ID INTEGER AUTO_INCREMENT, NAME VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255) NULL, TENANT_ID INTEGER NOT NULL, @@ -889,8 +889,8 @@ CREATE TABLE IF NOT EXISTS DM_TAG ( -- DM_DEVICE_TAG_MAPPING TABLE -- CREATE TABLE IF NOT EXISTS DM_DEVICE_TAG_MAPPING ( - ENROLMENT_ID BIGINT NOT NULL, - TAG_ID BIGINT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TAG_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ENROLMENT_ID, TAG_ID, TENANT_ID), FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID), diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index dc39bb4d16..272066798d 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -954,19 +954,19 @@ END; -- DM_TAG TABLE -- CREATE TABLE IF NOT EXISTS DM_TAG ( - ID BIGINT IDENTITY(1,1) PRIMARY KEY, + ID INTEGER IDENTITY(1,1) PRIMARY KEY, NAME NVARCHAR(255) NOT NULL, DESCRIPTION NVARCHAR(255) NULL, - TENANT_ID INT NOT NULL, + TENANT_ID INTEGER NOT NULL, CONSTRAINT DM_TAG_NAME_TENANT_UNIQUE UNIQUE (NAME, TENANT_ID) ); -- END OF DM_TAG TABLE -- -- DM_DEVICE_TAG_MAPPING TABLE -- CREATE TABLE IF NOT EXISTS DM_DEVICE_TAG_MAPPING ( - ENROLMENT_ID BIGINT NOT NULL, - TAG_ID BIGINT NOT NULL, - TENANT_ID INT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TAG_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ENROLMENT_ID, TAG_ID, TENANT_ID), FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID), FOREIGN KEY (TAG_ID) REFERENCES DM_TAG(ID) ON DELETE CASCADE diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index a943265bdb..773fe53b34 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -953,19 +953,19 @@ CREATE TABLE IF NOT EXISTS DM_CEA_POLICIES ( -- DM_TAG TABLE -- CREATE TABLE IF NOT EXISTS DM_TAG ( - ID BIGINT AUTO_INCREMENT PRIMARY KEY, + ID INTEGER AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255) NULL, - TENANT_ID INT NOT NULL, + TENANT_ID INTEGER NOT NULL, CONSTRAINT DM_TAG_NAME_TENANT_UNIQUE UNIQUE (NAME, TENANT_ID) ); -- END OF DM_TAG TABLE -- -- DM_DEVICE_TAG_MAPPING TABLE -- CREATE TABLE IF NOT EXISTS DM_DEVICE_TAG_MAPPING ( - ENROLMENT_ID BIGINT NOT NULL, - TAG_ID BIGINT NOT NULL, - TENANT_ID INT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TAG_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ENROLMENT_ID, TAG_ID, TENANT_ID), FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID), FOREIGN KEY (TAG_ID) REFERENCES DM_TAG(ID) ON DELETE CASCADE diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 2fa51b9d49..1b1071c290 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1258,7 +1258,7 @@ END; -- DM_TAG TABLE -- CREATE TABLE DM_TAG ( - ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY, + ID NUMBER(10) GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY, NAME VARCHAR2(255) NOT NULL, DESCRIPTION VARCHAR2(255) NULL, TENANT_ID NUMBER(10) NOT NULL, @@ -1268,8 +1268,8 @@ CREATE TABLE DM_TAG ( -- DM_DEVICE_TAG_MAPPING TABLE -- CREATE TABLE DM_DEVICE_TAG_MAPPING ( - ENROLMENT_ID NUMBER(19) NOT NULL, - TAG_ID NUMBER(19) NOT NULL, + ENROLMENT_ID NUMBER(10) NOT NULL, + TAG_ID NUMBER(10) NOT NULL, TENANT_ID NUMBER(10) NOT NULL, PRIMARY KEY (ENROLMENT_ID, TAG_ID, TENANT_ID), FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID), diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index d9bce9fd04..31591893e1 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -884,7 +884,7 @@ CREATE TABLE IF NOT EXISTS DM_CEA_POLICIES ( -- DM_TAG TABLE -- CREATE TABLE IF NOT EXISTS DM_TAG ( - ID BIGSERIAL PRIMARY KEY, + ID INTEGER PRIMARY KEY, NAME VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255) NULL, TENANT_ID INTEGER NOT NULL, @@ -894,8 +894,8 @@ CREATE TABLE IF NOT EXISTS DM_TAG ( -- DM_DEVICE_TAG_MAPPING TABLE -- CREATE TABLE IF NOT EXISTS DM_DEVICE_TAG_MAPPING ( - ENROLMENT_ID BIGINT NOT NULL, - TAG_ID BIGINT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TAG_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ENROLMENT_ID, TAG_ID, TENANT_ID), FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID), From afa329455527cf27dc0093a49dfa5af435c13c54 Mon Sep 17 00:00:00 2001 From: nipuni Date: Thu, 29 Aug 2024 10:15:11 +0530 Subject: [PATCH 2/4] Fix search by middle part of the username is not working in uninstall table in app store. --- .../mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 6 +++--- .../mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java | 6 +++--- .../mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index e116df7490..5586be8002 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -1317,7 +1317,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { query += " AND i.VALUE_FIELD LIKE ?" ; } if (user != null && !user.isEmpty()) { - query += " AND e.OWNER = ?"; + query += " AND e.OWNER LIKE ?"; isOwnerProvided = true; } if (status != null && !status.isEmpty()) { @@ -1347,7 +1347,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString()); ps.setString(index++, EnrolmentInfo.Status.DELETED.toString()); if (isDeviceNameProvided) { - ps.setString(index++, name + "%"); + ps.setString(index++, "%" + name + "%"); } if (isOwnershipProvided) { ps.setString(index++, ownership); @@ -1356,7 +1356,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setString(index++, "%" + serial + "%"); } if (isOwnerProvided) { - ps.setString(index++, user); + ps.setString(index++, "%" + user + "%"); } if (isStatusProvided) { for (String deviceStatus : status) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 0f502cf874..ac63399d38 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -1068,7 +1068,7 @@ public class PostgreSQLDeviceDAOImpl extends GenericDeviceDAOImpl { isOwnershipProvided = true; } if (user != null && !user.isEmpty()) { - query += " AND e.OWNER = ?"; + query += " AND e.OWNER LIKE ?"; isOwnerProvided = true; } if (status != null && !status.isEmpty()) { @@ -1099,13 +1099,13 @@ public class PostgreSQLDeviceDAOImpl extends GenericDeviceDAOImpl { ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString()); ps.setString(index++, EnrolmentInfo.Status.DELETED.toString()); if (isDeviceNameProvided) { - ps.setString(index++, name + "%"); + ps.setString(index++, "%" + name + "%"); } if (isOwnershipProvided) { ps.setString(index++, ownership); } if (isOwnerProvided) { - ps.setString(index++, user); + ps.setString(index++, "%" + user + "%"); } if (isStatusProvided) { for (String deviceStatus : status) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index 7de242ead9..9dc29afa72 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -936,7 +936,7 @@ public class SQLServerDeviceDAOImpl extends GenericDeviceDAOImpl { isOwnershipProvided = true; } if (user != null && !user.isEmpty()) { - query += " AND e.OWNER = ?"; + query += " AND e.OWNER LIKE ?"; isOwnerProvided = true; } if (status != null && !status.isEmpty()) { @@ -967,13 +967,13 @@ public class SQLServerDeviceDAOImpl extends GenericDeviceDAOImpl { ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString()); ps.setString(index++, EnrolmentInfo.Status.DELETED.toString()); if (isDeviceNameProvided) { - ps.setString(index++, name + "%"); + ps.setString(index++, "%" + name + "%"); } if (isOwnershipProvided) { ps.setString(index++, ownership); } if (isOwnerProvided) { - ps.setString(index++, user); + ps.setString(index++, "%" + user + "%"); } if (isStatusProvided) { for (String deviceStatus : status) { From 9ce605d883fa2dc38c6f7748dfe86e0d1a796b18 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Fri, 30 Aug 2024 17:43:32 +0530 Subject: [PATCH 3/4] Update release rating data type --- .../mgt/core/application/mgt/common/ReleaseVersionInfo.java | 6 +++--- .../dao/impl/application/GenericApplicationDAOImpl.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java index 218f92187b..e1e7548d68 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java @@ -22,7 +22,7 @@ package io.entgra.device.mgt.core.application.mgt.common; public class ReleaseVersionInfo { private String version; private String releaseType; - private String rating; + private double rating; private String state; private String uuid; @@ -38,11 +38,11 @@ public class ReleaseVersionInfo { return releaseType; } - public String getRating() { + public double getRating() { return rating; } - public void setRating(String rating) { + public void setRating(double rating) { this.rating = rating; } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index b327d9803d..c99a06eeb4 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -2075,7 +2075,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic releaseVersionInfo = new ReleaseVersionInfo(); releaseVersionInfo.setVersion(resultSet.getString("VERSION")); releaseVersionInfo.setReleaseType(resultSet.getString("RELEASE_TYPE")); - releaseVersionInfo.setRating(resultSet.getString("RATING")); + releaseVersionInfo.setRating(resultSet.getDouble("RATING")); releaseVersionInfo.setState(resultSet.getString("CURRENT_STATE")); releaseVersionInfo.setUuid(resultSet.getString("UUID")); releaseVersionInfos.add(releaseVersionInfo); From 320d5215de079200ac06475251dad999e38ad152 Mon Sep 17 00:00:00 2001 From: nipuni Date: Fri, 30 Aug 2024 13:39:52 +0530 Subject: [PATCH 4/4] Implement the search API for Subscription details view --- .../common/services/SubscriptionManager.java | 5 +- .../mgt/core/dao/SubscriptionDAO.java | 71 +++++- .../GenericSubscriptionDAOImpl.java | 232 ++++++++++++------ .../OracleSubscriptionDAOImpl.java | 106 +++++--- .../SQLServerSubscriptionDAOImpl.java | 107 +++++--- .../core/impl/SubscriptionManagerImpl.java | 27 +- 6 files changed, 381 insertions(+), 167 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java index 1e70f1b9d6..fd16e70872 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java @@ -187,11 +187,14 @@ public interface SubscriptionManager { * @param subType subscription type of the application. * @param offsetValue offset value for get paginated request. * @param limitValue limit value for get paginated request. + * @param uninstalled a Boolean flag indicating the filter criteria for retrieve subscription data + * @param searchName an optional search term to filter the results by name. If null or empty, no filtering by name is applied. * @return {@link PaginationResult} pagination result of the category details. * @throws {@link ApplicationManagementException} Exception of the application management */ PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, - String subType) throws ApplicationManagementException; + String subType, Boolean uninstalled, String searchName) + throws ApplicationManagementException; /** * This method is responsible to provide application subscription data for given application release UUID. diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java index c35c4a5251..cd1755fc21 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java @@ -198,14 +198,33 @@ public interface SubscriptionDAO { * @param offsetValue offset value for get paginated result * @param limitValue limit value for get paginated result * @param appReleaseId id of the application release. + * @param uninstalled a Boolean flag indicating the filter criteria for getting users: + * - `true` to get only unsubscribed users, + * - `false` to get only subscribed users, + * - `null` to get all users regardless of their unsubscription status. + * @param searchName an optional search term to filter the results by username. * @return subscribedUsers - list of app subscribed users. * @throws {@link ApplicationManagementDAOException} if connections establishment fails. */ List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException; - int getSubscribedUserCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException; + /** + * This method is used to get the count of users who are subscribed or unsubscribed to a specific application release. + * + * @param appReleaseId the ID of the application release for which the user count is to be retrieved. + * @param tenantId the ID of the current tenant. + * @param uninstalled a Boolean flag indicating the filter criteria for counting users: + * - `true` to count only unsubscribed users, + * - `false` to count only subscribed users, + * - `null` to count all users regardless of their unsubscription status. + * @param searchName an optional search term to filter the results by username. + * @return the count of users based on the specified criteria. + * @throws ApplicationManagementDAOException if an error occurs while establishing a database connection or executing the query. + */ + int getSubscribedUserCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName) + throws ApplicationManagementDAOException; /** * This method is used to get the details of roles @@ -214,14 +233,34 @@ public interface SubscriptionDAO { * @param offsetValue offset value for get paginated request. * @param limitValue limit value for get paginated request. * @param appReleaseId id of the application release. + * @param uninstalled a Boolean flag indicating the filter criteria for getting roles: + * - `true` to get only unsubscribed roles, + * - `false` to get only subscribed roles, + * - `null` to get all roles regardless of their unsubscription status. + * @param searchName an optional search term to filter the results by role name. * @return subscribedRoles - list of app subscribed roles. * @throws {@link ApplicationManagementDAOException} if connections establishment fails. */ List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException; - int getSubscribedRoleCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException; + /** + * This method retrieves the count of roles subscribed to a given application release. + * The count can be filtered based on the unsubscription status. + * + * @param appReleaseId the ID of the application release for which the subscribed roles are counted. + * @param tenantId the ID of the current tenant. + * @param uninstalled a Boolean flag indicating the filter criteria for counting roles: + * - `true` to count only unsubscribed roles, + * - `false` to count only subscribed roles, + * - `null` to count all roles regardless of their unsubscription status. + * @param searchName an optional search term to filter the results by role name. + * @return the count of roles that match the specified criteria. + * @throws ApplicationManagementDAOException if there is an error while accessing the database or processing the request. + */ + int getSubscribedRoleCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName) + throws ApplicationManagementDAOException; /** * This method is used to get the details of subscribed groups @@ -230,13 +269,33 @@ public interface SubscriptionDAO { * @param offsetValue offset value for get paginated request. * @param limitValue limit value for get paginated request. * @param appReleaseId id of the application release. + * @param uninstalled a Boolean flag indicating the filter criteria for getting groups: + * - `true` to get only unsubscribed groups, + * - `false` to get only subscribed groups, + * - `null` to get all groups regardless of their unsubscription status. + * @param searchName an optional search term to filter the results by group name. * @return subscribedGroups - list of app subscribed groups. * @throws {@link ApplicationManagementDAOException} if connections establishment fails. */ - List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId) + List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId, + Boolean uninstalled, String searchName) throws ApplicationManagementDAOException; - int getSubscribedGroupCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException; + /** + * This method is used to get the count of subscribed groups + * + * @param tenantId id of the current tenant + * @param appReleaseId id of the application release. + * @param uninstalled a Boolean flag indicating the filter criteria for counting groups: + * - `true` to count only unsubscribed groups, + * - `false` to count only subscribed groups, + * - `null` to count all groups regardless of their unsubscription status. + * @param searchName an optional search term to filter the results by group name. + * @return subscribedGroups - list of app subscribed groups. + * @throws {@link ApplicationManagementDAOException} if connections establishment fails. + */ + int getSubscribedGroupCount(int appReleaseId, int tenantId,Boolean uninstalled, String searchName) + throws ApplicationManagementDAOException; /** * This method is used to get the details of subscribed groups diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 66aec68576..a5701cfdfb 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -967,25 +967,37 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc @Override public List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed users for " + - "given app release id."); + log.debug("Request received in DAO Layer to get subscribed/unsubscribed users for the given app release ID."); } try { Connection conn = this.getDBConnection(); List subscribedUsers = new ArrayList<>(); - String sql = "SELECT " - + "US.USER_NAME AS USER_NAME " - + "FROM AP_USER_SUBSCRIPTION US " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; + String sql = "SELECT US.USER_NAME AS USER_NAME " + + "FROM AP_USER_SUBSCRIPTION US " + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ? "; + if (uninstalled != null) { + sql += "AND UNSUBSCRIBED = ? "; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += "AND US.USER_NAME LIKE ? "; + } + sql += "LIMIT ? OFFSET ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); - stmt.setInt(3, limitValue); - stmt.setInt(4, offsetValue); + int index = 1; + stmt.setInt(index++, appReleaseId); + stmt.setInt(index++, tenantId); + if (uninstalled != null) { + stmt.setBoolean(index++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + stmt.setString(index++, "%" + searchName + "%"); + } + stmt.setInt(index++, limitValue); + stmt.setInt(index, offsetValue); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { subscribedUsers.add(rs.getString("USER_NAME")); @@ -994,50 +1006,62 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc return subscribedUsers; } } catch (DBConnectionException e) { - String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed users for given app release id."; + String msg = "Error occurred while obtaining the DB connection to get subscribed/unsubscribed users for the " + + "given app release ID."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed users for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed users for the given app release ID."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } } @Override - public int getSubscribedUserCount(int appReleaseId, int tenantId) + public int getSubscribedUserCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed users for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed users for " + "given app release id."); } try { Connection conn = this.getDBConnection(); - String sql = "SELECT " - + "COUNT(US.USER_NAME) AS USER_NAME " - + "FROM AP_USER_SUBSCRIPTION US " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + String sql = "SELECT COUNT(US.USER_NAME) AS USER_COUNT " + + "FROM AP_USER_SUBSCRIPTION US " + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND US.USER_NAME LIKE ?"; + } try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); + int index = 1; + stmt.setInt(index++, appReleaseId); + stmt.setInt(index++, tenantId); + if (uninstalled != null) { + stmt.setBoolean(index++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + stmt.setString(index++, "%" + searchName + "%"); + } try (ResultSet rs = stmt.executeQuery()) { if (rs.next()) { - return rs.getInt("USER_NAME"); + return rs.getInt("USER_COUNT"); } } return 0; } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed users count for given app release id."; + "subscribed/unsubscribed users count for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed users for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed users count for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } @@ -1151,25 +1175,40 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc @Override public List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed roles for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " + "given app release id."); } try { Connection conn = this.getDBConnection(); List subscribedRoles = new ArrayList<>(); String sql = "SELECT " - + "RS.ROLE_NAME AS ROLE " - + "FROM AP_ROLE_SUBSCRIPTION RS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; + + "RS.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION RS " + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND RS.ROLE_NAME LIKE ?"; + } + sql += " LIMIT ? OFFSET ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { - ps.setInt(1, appReleaseId); - ps.setInt(2, tenantId); - ps.setInt(3, limitValue); - ps.setInt(4, offsetValue); + int paramIndex = 1; + ps.setInt(paramIndex++, appReleaseId); + ps.setInt(paramIndex++, tenantId); + + if (uninstalled != null) { + ps.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + ps.setString(paramIndex++, "%" + searchName + "%"); + } + ps.setInt(paramIndex++, limitValue); + ps.setInt(paramIndex, offsetValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedRoles.add(rs.getString("ROLE")); @@ -1179,49 +1218,61 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed roles for given app release id."; + "subscribed/unsubscribed roles for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed roles for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed roles for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } } @Override - public int getSubscribedRoleCount(int appReleaseId, int tenantId) + public int getSubscribedRoleCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed roles for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " + "given app release id."); } try { Connection conn = this.getDBConnection(); String sql = "SELECT " - + "COUNT(RS.ROLE_NAME) AS ROLE_NAME " - + "FROM AP_ROLE_SUBSCRIPTION RS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + + "COUNT(RS.ROLE_NAME) AS ROLE_COUNT " + + "FROM AP_ROLE_SUBSCRIPTION RS " + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND RS.ROLE_NAME LIKE ?"; + } try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); - + int paramIndex = 1; + stmt.setInt(paramIndex++, appReleaseId); + stmt.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + stmt.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + stmt.setString(paramIndex++, "%" + searchName + "%"); + } try (ResultSet rs = stmt.executeQuery()) { if (rs.next()) { - return rs.getInt("ROLE_NAME"); + return rs.getInt("ROLE_COUNT"); } + return 0; } - return 0; } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed roles count for given app release id."; + "subscribed/unsubscribed roles count for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed roles for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed roles count for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } @@ -1269,25 +1320,37 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc @Override public List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed groups for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed groups for " + "given app release id."); } try { Connection conn = this.getDBConnection(); List subscribedGroups = new ArrayList<>(); - String sql = "SELECT " - + "GS.GROUP_NAME AS APP_GROUPS " - + "FROM AP_GROUP_SUBSCRIPTION GS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; + String sql = "SELECT GS.GROUP_NAME AS APP_GROUPS " + + "FROM AP_GROUP_SUBSCRIPTION GS " + + "WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND GS.GROUP_NAME LIKE ?"; + } + sql += " LIMIT ? OFFSET ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { - ps.setInt(1, appReleaseId); - ps.setInt(2, tenantId); - ps.setInt(3, limitValue); - ps.setInt(4, offsetValue); + int paramIndex = 1; + ps.setInt(paramIndex++, appReleaseId); + ps.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + ps.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + ps.setString(paramIndex++, "%" + searchName + "%"); + } + ps.setInt(paramIndex++, limitValue); + ps.setInt(paramIndex, offsetValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedGroups.add(rs.getString("APP_GROUPS")); @@ -1297,11 +1360,11 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed groups for given app release id."; + "subscribed/unsubscribed groups for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed groups for given " + + String msg = "SQL Error occurred while getting subscribed/unsubscribed groups for given " + "app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); @@ -1309,24 +1372,34 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public int getSubscribedGroupCount(int appReleaseId, int tenantId) + public int getSubscribedGroupCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed groups for " + - "given app release id."); + log.debug("Request received in DAO Layer to get the count of subscribed/unsubscribed groups for " + + "given app release id."); } try { Connection conn = this.getDBConnection(); - String sql = "SELECT " - + "COUNT(GS.GROUP_NAME) AS APP_GROUPS_COUNT " - + "FROM AP_GROUP_SUBSCRIPTION GS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + String sql = "SELECT COUNT(GS.GROUP_NAME) AS APP_GROUPS_COUNT " + + "FROM AP_GROUP_SUBSCRIPTION GS " + + "WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND GS.GROUP_NAME LIKE ?"; + } try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); - + int paramIndex = 1; + stmt.setInt(paramIndex++, appReleaseId); + stmt.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + stmt.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + stmt.setString(paramIndex++, "%" + searchName + "%"); + } try (ResultSet rs = stmt.executeQuery()) { if (rs.next()) { return rs.getInt("APP_GROUPS_COUNT"); @@ -1335,12 +1408,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc return 0; } } catch (DBConnectionException e) { - String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed groups count for given app release id."; + String msg = "Error occurred while obtaining the DB connection to get the count of " + + "subscribed/unsubscribed groups for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed groups for given app release id."; + String msg = "SQL Error occurred while getting the count of subscribed/unsubscribed groups for given " + + "app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java index f66051e308..a074672a55 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java @@ -43,10 +43,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { @Override public List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed users for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed users for " + "given app release id."); } try { @@ -55,13 +55,28 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { String sql = "SELECT " + "US.USER_NAME AS USER " + "FROM AP_USER_SUBSCRIPTION US " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ? "; + if (uninstalled != null) { + sql += "AND UNSUBSCRIBED = ? "; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += "AND US.USER_NAME LIKE ? "; + } + sql += "ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); - stmt.setInt(3, offsetValue); - stmt.setInt(4, limitValue); + int index = 1; + stmt.setInt(index++, appReleaseId); + stmt.setInt(index++, tenantId); + if (uninstalled != null) { + stmt.setBoolean(index++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + stmt.setString(index++, "%" + searchName + "%"); + } + stmt.setInt(index++, offsetValue); + stmt.setInt(index, limitValue); + try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { subscribedUsers.add(rs.getString("USER")); @@ -71,11 +86,11 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed users for given app release id."; + "subscribed/unsubscribed users for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed users for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed users for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } @@ -83,10 +98,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { @Override public List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed roles for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " + "given app release id."); } try { @@ -95,13 +110,27 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { String sql = "SELECT " + "RS.ROLE_NAME AS ROLE " + "FROM AP_ROLE_SUBSCRIPTION RS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ? "; + if (uninstalled != null) { + sql += "AND UNSUBSCRIBED = ? "; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += "AND RS.ROLE_NAME LIKE ? "; + } + sql += "ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { - ps.setInt(1, appReleaseId); - ps.setInt(2, tenantId); - ps.setInt(3, offsetValue); - ps.setInt(4, limitValue); + int paramIndex = 1; + ps.setInt(paramIndex++, appReleaseId); + ps.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + ps.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + ps.setString(paramIndex++, "%" + searchName + "%"); + } + ps.setInt(paramIndex++, offsetValue); + ps.setInt(paramIndex, limitValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedRoles.add(rs.getString("ROLE")); @@ -111,11 +140,11 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed roles for given app release id."; + "subscribed/unsubscribed roles for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed roles for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed roles for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } @@ -123,11 +152,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { @Override public List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed groups for " + - "given app release id."); + log.debug("Request received in DAO Layer to get subscribed/unsubscribed groups for the given app release ID."); } try { Connection conn = this.getDBConnection(); @@ -135,13 +163,26 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { String sql = "SELECT " + "GS.GROUP_NAME AS GROUPS " + "FROM AP_GROUP_SUBSCRIPTION GS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND GS.GROUP_NAME LIKE ?"; + } + sql += " ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { - ps.setInt(1, appReleaseId); - ps.setInt(2, tenantId); - ps.setInt(3, offsetValue); - ps.setInt(4, limitValue); + int paramIndex = 1; + ps.setInt(paramIndex++, appReleaseId); + ps.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + ps.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + ps.setString(paramIndex++, "%" + searchName + "%"); + } + ps.setInt(paramIndex++, offsetValue); + ps.setInt(paramIndex, limitValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedGroups.add(rs.getString("GROUPS")); @@ -150,13 +191,12 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { return subscribedGroups; } } catch (DBConnectionException e) { - String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed groups for given app release id."; + String msg = "Error occurred while obtaining the DB connection to get subscribed/unsubscribed groups" + + " for the given app release ID."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed groups for given " + - "app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed groups for the given app release ID."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java index f715a244c5..622ce0c399 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java @@ -39,10 +39,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { @Override public List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed users for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed users for " + "given app release id."); } try { @@ -51,13 +51,28 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { String sql = "SELECT " + "US.USER_NAME AS USER_NAME " + "FROM AP_USER_SUBSCRIPTION US " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ? "; + if (uninstalled != null) { + sql += "AND UNSUBSCRIBED = ? "; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += "AND US.USER_NAME LIKE ? "; + } + sql += "ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, appReleaseId); - stmt.setInt(2, tenantId); - stmt.setInt(3, offsetValue); - stmt.setInt(4, limitValue); + int index = 1; + stmt.setInt(index++, appReleaseId); + stmt.setInt(index++, tenantId); + if (uninstalled != null) { + stmt.setBoolean(index++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + stmt.setString(index++, "%" + searchName + "%"); + } + stmt.setInt(index++, offsetValue); + stmt.setInt(index, limitValue); + try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { subscribedUsers.add(rs.getString("USER_NAME")); @@ -67,11 +82,11 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed users for given app release id."; + "subscribed/unsubscribed users for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed users for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed users for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } @@ -79,10 +94,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { @Override public List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed roles for " + + log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " + "given app release id."); } try { @@ -91,13 +106,29 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { String sql = "SELECT " + "RS.ROLE_NAME AS ROLE " + "FROM AP_ROLE_SUBSCRIPTION RS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "WHERE AP_APP_RELEASE_ID = ? " + + "AND TENANT_ID = ? "; + if (uninstalled != null) { + sql += "AND UNSUBSCRIBED = ? "; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += "AND RS.ROLE_NAME LIKE ? "; + } + sql += "ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { - ps.setInt(1, appReleaseId); - ps.setInt(2, tenantId); - ps.setInt(3, offsetValue); - ps.setInt(4, limitValue); + int paramIndex = 1; + ps.setInt(paramIndex++, appReleaseId); + ps.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + ps.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + ps.setString(paramIndex++, "%" + searchName + "%"); + } + ps.setInt(paramIndex++, offsetValue); + ps.setInt(paramIndex, limitValue); + try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedRoles.add(rs.getString("ROLE")); @@ -107,11 +138,11 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed roles for given app release id."; + "subscribed/unsubscribed roles for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed roles for given app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed roles for given app release id."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } @@ -119,11 +150,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { @Override public List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, - int tenantId) + int tenantId, Boolean uninstalled, String searchName) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to get already subscribed groups for " + - "given app release id."); + log.debug("Request received in DAO Layer to get subscribed/unsubscribed groups for the given app release ID."); } try { Connection conn = this.getDBConnection(); @@ -131,13 +161,26 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { String sql = "SELECT " + "GS.GROUP_NAME AS GROUPS " + "FROM AP_GROUP_SUBSCRIPTION GS " - + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; + if (uninstalled != null) { + sql += " AND UNSUBSCRIBED = ?"; + } + if (searchName != null && !searchName.trim().isEmpty()) { + sql += " AND GS.GROUP_NAME LIKE ?"; + } + sql += " ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { - ps.setInt(1, appReleaseId); - ps.setInt(2, tenantId); - ps.setInt(3, offsetValue); - ps.setInt(4, limitValue); + int paramIndex = 1; + ps.setInt(paramIndex++, appReleaseId); + ps.setInt(paramIndex++, tenantId); + if (uninstalled != null) { + ps.setBoolean(paramIndex++, uninstalled); + } + if (searchName != null && !searchName.trim().isEmpty()) { + ps.setString(paramIndex++, "%" + searchName + "%"); + } + ps.setInt(paramIndex++, offsetValue); + ps.setInt(paramIndex, limitValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedGroups.add(rs.getString("GROUPS")); @@ -146,13 +189,11 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { return subscribedGroups; } } catch (DBConnectionException e) { - String msg = "Error occurred while obtaining the DB connection to get already " + - "subscribed groups for given app release id."; + String msg = "Error occurred while obtaining the DB connection to get subscribed/unsubscribed groups for the given app release ID."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting subscribed groups for given " + - "app release id."; + String msg = "SQL Error occurred while getting subscribed/unsubscribed groups for the given app release ID."; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java index 0c5b4057ff..92f0734c9f 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -1498,7 +1498,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType) + public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType, + Boolean uninstalled, String searchName) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -1513,20 +1514,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { subscriptionList = subscriptionDAO - .getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId); - count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId); - } else { - if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { - subscriptionList = subscriptionDAO - .getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId); - count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId); - } else { - if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { - subscriptionList = subscriptionDAO - .getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId); - count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId); - } - } + .getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName); + count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId, uninstalled, searchName); + } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { + subscriptionList = subscriptionDAO + .getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName); + count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId, uninstalled, searchName); + } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { + subscriptionList = subscriptionDAO + .getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName); + count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId, uninstalled, searchName); } paginationResult.setData(subscriptionList);