From 0ee44127700f791a8f0a94abb48213b33d58dbd2 Mon Sep 17 00:00:00 2001 From: ruwin Date: Tue, 20 Aug 2024 02:07:17 +0530 Subject: [PATCH] =?UTF-8?q?=1B[200~Refactored=20the=20code=20in=20subscrip?= =?UTF-8?q?tion=20management.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/services/SubscriptionManager.java | 6 - .../core/impl/SubscriptionManagerImpl.java | 280 +++++------------- 2 files changed, 77 insertions(+), 209 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 15cf23af56..aabb895ac0 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 @@ -252,12 +252,6 @@ public interface SubscriptionManager { SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException; -// SubscriptionResponse getStatusBaseSubscriptionsGroup(SubscriptionInfo subscriptionInfo, int limit, int offset) -// throws ApplicationManagementException; - -// SubscriptionResponse getStatusBaseSubscriptionsAll(SubscriptionInfo subscriptionInfo, int limit, int offset) -// throws ApplicationManagementException; - /** * Get subscription statistics related data describes by the {@link SubscriptionInfo} 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 e52b375e97..56158dea2d 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 @@ -1696,12 +1696,28 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } - List subscriptionEntities = subscriptionDAO. - getGroupsSubscriptionDetailsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit); - int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) : - subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId); - return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities); - } catch (DBConnectionException | ApplicationManagementDAOException e) { + if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.GROUP)) { + List subscriptionEntities = subscriptionDAO. + getGroupsSubscriptionDetailsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit); + int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) : + subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId); + return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities); + } if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.ROLE)){ + List subscriptionEntities = subscriptionDAO. + getRoleSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit); + int subscriptionCount = isUnsubscribe ? subscriptionDAO.getRoleUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) : + subscriptionDAO.getRoleSubscriptionCount(applicationReleaseDTO.getId(), tenantId); + return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities); + } if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.USER)){ + List subscriptionEntities = subscriptionDAO. + getUserSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit); + int subscriptionCount = isUnsubscribe ? subscriptionDAO.getUserUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) : + subscriptionDAO.getUserSubscriptionCount(applicationReleaseDTO.getId(), tenantId); + return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities); + } else { + return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), Collections.emptyList()); + } + } catch (DBConnectionException | ApplicationManagementDAOException e) { String msg = "Error encountered while connecting to the database"; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -1710,6 +1726,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + /** + * Retrieves subscription statistics described by the {@link SubscriptionInfo} entity. + * @param subscriptionInfo The {@link SubscriptionInfo} containing details about the subscription type and identifier. + * @return {@link SubscriptionStatistics} The subscription statistics for the specified subscription type and identifier. + * @throws ApplicationManagementException Throws when an error is encountered while getting subscription statistics. + */ public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { @@ -1728,14 +1750,30 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } - List devices = HelperUtil.getGroupManagementProviderService(). - getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false); - List deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList()); - SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. - getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); - int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier()); - return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); - } catch (ApplicationManagementDAOException e) { + if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.GROUP)) { + List devices = HelperUtil.getGroupManagementProviderService(). + getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false); + List deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList()); + SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. + getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); + int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier()); + return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); + } if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.ROLE)){ + List deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId); + SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. + getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); + int allDeviceCount = deviceIdsOwnByRole.size(); + return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); + } if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.USER)){ + List deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); + SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. + getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); + int allDeviceCount = deviceIdsOwnByUser.size(); + return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); + } else { + return null; + } + } catch (ApplicationManagementDAOException e) { String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier(); log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -1743,6 +1781,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier(); log.error(msg, e); throw new ApplicationManagementException(msg, e); + } catch (UserStoreException e) { + String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier(); + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (DeviceManagementException e) { + String msg = "Error encountered while getting subscription statistics for user: " + subscriptionInfo.getIdentifier(); + log.error(msg, e); + throw new ApplicationManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1767,175 +1813,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return getStatusBaseSubscriptionsRoleUser(subscriptionInfo, limit, offset); } } -// -// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); -// List deviceSubscriptionDTOS; -// int deviceCount = 0; -// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); -// -// try { -// ConnectionManagerUtil.openDBConnection(); -// ApplicationReleaseDTO applicationReleaseDTO = getApplicationRelease(subscriptionInfo.getApplicationUUID(), tenantId); -// ApplicationDTO applicationDTO = getApplication(subscriptionInfo.getApplicationUUID(), tenantId); -// -// String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo); -// DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria(); -// -// if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.GROUP)){ -// deviceSubscriptionDTOS = handleGroupSubscription(subscriptionInfo, limit, offset, isUnsubscribe, applicationReleaseDTO, applicationDTO, deviceSubscriptionStatus, deviceSubscriptionFilterCriteria); -// } if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.DEVICE)) { -// deviceSubscriptionDTOS = handleDeviceSubscription(subscriptionInfo, isUnsubscribe, applicationReleaseDTO, deviceSubscriptionStatus, deviceSubscriptionFilterCriteria); -// } else { -// getStatusBaseSubscriptionsRoleUser(subscriptionInfo, limit, offset); -// } -// -// List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS, -// subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset); -// return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions); -// } catch (Exception e) { -// handleException(e, subscriptionInfo.getIdentifier()); -// return null; // This line will not be reached due to exception handling, but is required for compilation. -// } finally { -// ConnectionManagerUtil.closeDBConnection(); -// } -// } -// -// private ApplicationReleaseDTO getApplicationRelease(String applicationUUID, int tenantId) throws ApplicationManagementException { -// ApplicationReleaseDTO applicationReleaseDTO = null; -// try { -// applicationReleaseDTO = applicationReleaseDAO.getReleaseByUUID(applicationUUID, tenantId); -// } catch (ApplicationManagementDAOException e) { -// throw new RuntimeException(e); -// } -// if (applicationReleaseDTO == null) { -// String msg = "Couldn't find an application release for application release UUID: " + applicationUUID; -// log.error(msg); -// throw new NotFoundException(msg); -// } -// return applicationReleaseDTO; -// } -// -// private ApplicationDTO getApplication(String applicationUUID, int tenantId) throws ApplicationManagementException { -// ApplicationDTO applicationDTO = null; -// try { -// applicationDTO = this.applicationDAO.getAppWithRelatedRelease(applicationUUID, tenantId); -// } catch (ApplicationManagementDAOException e) { -// throw new RuntimeException(e); -// } -// if (applicationDTO == null) { -// String msg = "Application not found for the release UUID: " + applicationUUID; -// log.error(msg); -// throw new NotFoundException(msg); -// } -// return applicationDTO; -// } -// -// private List handleDeviceSubscription(SubscriptionInfo subscriptionInfo, boolean isUnsubscribe, ApplicationReleaseDTO applicationReleaseDTO, -// String deviceSubscriptionStatus, DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria) throws DeviceManagementException { -// DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); -// List deviceSubscriptionDTOS; -// List dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus()); -// -// if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) { -// try { -// deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.getId(), -// isUnsubscribe, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(), null, null, -// deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); -// } catch (ApplicationManagementDAOException e) { -// throw new RuntimeException(e); -// } -// -// List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream() -// .map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList()); -// -// List newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription); -// -// deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); -// } else { -// try { -// deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.getId(), -// isUnsubscribe, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(), dbSubscriptionStatus, null, -// deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); -// } catch (ApplicationManagementDAOException e) { -// throw new RuntimeException(e); -// } -// } -// return deviceSubscriptionDTOS; -// } -// -// private List handleGroupSubscription(SubscriptionInfo subscriptionInfo, int limit, int offset, boolean isUnsubscribe, -// ApplicationReleaseDTO applicationReleaseDTO, ApplicationDTO applicationDTO, String deviceSubscriptionStatus, DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria) -// throws GroupManagementException, DeviceManagementException { -// GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService(); -// DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); -// List deviceSubscriptionDTOS; -// List dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus()); -// -// if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) { -// List allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(), -// applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(), -// deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1).getDeviceIds(); -// -// try { -// deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(), -// isUnsubscribe, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(), allDeviceIdsOwnByGroup, null, -// null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); -// } catch (ApplicationManagementDAOException e) { -// throw new RuntimeException(e); -// } -// -// List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream() -// .map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList()); -// -// for (Integer deviceId : deviceIdsOfSubscription) { -// allDeviceIdsOwnByGroup.remove(deviceId); -// } -// -// List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(allDeviceIdsOwnByGroup); -// deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); -// } else { -// GroupDetailsDTO groupDetailsDTO = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(), -// applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(), -// deviceSubscriptionFilterCriteria.getDeviceStatus(), offset, limit); -// List paginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds(); -// -// try { -// deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(), -// isUnsubscribe, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(), paginatedDeviceIdsOwnByGroup, dbSubscriptionStatus, -// null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); -// } catch (ApplicationManagementDAOException e) { -// throw new RuntimeException(e); -// } -// } -// return deviceSubscriptionDTOS; -// } -// -// private void handleException(Exception e, String identifier) throws ApplicationManagementException { -// if (e instanceof GroupManagementException) { -// String msg = "Error encountered while retrieving group details for group: " + identifier; -// log.error(msg, e); -// throw new ApplicationManagementException(msg, e); -// } else if (e instanceof ApplicationManagementDAOException || e instanceof DBConnectionException) { -// String msg = "Error encountered while connecting to the database"; -// log.error(msg, e); -// throw new ApplicationManagementException(msg, e); -// } else if (e instanceof DeviceManagementException) { -// throw new RuntimeException(e); -// } else { -// String msg = "Unexpected error occurred"; -// log.error(msg, e); -// throw new ApplicationManagementException(msg, e); -// } -// } -// - public SubscriptionResponse getStatusBaseSubscriptionsDevice(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException { -// if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.DEVICE)){ -// return null; -// } final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); List deviceSubscriptionDTOS; int deviceCount = 0; @@ -2093,7 +1974,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { try { ConnectionManagerUtil.openDBConnection(); - List deviceIdsOwnByRole = getAllDeviceIds(subscriptionInfo); + List deviceIdsOwnByRoleUser = getAllDeviceIds(subscriptionInfo); ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); @@ -2118,21 +1999,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) { deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(), - isUnsubscribe, tenantId, deviceIdsOwnByRole, null, + isUnsubscribe, tenantId, deviceIdsOwnByRoleUser, null, null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream(). map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList()); for (Integer deviceId : deviceIdsOfSubscription) { - deviceIdsOwnByRole.remove(deviceId); + deviceIdsOwnByRoleUser.remove(deviceId); } - List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRole); + List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRoleUser); deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); } else { deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(), - isUnsubscribe, tenantId, deviceIdsOwnByRole, dbSubscriptionStatus, + isUnsubscribe, tenantId, deviceIdsOwnByRoleUser, dbSubscriptionStatus, subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); } deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, @@ -2181,25 +2062,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return deviceListOwnByRole.stream().map(Device::getId).collect(Collectors.toList()); } - - - private List getAllDeviceIds (SubscriptionInfo subscriptionInfo) throws DeviceManagementException, UserStoreException { - String type = subscriptionInfo.getSubscriptionType(); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - if (Objects.equals(type, SubscriptionMetadata.SubscriptionTypes.ROLE)){ - return getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(),tenantId); - } -// if (Objects.equals(type, SubscriptionMetadata.SubscriptionTypes.GROUP)){ -// return getDeviceIdsOwnByGroup(subscriptionInfo.getIdentifier(),tenantId); -// } - if (Objects.equals(type,SubscriptionMetadata.SubscriptionTypes.USER)){ - return getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); - }else - return null; - } - - - @SuppressWarnings("unchecked") private List getDeviceIdsOwnByUser(String username) throws DeviceManagementException { List deviceListOwnByUser = new ArrayList<>(); @@ -2214,6 +2076,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return deviceListOwnByUser.stream().map(Device::getId).collect(Collectors.toList()); } + private List getAllDeviceIds (SubscriptionInfo subscriptionInfo) throws DeviceManagementException, UserStoreException { + String type = subscriptionInfo.getSubscriptionType(); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + if (Objects.equals(type, SubscriptionMetadata.SubscriptionTypes.ROLE)){ + return getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(),tenantId); + } + if (Objects.equals(type,SubscriptionMetadata.SubscriptionTypes.USER)){ + return getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); + }else + return null; + } + /** * Get subscription statistics related data describes by the {@link SubscriptionInfo}