From de1d79f27c2f2ef2d9f8802d2efcc88b35b25839 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 11 Jul 2024 23:53:34 +0530 Subject: [PATCH 1/2] Fix same device data loading for subscriptions --- .../core/impl/SubscriptionManagerImpl.java | 76 +++++++++++-------- .../dao/impl/AbstractEnrollmentDAOImpl.java | 12 +-- 2 files changed, 51 insertions(+), 37 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 203740c6da..174e317ee6 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 @@ -1929,6 +1929,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // Retrieve owner details and device IDs for the user using the service layer OwnerWithDeviceDTO ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(userName, applicationDTO.getDeviceTypeId()); + log.info("line no 1932 device ids : " + ownerDetailsWithDevices.getDeviceIds()); + log.info("line no 1933 device identifiers : " + ownerDetailsWithDevices.getDeviceIdentifiers()); + log.info("line no 1934 device names : " + ownerDetailsWithDevices.getDeviceNames()); SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO(); userSubscriptionDTO.setName(userSubscription.getName()); @@ -1965,15 +1968,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager { for (Integer deviceId : deviceIds) { List deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( userSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds); + OwnerWithDeviceDTO ownerWithDeviceByDeviceId = + deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId); + if (ownerWithDeviceByDeviceId == null) { + continue; + } boolean isNewDevice = true; for (DeviceSubscriptionDTO subscription : deviceSubscriptions) { if (subscription.getDeviceId() == deviceId) { DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); deviceDetail.setDeviceId(subscription.getDeviceId()); deviceDetail.setSubId(subscription.getId()); - deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); - deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); - deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); + deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName()); + deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus()); + deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames()); deviceDetail.setActionType(subscription.getActionTriggeredFrom()); deviceDetail.setStatus(subscription.getStatus()); deviceDetail.setActionType(subscription.getActionTriggeredFrom()); @@ -1982,8 +1990,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()); + deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes()); + deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers()); status = subscription.getStatus(); switch (status) { @@ -2013,16 +2021,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (subscribedDevice.getDeviceId() == deviceId) { DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData(); subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId()); - subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); - subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); - subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); + subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames()); + subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName()); + subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus()); subscribedDeviceDetail.setSubId(subscribedDevice.getId()); subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy()); subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); - subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); - subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); + subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes()); + subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers()); subscribedDevices.add(subscribedDeviceDetail); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); isSubscribedDevice = true; @@ -2032,11 +2040,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (!isSubscribedDevice) { DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData(); newDeviceDetail.setDeviceId(deviceId); - newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); - newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); - newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); - newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); - newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); + newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName()); + newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus()); + newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames()); + newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -2153,7 +2161,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( appReleaseId, !unsubscribe, tenantId, deviceIds); } - + OwnerWithDeviceDTO ownerWithDeviceByDeviceId = + deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId); + if (ownerWithDeviceByDeviceId == null) { + continue; + } List deviceSubscriptions; try { deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( @@ -2167,9 +2179,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (deviceSubscription.getDeviceId() == deviceId) { DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); deviceDetail.setDeviceId(deviceSubscription.getDeviceId()); - deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); - deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); - deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); + deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames()); + deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName()); + deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus()); deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom()); deviceDetail.setStatus(deviceSubscription.getStatus()); deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom()); @@ -2179,8 +2191,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()); + deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes()); + deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers()); status = deviceSubscription.getStatus(); switch (status) { @@ -2210,16 +2222,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (subscribedDevice.getDeviceId() == deviceId) { DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData(); subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId()); - subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); - subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); - subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); + subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames()); + subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName()); + subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus()); subscribedDeviceDetail.setSubId(subscribedDevice.getId()); subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy()); subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); - subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); - subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); + subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes()); + subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers()); subscribedDevices.add(subscribedDeviceDetail); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); isSubscribedDevice = true; @@ -2229,11 +2241,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (!isSubscribedDevice) { DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData(); newDeviceDetail.setDeviceId(deviceId); - newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); - newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); - newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); - newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); - newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); + newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames()); + newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName()); + newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus()); + newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes()); + newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -2266,7 +2278,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } return roleSubscriptionsWithDevices; - } catch (ApplicationManagementDAOException e) { + } catch (ApplicationManagementDAOException | DeviceManagementDAOException e) { String msg = "Error occurred in retrieving role subscriptions with devices"; log.error(msg, e); throw new ApplicationManagementException(msg, e); 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 6f9d3e727f..9a25164a5b 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 @@ -597,9 +597,11 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { while (rs.next()) { if (ownerDetails.getUserName() == null) { ownerDetails.setUserName(rs.getString("OWNER")); - ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS")); - ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME")); } + ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS")); + ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME")); + ownerDetails.setDeviceTypes("DEVICE_TYPE"); + ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION"); deviceIds.add(rs.getInt("DEVICE_ID")); deviceCount++; } @@ -610,11 +612,11 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { log.error(msg, e); throw new DeviceManagementDAOException(msg, e); } - ownerDetails.setDeviceIds(deviceIds); - ownerDetails.setDeviceTypes("DEVICE_TYPE"); - ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION"); ownerDetails.setDeviceCount(deviceCount); + log.info("line no 617 device ids : " + ownerDetails.getDeviceIds()); + log.info("line no 618 device identifiers : " + ownerDetails.getDeviceIdentifiers()); + log.info("line no 619 device names : " + ownerDetails.getDeviceNames()); return ownerDetails; } From 11bca0f4ae99a17363b257a6a270c6900011af12 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 11 Jul 2024 23:57:14 +0530 Subject: [PATCH 2/2] Remove unnecessary logs --- .../application/mgt/core/impl/SubscriptionManagerImpl.java | 3 --- .../device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java | 3 --- 2 files changed, 6 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 174e317ee6..6d90d22272 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 @@ -1929,9 +1929,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // Retrieve owner details and device IDs for the user using the service layer OwnerWithDeviceDTO ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(userName, applicationDTO.getDeviceTypeId()); - log.info("line no 1932 device ids : " + ownerDetailsWithDevices.getDeviceIds()); - log.info("line no 1933 device identifiers : " + ownerDetailsWithDevices.getDeviceIdentifiers()); - log.info("line no 1934 device names : " + ownerDetailsWithDevices.getDeviceNames()); SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO(); userSubscriptionDTO.setName(userSubscription.getName()); 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 9a25164a5b..98ef10ebe6 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 @@ -614,9 +614,6 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } ownerDetails.setDeviceIds(deviceIds); ownerDetails.setDeviceCount(deviceCount); - log.info("line no 617 device ids : " + ownerDetails.getDeviceIds()); - log.info("line no 618 device identifiers : " + ownerDetails.getDeviceIdentifiers()); - log.info("line no 619 device names : " + ownerDetails.getDeviceNames()); return ownerDetails; }