From e024283f25f2dbb4b3954fa9558dfce1c26736ee Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 27 Jun 2024 22:11:30 +0530 Subject: [PATCH] Return device type and identifier with subscription list --- .../mgt/common/DeviceSubscriptionData.java | 18 ++++++++++ .../core/impl/SubscriptionManagerImpl.java | 30 +++++++++++++++++ .../dao/impl/AbstractEnrollmentDAOImpl.java | 4 ++- .../core/dao/impl/AbstractGroupDAOImpl.java | 33 +++++++++++-------- .../device/mgt/core/dto/GroupDetailsDTO.java | 18 ++++++++++ .../mgt/core/dto/OwnerWithDeviceDTO.java | 18 ++++++++++ 6 files changed, 107 insertions(+), 14 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/DeviceSubscriptionData.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java index 465db48c53..b77b2ba599 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java @@ -40,6 +40,8 @@ public class DeviceSubscriptionData { private String unsubscribedBy; private Timestamp unsubscribedTimestamp; private String deviceName; + private String deviceIdentifier; + private String type; public String getAction() { return action; @@ -168,4 +170,20 @@ public class DeviceSubscriptionData { public void setDeviceName(String deviceName) { this.deviceName = deviceName; } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } } 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 0ade616d52..669cdb7745 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 @@ -1792,6 +1792,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setUnsubscribed(subscription.isUnsubscribed()); deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp()); + deviceDetail.setType(groupDetailWithDevices.getDeviceTypes().get(deviceId)); + deviceDetail.setDeviceIdentifier(groupDetailWithDevices.getDeviceIdentifiers().get(deviceId)); status = subscription.getStatus(); switch (status) { @@ -1829,6 +1831,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); + subscribedDeviceDetail.setType(groupDetailWithDevices.getDeviceTypes().get(deviceId)); + subscribedDeviceDetail.setDeviceIdentifier(groupDetailWithDevices.getDeviceIdentifiers().get(deviceId)); subscribedDevices.add(subscribedDeviceDetail); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); isSubscribedDevice = true; @@ -1841,6 +1845,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId)); newDeviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId)); newDeviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId)); + newDeviceDetail.setType(groupDetailWithDevices.getDeviceTypes().get(deviceId)); + newDeviceDetail.setDeviceIdentifier(groupDetailWithDevices.getDeviceIdentifiers().get(deviceId)); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -1975,6 +1981,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setUnsubscribed(subscription.isUnsubscribed()); deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp()); + deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); + deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); status = subscription.getStatus(); switch (status) { @@ -2012,6 +2020,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); + subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); + subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); subscribedDevices.add(subscribedDeviceDetail); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); isSubscribedDevice = true; @@ -2024,6 +2034,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); + newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -2166,6 +2178,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setUnsubscribed(deviceSubscription.isUnsubscribed()); deviceDetail.setUnsubscribedBy(deviceSubscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedTimestamp(deviceSubscription.getUnsubscribedTimestamp()); + deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); + deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); status = deviceSubscription.getStatus(); switch (status) { @@ -2203,6 +2217,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); + subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); + subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); subscribedDevices.add(subscribedDeviceDetail); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); isSubscribedDevice = true; @@ -2215,6 +2231,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); + newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -2359,6 +2377,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setUnsubscribed(subscription.isUnsubscribed()); deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp()); + deviceDetail.setType(ownerWithDevice.getDeviceTypes()); + deviceDetail.setDeviceIdentifier(ownerWithDevice.getDeviceIdentifiers()); String status = subscription.getStatus(); switch (status) { @@ -2393,6 +2413,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribedDeviceDetail.setActionTriggeredTimestamp(allSubscription.getSubscribedTimestamp()); subscribedDeviceDetail.setActionType(allSubscription.getActionTriggeredFrom()); subscribedDeviceDetail.setStatus(allSubscription.getStatus()); + subscribedDeviceDetail.setType(ownerWithDevice.getDeviceTypes()); + subscribedDeviceDetail.setDeviceIdentifier(ownerWithDevice.getDeviceIdentifiers()); subscribedDevices.add(subscribedDeviceDetail); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); } @@ -2402,6 +2424,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceId(deviceId); newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); + newDeviceDetail.setType(ownerWithDevice.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerWithDevice.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } else if (!unsubscribe && !allSubscriptionForSubscribedMap.containsKey(deviceId) && !deviceSubscriptionMap.containsKey(deviceId) @@ -2411,6 +2435,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); + newDeviceDetail.setType(ownerWithDevice.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerWithDevice.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -2521,6 +2547,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setUnsubscribed(subscription.isUnsubscribed()); deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp()); + deviceDetail.setType(ownerWithDevice.getDeviceTypes()); + deviceDetail.setDeviceIdentifier(ownerWithDevice.getDeviceIdentifiers()); String status = subscription.getStatus(); switch (status) { @@ -2547,6 +2575,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); + newDeviceDetail.setType(ownerWithDevice.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerWithDevice.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java index dff096c933..2ee345fd77 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java @@ -571,7 +571,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { List deviceIds = new ArrayList<>(); int deviceCount = 0; - String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME " + + String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME, e.DEVICE_TYPE AS DEVICE_TYPE, e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION " + "FROM DM_ENROLMENT e " + "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + "WHERE e.OWNER = ? AND e.TENANT_ID = ?"; @@ -600,6 +600,8 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { ownerDetails.setDeviceIds(deviceIds); ownerDetails.setDeviceStatus("DEVICE_STATUS"); ownerDetails.setDeviceNames("DEVICE_NAME"); + ownerDetails.setDeviceTypes("DEVICE_TYPE"); + ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION"); ownerDetails.setDeviceCount(deviceCount); return ownerDetails; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java index c3aa38539d..3c5d836f49 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java @@ -1451,6 +1451,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { Map deviceOwners = new HashMap<>(); Map deviceStatuses = new HashMap<>(); Map deviceNames = new HashMap<>(); + Map deviceTypes = new HashMap<>(); + Map deviceIdentifiers = new HashMap<>(); String sql = "SELECT " + @@ -1459,6 +1461,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { " g.OWNER AS GROUP_OWNER, " + " e.OWNER AS DEVICE_OWNER, " + " e.STATUS AS DEVICE_STATUS, " + + " e.DEVICE_TYPE AS DEVICE_TYPE, " + + " e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + " dgm.DEVICE_ID, " + " d.NAME AS DEVICE_NAME " + "FROM " + @@ -1480,19 +1484,20 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { stmt.setInt(3, limit); stmt.setInt(4, offset); - try (ResultSet rs = stmt.executeQuery()) { - while (rs.next()) { - if (groupDetails.getGroupId() == 0) { - groupDetails.setGroupId(rs.getInt("GROUP_ID")); - groupDetails.setGroupName(rs.getString("GROUP_NAME")); - groupDetails.setGroupOwner(rs.getString("GROUP_OWNER")); - } - int deviceId = rs.getInt("DEVICE_ID"); - deviceIds.add(deviceId); - deviceOwners.put(deviceId, rs.getString("DEVICE_OWNER")); - deviceStatuses.put(deviceId, rs.getString("DEVICE_STATUS")); - deviceNames.put(deviceId, rs.getString("DEVICE_NAME")); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + if (groupDetails.getGroupId() == 0) { + groupDetails.setGroupId(rs.getInt("GROUP_ID")); + groupDetails.setGroupName(rs.getString("GROUP_NAME")); + groupDetails.setGroupOwner(rs.getString("GROUP_OWNER")); } + int deviceId = rs.getInt("DEVICE_ID"); + deviceIds.add(deviceId); + deviceOwners.put(deviceId, rs.getString("DEVICE_OWNER")); + deviceStatuses.put(deviceId, rs.getString("DEVICE_STATUS")); + deviceNames.put(deviceId, rs.getString("DEVICE_NAME")); + deviceTypes.put(deviceId, rs.getString("DEVICE_TYPE")); + deviceIdentifiers.put(deviceId, rs.getString("DEVICE_IDENTIFICATION")); } } } catch (SQLException e) { @@ -1505,6 +1510,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { groupDetails.setDeviceOwners(deviceOwners); groupDetails.setDeviceStatuses(deviceStatuses); groupDetails.setDeviceNames(deviceNames); + groupDetails.setDeviceTypes(deviceTypes); + groupDetails.setDeviceIdentifiers(deviceIdentifiers); return groupDetails; } -} \ No newline at end of file +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/GroupDetailsDTO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/GroupDetailsDTO.java index 289fcfd472..c3a20d5217 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/GroupDetailsDTO.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/GroupDetailsDTO.java @@ -32,6 +32,8 @@ public class GroupDetailsDTO { private Map deviceOwners; private Map deviceStatuses; private Map deviceNames; + private Map deviceTypes; + private Map deviceIdentifiers; public int getGroupId() { return groupId; @@ -112,4 +114,20 @@ public class GroupDetailsDTO { public void setDeviceNames(Map deviceNames) { this.deviceNames = deviceNames; } + + public Map getDeviceTypes() { + return deviceTypes; + } + + public void setDeviceTypes(Map deviceTypes) { + this.deviceTypes = deviceTypes; + } + + public Map getDeviceIdentifiers() { + return deviceIdentifiers; + } + + public void setDeviceIdentifiers(Map deviceIdentifiers) { + this.deviceIdentifiers = deviceIdentifiers; + } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/OwnerWithDeviceDTO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/OwnerWithDeviceDTO.java index 9d644b1930..be6f63702a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/OwnerWithDeviceDTO.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dto/OwnerWithDeviceDTO.java @@ -27,6 +27,8 @@ public class OwnerWithDeviceDTO { private int deviceCount; private String deviceStatus; private String deviceNames; + private String deviceTypes; + private String deviceIdentifiers; public String getUserName() { return userName; @@ -67,4 +69,20 @@ public class OwnerWithDeviceDTO { public void setDeviceNames(String deviceNames) { this.deviceNames = deviceNames; } + + public String getDeviceTypes() { + return deviceTypes; + } + + public void setDeviceTypes(String deviceTypes) { + this.deviceTypes = deviceTypes; + } + + public String getDeviceIdentifiers() { + return deviceIdentifiers; + } + + public void setDeviceIdentifiers(String deviceIdentifiers) { + this.deviceIdentifiers = deviceIdentifiers; + } }