Implement the search API for Subscription details view

sub-search
Nipuni Kavindya 3 months ago
parent a22c7eac4d
commit 99b1f17215

@ -187,11 +187,12 @@ 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
* @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) throws ApplicationManagementException;
/**
* This method is responsible to provide application subscription data for given application release UUID.

@ -198,14 +198,30 @@ 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.
* @return subscribedUsers - list of app subscribed users.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
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.
* @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) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of roles
@ -214,14 +230,31 @@ 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.
* @return subscribedRoles - list of app subscribed roles.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
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.
* @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) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of subscribed groups
@ -230,13 +263,29 @@ 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.
* @return subscribedGroups - list of app subscribed groups.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId)
List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId, Boolean uninstalled)
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.
* @return subscribedGroups - list of app subscribed groups.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
int getSubscribedGroupCount(int appReleaseId, int tenantId,Boolean uninstalled) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of subscribed groups

@ -967,25 +967,31 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
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<String> 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 = ? ";
}
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);
}
stmt.setInt(index++, limitValue);
stmt.setInt(index, offsetValue);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
subscribedUsers.add(rs.getString("USER_NAME"));
@ -994,39 +1000,42 @@ 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)
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 = ?";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
if (uninstalled != null) {
stmt.setBoolean(3, uninstalled);
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("USER_NAME");
return rs.getInt("USER_COUNT");
}
}
return 0;
@ -1037,7 +1046,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
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 users count for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -1151,10 +1160,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
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 {
@ -1163,13 +1172,21 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
String sql = "SELECT "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
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 = 3;
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
ps.setInt(paramIndex++, limitValue);
ps.setInt(paramIndex, offsetValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedRoles.add(rs.getString("ROLE"));
@ -1190,38 +1207,43 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public int getSubscribedRoleCount(int appReleaseId, int tenantId)
public int getSubscribedRoleCount(int appReleaseId, int tenantId, Boolean uninstalled)
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 "
+ "COUNT(RS.ROLE_NAME) AS ROLE_COUNT "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
if (uninstalled != null) {
stmt.setBoolean(3, uninstalled);
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("ROLE_NAME");
}
return rs.getInt("ROLE_COUNT");
}
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 roles count for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -1269,25 +1291,31 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
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<String> 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 = ?";
}
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);
}
ps.setInt(paramIndex++, limitValue);
ps.setInt(paramIndex, offsetValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedGroups.add(rs.getString("APP_GROUPS"));
@ -1297,11 +1325,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 +1337,27 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public int getSubscribedGroupCount(int appReleaseId, int tenantId)
public int getSubscribedGroupCount(int appReleaseId, int tenantId, Boolean uninstalled)
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 the count of subscribed 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 = ?";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
if (uninstalled != null) {
stmt.setBoolean(3, uninstalled);
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("APP_GROUPS_COUNT");
@ -1335,12 +1366,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 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 groups for given " +
"app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}

@ -43,7 +43,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for " +
@ -83,7 +83,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed roles for " +
@ -123,7 +123,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +

@ -39,7 +39,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for " +
@ -79,7 +79,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed roles for " +
@ -119,7 +119,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +

@ -1498,7 +1498,7 @@ 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)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1513,20 +1513,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)) {
.getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled);
count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId, uninstalled);
} 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)) {
.getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled);
count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId, uninstalled);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscriptionList = subscriptionDAO
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId);
}
}
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId, uninstalled);
}
paginationResult.setData(subscriptionList);

Loading…
Cancel
Save