From ba5333242c735e56d0df0585237dbd02cad709b5 Mon Sep 17 00:00:00 2001 From: ruwin Date: Mon, 5 Aug 2024 16:34:32 +0530 Subject: [PATCH] Refactor subscription related methods (cherry picked from commit 00d13c904fd446de18d582e7dc8e82ff07771d35) --- .../core/impl/SubscriptionManagerImpl.java | 103 +++++++++----- ...bscriptionManagementHelperServiceImpl.java | 126 ++++++++++-------- ...bscriptionManagementHelperServiceImpl.java | 110 ++++++++------- ...bscriptionManagementHelperServiceImpl.java | 110 ++++++++------- 4 files changed, 258 insertions(+), 191 deletions(-) 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 49552ea153..5ec7bbda1f 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 @@ -19,32 +19,13 @@ package io.entgra.device.mgt.core.application.mgt.core.impl; import com.google.gson.Gson; -import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse; -import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo; -import io.entgra.device.mgt.core.application.mgt.common.ApplicationType; -import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult; -import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData; -import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo; -import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse; -import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics; -import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO; -import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes; -import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus; -import io.entgra.device.mgt.core.application.mgt.common.SubAction; -import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder; -import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType; -import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO; +import io.entgra.device.mgt.core.application.mgt.common.*; +import io.entgra.device.mgt.core.application.mgt.common.dto.*; import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager; import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO; import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO; import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; +import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil; import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementServiceProvider; import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; @@ -122,14 +103,7 @@ import java.net.URL; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -1709,9 +1683,72 @@ public class SubscriptionManagerImpl implements SubscriptionManager { @Override public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException { - SubscriptionManagementHelperService subscriptionManagementHelperService = - SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo); - return subscriptionManagementHelperService.getSubscriptions(subscriptionInfo, limit, offset); + final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); + final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + ConnectionManagerUtil.openDBConnection(); + ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. + getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't find an application release for application release UUID: " + + subscriptionInfo.getApplicationUUID(); + 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) { + String msg = "Error encountered while connecting to the database"; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } +// @Override +// public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) +// throws ApplicationManagementException { +// SubscriptionManagementHelperService subscriptionManagementHelperService = +// SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo); +// return subscriptionManagementHelperService.getSubscriptions(subscriptionInfo, limit, offset); +// } + + + public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) + throws ApplicationManagementException { + final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + ConnectionManagerUtil.openDBConnection(); + ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. + getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't find an application release for application release UUID: " + + subscriptionInfo.getApplicationUUID(); + 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) { + String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier(); + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (GroupManagementException e) { + String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier(); + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } /** 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/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java index 16834bf2a1..7521fa112a 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java @@ -150,69 +150,79 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr } @Override - public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) - throws ApplicationManagementException { - final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); - final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { - ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. - getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for application release UUID: " + - subscriptionInfo.getApplicationUUID(); - 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) { - String msg = "Error encountered while connecting to the database"; - log.error(msg, e); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException { + return null; } @Override - public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) - throws ApplicationManagementException { - final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { - ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. - getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for application release UUID: " + - subscriptionInfo.getApplicationUUID(); - 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) { - String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier(); - log.error(msg, e); - throw new ApplicationManagementException(msg, e); - } catch (GroupManagementException e) { - String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier(); - log.error(msg, e); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { + return null; } +// @Override +// public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) +// throws ApplicationManagementException { +// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); +// final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); +// try { +// ConnectionManagerUtil.openDBConnection(); +// ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. +// getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); +// if (applicationReleaseDTO == null) { +// String msg = "Couldn't find an application release for application release UUID: " + +// subscriptionInfo.getApplicationUUID(); +// 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) { +// String msg = "Error encountered while connecting to the database"; +// log.error(msg, e); +// throw new ApplicationManagementException(msg, e); +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } + +// @Override +// public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) +// throws ApplicationManagementException { +// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); +// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); +// try { +// ConnectionManagerUtil.openDBConnection(); +// ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. +// getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); +// if (applicationReleaseDTO == null) { +// String msg = "Couldn't find an application release for application release UUID: " + +// subscriptionInfo.getApplicationUUID(); +// 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) { +// String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier(); +// log.error(msg, e); +// throw new ApplicationManagementException(msg, e); +// } catch (GroupManagementException e) { +// String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier(); +// log.error(msg, e); +// throw new ApplicationManagementException(msg, e); +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } + private static class GroupBasedSubscriptionManagementHelperServiceImplHolder { private static final GroupBasedSubscriptionManagementHelperServiceImpl INSTANCE = new GroupBasedSubscriptionManagementHelperServiceImpl(); 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/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java index b667198fd5..031b1a4f99 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java @@ -144,62 +144,72 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri } @Override - public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) - throws ApplicationManagementException { - final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); - final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { - ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. - getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for application release UUID: " + - subscriptionInfo.getApplicationUUID(); - log.error(msg); - throw new NotFoundException(msg); - } - 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); - } catch (DBConnectionException | ApplicationManagementDAOException e) { - String msg = "Error encountered while connecting to the database"; - log.error(msg, e); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException { + return null; } @Override public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { - final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { - ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. - getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for application release UUID: " + - subscriptionInfo.getApplicationUUID(); - log.error(msg); - throw new NotFoundException(msg); - } - List deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId); - SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. - getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); - int allDeviceCount = deviceIdsOwnByRole.size(); - return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); - } catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) { - String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier(); - log.error(msg, e); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + return null; } +// @Override +// public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) +// throws ApplicationManagementException { +// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); +// final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); +// try { +// ConnectionManagerUtil.openDBConnection(); +// ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. +// getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); +// if (applicationReleaseDTO == null) { +// String msg = "Couldn't find an application release for application release UUID: " + +// subscriptionInfo.getApplicationUUID(); +// log.error(msg); +// throw new NotFoundException(msg); +// } +// 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); +// } catch (DBConnectionException | ApplicationManagementDAOException e) { +// String msg = "Error encountered while connecting to the database"; +// log.error(msg, e); +// throw new ApplicationManagementException(msg, e); +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } + +// @Override +// public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { +// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); +// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); +// try { +// ConnectionManagerUtil.openDBConnection(); +// ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. +// getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); +// if (applicationReleaseDTO == null) { +// String msg = "Couldn't find an application release for application release UUID: " + +// subscriptionInfo.getApplicationUUID(); +// log.error(msg); +// throw new NotFoundException(msg); +// } +// List deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId); +// SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. +// getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); +// int allDeviceCount = deviceIdsOwnByRole.size(); +// return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); +// } catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) { +// String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier(); +// log.error(msg, e); +// throw new ApplicationManagementException(msg, e); +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } + @SuppressWarnings("unchecked") private List getDeviceIdsOwnByRole(String roleName, int tenantId) throws UserStoreException, DeviceManagementException { UserStoreManager userStoreManager = DataHolder.getInstance().getRealmService(). 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/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java index b8978b1c7a..c973b053d8 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java @@ -135,62 +135,72 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri } @Override - public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) - throws ApplicationManagementException { - final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); - final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { - ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. - getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for application release UUID: " + - subscriptionInfo.getApplicationUUID(); - log.error(msg); - throw new NotFoundException(msg); - } - 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); - } catch (DBConnectionException | ApplicationManagementDAOException e) { - String msg = "Error encountered while connecting to the database"; - log.error(msg, e); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException { + return null; } @Override public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { - final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { - ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. - getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for application release UUID: " + - subscriptionInfo.getApplicationUUID(); - log.error(msg); - throw new NotFoundException(msg); - } - List deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); - SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. - getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); - int allDeviceCount = deviceIdsOwnByUser.size(); - return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); - } catch (DeviceManagementException | ApplicationManagementDAOException 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(); - } + return null; } +// @Override +// public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) +// throws ApplicationManagementException { +// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); +// final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); +// try { +// ConnectionManagerUtil.openDBConnection(); +// ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. +// getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); +// if (applicationReleaseDTO == null) { +// String msg = "Couldn't find an application release for application release UUID: " + +// subscriptionInfo.getApplicationUUID(); +// log.error(msg); +// throw new NotFoundException(msg); +// } +// 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); +// } catch (DBConnectionException | ApplicationManagementDAOException e) { +// String msg = "Error encountered while connecting to the database"; +// log.error(msg, e); +// throw new ApplicationManagementException(msg, e); +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } + +// @Override +// public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { +// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); +// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); +// try { +// ConnectionManagerUtil.openDBConnection(); +// ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. +// getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); +// if (applicationReleaseDTO == null) { +// String msg = "Couldn't find an application release for application release UUID: " + +// subscriptionInfo.getApplicationUUID(); +// log.error(msg); +// throw new NotFoundException(msg); +// } +// List deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); +// SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. +// getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); +// int allDeviceCount = deviceIdsOwnByUser.size(); +// return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); +// } catch (DeviceManagementException | ApplicationManagementDAOException 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(); +// } +// } + @SuppressWarnings("unchecked") private List getDeviceIdsOwnByUser(String username) throws DeviceManagementException { List deviceListOwnByUser = new ArrayList<>();