From 29951a156092f7eae7e4958686070b60776cdb78 Mon Sep 17 00:00:00 2001 From: nipunnadeen Date: Tue, 24 Sep 2019 22:50:36 +0530 Subject: [PATCH] Create an API to get subscribed Category details --- .../core/impl/SubscriptionManagerImpl.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) 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 bc8476ea01d..0fbb5a57093 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 @@ -667,4 +667,53 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.closeDBConnection(); } } + + @Override + public PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, + String appUUID, String subType) + throws ApplicationManagementException { + + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + PaginationResult paginationResult = new PaginationResult(); + try { + ConnectionManagerUtil.openDBConnection(); + + ApplicationDTO applicationDTO = this.applicationDAO + .getAppWithRelatedRelease(appUUID, tenantId); + int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); + + int count=0; + List SubscriptionList = new ArrayList<>(); + + if(SubsciptionType.USER.toString().equalsIgnoreCase(subType)){ + SubscriptionList = subscriptionDAO + .getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId); + }else if(SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)){ + SubscriptionList = subscriptionDAO + .getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId); + }else if(SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) { + SubscriptionList = subscriptionDAO + .getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId); + } + count = SubscriptionList.size(); + paginationResult.setData(SubscriptionList); + paginationResult.setRecordsFiltered(count); + paginationResult.setRecordsTotal(count); + + return paginationResult; + + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred when get application release data for application" + + " release UUID: " + appUUID; + throw new ApplicationManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "DB Connection error occurred while getting category details that " + + "given application id"; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } }