From 2da8cdd05feedfb2f540342382570288df096e22 Mon Sep 17 00:00:00 2001 From: ruwin Date: Tue, 10 Sep 2024 07:25:08 +0530 Subject: [PATCH] Fixed the incorrect device statistics issue happening due to REMOVED and DELETED devices. --- ...BasedSubscriptionManagementHelperServiceImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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/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..e78ab631f2 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 @@ -195,10 +195,18 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr } List devices = HelperUtil.getGroupManagementProviderService(). getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false); - List deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList()); + List removedIds = devices.stream() + .filter(device -> {String status = String.valueOf(device.getEnrolmentInfo().getStatus()); + return "REMOVED".equalsIgnoreCase(status) || "DELETED".equalsIgnoreCase(status);}) + .map(device -> device.getEnrolmentInfo().getId()).collect(Collectors.toList()); + List enrollmentIdsOwnByGroup = devices.stream().map(device -> device.getEnrolmentInfo().getId()).collect(Collectors.toList()); + enrollmentIdsOwnByGroup.removeAll(removedIds); + List deviceIdsOwnByGroup = devices.stream() + .filter(device -> enrollmentIdsOwnByGroup.contains(device.getEnrolmentInfo().getId())) + .map(Device::getId).collect(Collectors.toList()); SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); - int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier()); + int allDeviceCount= deviceIdsOwnByGroup.size(); return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); } catch (ApplicationManagementDAOException e) { String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();