Set the correct count value of the subscribers retrieving API

feature/appm-store/pbac
Nipun Nadeen De Silva 5 years ago committed by Dharmakeerthi Lasantha
parent f01636a2b0
commit 3f582db051

@ -165,6 +165,8 @@ public interface SubscriptionDAO {
int tenantId)
throws ApplicationManagementDAOException;
int getSubscribedUserCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of roles
*
@ -179,6 +181,8 @@ public interface SubscriptionDAO {
int tenantId)
throws ApplicationManagementDAOException;
int getSubscribedRoleCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of subscribed groups
*
@ -191,4 +195,6 @@ public interface SubscriptionDAO {
*/
List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId)
throws ApplicationManagementDAOException;
int getSubscribedGroupCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
}

@ -877,6 +877,44 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
}
@Override
public int getSubscribedUserCount(int appReleaseId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed 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 = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("USER_NAME");
}
}
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.";
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.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<ScheduledSubscriptionDTO> getScheduledSubscriptionByStatus(ExecutionStatus status, boolean deleted)
throws ApplicationManagementDAOException {
@ -986,6 +1024,44 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
}
@Override
public int getSubscribedRoleCount(int appReleaseId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed 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 = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("ROLE_NAME");
}
}
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.";
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.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public ScheduledSubscriptionDTO getPendingScheduledSubscriptionByTaskName(String taskName)
throws ApplicationManagementDAOException {
@ -1066,4 +1142,42 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public int getSubscribedGroupCount(int appReleaseId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +
"given app release id.");
}
try {
Connection conn = this.getDBConnection();
String sql = "SELECT "
+ "COUNT(GS.GROUP_NAME) AS GROUPS "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("GROUPS");
}
}
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.";
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.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -1137,18 +1137,22 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<String> subscriptionList = new ArrayList<>();
int count = 0;
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);
}
int count = subscriptionList.size();
paginationResult.setData(subscriptionList);
paginationResult.setRecordsFiltered(count);
paginationResult.setRecordsTotal(count);

Loading…
Cancel
Save