Fixed the incorrect device statistics issue happening due to REMOVED and DELETED devices.

pagination
Ruwin Dissanayake 2 months ago
parent 35ab8ceb97
commit 2da8cdd05f

@ -195,10 +195,18 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
} }
List<Device> devices = HelperUtil.getGroupManagementProviderService(). List<Device> devices = HelperUtil.getGroupManagementProviderService().
getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false); getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false);
List<Integer> deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList()); List<Integer> 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<Integer> enrollmentIdsOwnByGroup = devices.stream().map(device -> device.getEnrolmentInfo().getId()).collect(Collectors.toList());
enrollmentIdsOwnByGroup.removeAll(removedIds);
List<Integer> deviceIdsOwnByGroup = devices.stream()
.filter(device -> enrollmentIdsOwnByGroup.contains(device.getEnrolmentInfo().getId()))
.map(Device::getId).collect(Collectors.toList());
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier()); int allDeviceCount= deviceIdsOwnByGroup.size();
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier(); String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();

Loading…
Cancel
Save