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 fdd8a26ac4..28bf05a07a 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 @@ -1710,12 +1710,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { groupDetailMap.put("DeviceCount", groupDetailWithDevices.get("DeviceCount")); // Fetch device subscriptions for each device ID in the group - List> deviceDetails = new ArrayList<>(); + List> pendingDevices = new ArrayList<>(); + List> installedDevices = new ArrayList<>(); + List> errorDevices = new ArrayList<>(); + List> newDevices = new ArrayList<>(); List deviceIds = (List) groupDetailWithDevices.get("DeviceIds"); Map statusCounts = new HashMap<>(); statusCounts.put("PENDING", 0); - statusCounts.put("IN_PROGRESS", 0); statusCounts.put("COMPLETED", 0); statusCounts.put("ERROR", 0); statusCounts.put("NEW", 0); @@ -1728,15 +1730,34 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (subscription.getDeviceId() == deviceId) { Map deviceDetailMap = new HashMap<>(); deviceDetailMap.put("DeviceID", subscription.getDeviceId()); - deviceDetailMap.put("Status", subscription.getStatus()); - deviceDetails.add(deviceDetailMap); +// deviceDetailMap.put("Status", subscription.getStatus()); // if need to get the real status String status = subscription.getStatus(); - statusCounts.put(status, statusCounts.get(status) + 1); + switch (status) { + case "COMPLETED": + installedDevices.add(deviceDetailMap); + statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1); + break; + case "ERROR": + case "INVALID": + case "UNAUTHORIZED": + errorDevices.add(deviceDetailMap); + statusCounts.put("ERROR", statusCounts.get("ERROR") + 1); + break; + case "IN_PROGRESS": + case "PENDING": + case "REPEATED": + pendingDevices.add(deviceDetailMap); + statusCounts.put("PENDING", statusCounts.get("PENDING") + 1); + break; + } isNewDevice = false; } } if (isNewDevice) { + Map newDeviceDetailMap = new HashMap<>(); + newDeviceDetailMap.put("DeviceID", deviceId); + newDevices.add(newDeviceDetailMap); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } } @@ -1748,7 +1769,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { statusPercentages.put(entry.getKey(), percentage); } - groupDetailMap.put("Devices", deviceDetails); + Map devicesMap = new HashMap<>(); + devicesMap.put("PendingDevices", pendingDevices); + devicesMap.put("InstalledDevices", installedDevices); + devicesMap.put("ErrorDevices", errorDevices); + devicesMap.put("NewDevices", newDevices); + + groupDetailMap.put("Devices", devicesMap); groupDetailMap.put("StatusPercentages", statusPercentages); groupDetailsWithDevices.add(groupDetailMap); @@ -1781,11 +1808,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List> userSubscriptions = subscriptionDAO.getUserSubscriptionsByUUID(uuid, unsubscribe, tenantId); List> userSubscriptionsWithDevices = new ArrayList<>(); - DeviceManagementProviderService deviceManagementProviderService = HelperUtil - .getDeviceManagementProviderService(); + DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); for (Map userSubscription : userSubscriptions) { - String userName = (String) userSubscription.get("UserName"); // Retrieve owner details and device IDs for the user using the service layer @@ -1803,12 +1828,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { userSubscriptionMap.put("DeviceCount", ownerDetailsWithDevices.get("DeviceCount")); // Fetch device subscriptions for each device ID associated with the user - List> deviceDetails = new ArrayList<>(); + List> pendingDevices = new ArrayList<>(); + List> installedDevices = new ArrayList<>(); + List> errorDevices = new ArrayList<>(); + List> newDevices = new ArrayList<>(); List deviceIds = (List) ownerDetailsWithDevices.get("DeviceIds"); Map statusCounts = new HashMap<>(); statusCounts.put("PENDING", 0); - statusCounts.put("IN_PROGRESS", 0); statusCounts.put("COMPLETED", 0); statusCounts.put("ERROR", 0); statusCounts.put("NEW", 0); @@ -1821,15 +1848,34 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (subscription.getDeviceId() == deviceId) { Map deviceDetailMap = new HashMap<>(); deviceDetailMap.put("DeviceID", subscription.getDeviceId()); - deviceDetailMap.put("Status", subscription.getStatus()); - deviceDetails.add(deviceDetailMap); +// deviceDetailMap.put("Status", subscription.getStatus()); String status = subscription.getStatus(); - statusCounts.put(status, statusCounts.get(status) + 1); + switch (status) { + case "COMPLETED": + installedDevices.add(deviceDetailMap); + statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1); + break; + case "ERROR": + case "INVALID": + case "UNAUTHORIZED": + errorDevices.add(deviceDetailMap); + statusCounts.put("ERROR", statusCounts.get("ERROR") + 1); + break; + case "IN_PROGRESS": + case "PENDING": + case "REPEATED": + pendingDevices.add(deviceDetailMap); + statusCounts.put("PENDING", statusCounts.get("PENDING") + 1); + break; + } isNewDevice = false; } } if (isNewDevice) { + Map newDeviceDetailMap = new HashMap<>(); + newDeviceDetailMap.put("DeviceID", deviceId); + newDevices.add(newDeviceDetailMap); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } } @@ -1841,7 +1887,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { statusPercentages.put(entry.getKey(), percentage); } - userSubscriptionMap.put("Devices", deviceDetails); + Map devicesMap = new HashMap<>(); + devicesMap.put("PendingDevices", pendingDevices); + devicesMap.put("InstalledDevices", installedDevices); + devicesMap.put("ErrorDevices", errorDevices); + devicesMap.put("NewDevices", newDevices); + + userSubscriptionMap.put("Devices", devicesMap); userSubscriptionMap.put("StatusPercentages", statusPercentages); userSubscriptionsWithDevices.add(userSubscriptionMap); @@ -1876,7 +1928,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); for (Map roleSubscription : roleSubscriptions) { - String roleName = (String) roleSubscription.get("RoleName"); Map roleSubscriptionMap = new HashMap<>(); roleSubscriptionMap.put("RoleName", roleName); @@ -1887,10 +1938,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { roleSubscriptionMap.put("UnsubscribedTimestamp", roleSubscription.get("UnsubscribedTimestamp")); roleSubscriptionMap.put("AppReleaseId", roleSubscription.get("AppReleaseId")); - List> deviceDetails = new ArrayList<>(); + List> pendingDevices = new ArrayList<>(); + List> installedDevices = new ArrayList<>(); + List> errorDevices = new ArrayList<>(); + List> newDevices = new ArrayList<>(); + Map statusCounts = new HashMap<>(); statusCounts.put("PENDING", 0); - statusCounts.put("IN_PROGRESS", 0); statusCounts.put("COMPLETED", 0); statusCounts.put("ERROR", 0); statusCounts.put("NEW", 0); @@ -1922,29 +1976,55 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (deviceSubscription.getDeviceId() == deviceId) { Map deviceDetailMap = new HashMap<>(); deviceDetailMap.put("DeviceID", deviceSubscription.getDeviceId()); - deviceDetailMap.put("Status", deviceSubscription.getStatus()); - deviceDetails.add(deviceDetailMap); +// deviceDetailMap.put("Status", deviceSubscription.getStatus()); String status = deviceSubscription.getStatus(); - statusCounts.put(status, statusCounts.get(status) + 1); + switch (status) { + case "COMPLETED": + installedDevices.add(deviceDetailMap); + statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1); + break; + case "ERROR": + case "INVALID": + case "UNAUTHORIZED": + errorDevices.add(deviceDetailMap); + statusCounts.put("ERROR", statusCounts.get("ERROR") + 1); + break; + case "IN_PROGRESS": + case "PENDING": + case "REPEATED": + pendingDevices.add(deviceDetailMap); + statusCounts.put("PENDING", statusCounts.get("PENDING") + 1); + break; + } isNewDevice = false; } } if (isNewDevice) { + Map newDeviceDetailMap = new HashMap<>(); + newDeviceDetailMap.put("DeviceID", deviceId); + newDevices.add(newDeviceDetailMap); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } } } - int totalDevices = deviceDetails.size(); + int totalDevices = pendingDevices.size() + installedDevices.size() + errorDevices.size() + newDevices.size(); Map statusPercentages = new HashMap<>(); for (Map.Entry entry : statusCounts.entrySet()) { double percentage = totalDevices == 0 ? 0.0 : ((double) entry.getValue() / totalDevices) * 100; statusPercentages.put(entry.getKey(), percentage); } - roleSubscriptionMap.put("Devices", deviceDetails); + Map devicesMap = new HashMap<>(); + devicesMap.put("PendingDevices", pendingDevices); + devicesMap.put("InstalledDevices", installedDevices); + devicesMap.put("ErrorDevices", errorDevices); + devicesMap.put("NewDevices", newDevices); + + roleSubscriptionMap.put("Devices", devicesMap); roleSubscriptionMap.put("StatusPercentages", statusPercentages); + roleSubscriptionMap.put("DeviceCount", totalDevices); roleSubscriptionsWithDevices.add(roleSubscriptionMap); } @@ -1967,6 +2047,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + // Get user list for each role public List getUsersForRole(String roleName) throws UserStoreException { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); int tenantId = ctx.getTenantId(); @@ -1991,6 +2072,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Map operationDetails = deviceManagementProviderService.getOperationDetailsById(operationId); if (operationDetails != null) { deviceSubscription.put("OperationCode", operationDetails.get("OperationCode")); + deviceSubscription.put("OperationDetails", operationDetails.get("OperationDetails")); + deviceSubscription.put("OperationProperties", operationDetails.get("OperationProperties")); } } }