From 6db42a0f4bdd75b4cd7419b19c33032ccda9e682 Mon Sep 17 00:00:00 2001 From: nipuni Date: Tue, 18 Jun 2024 08:57:58 +0530 Subject: [PATCH 1/2] Generalize JSON keys of application subscription APIs. --- .../mgt/common/DeviceSubscriptionData.java | 9 ++ .../common/dto/SubscriptionResponseDTO.java | 36 ++--- ...onDetailDTO.java => SubscriptionsDTO.java} | 86 ++++++------ .../mgt/common/dto/UserSubscriptionDTO.java | 132 ------------------ .../common/services/SubscriptionManager.java | 16 +-- .../mgt/core/dao/SubscriptionDAO.java | 11 +- .../GenericSubscriptionDAOImpl.java | 25 ++-- .../core/impl/SubscriptionManagerImpl.java | 60 ++++---- .../dao/impl/AbstractEnrollmentDAOImpl.java | 16 ++- .../core/dao/impl/AbstractGroupDAOImpl.java | 26 +++- .../device/mgt/core/dto/GroupDetailsDTO.java | 9 ++ .../mgt/core/dto/OwnerWithDeviceDTO.java | 9 ++ 12 files changed, 173 insertions(+), 262 deletions(-) rename components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/{GroupSubscriptionDetailDTO.java => SubscriptionsDTO.java} (80%) delete mode 100644 components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/UserSubscriptionDTO.java 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 aadbfaca6a..465db48c53 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 @@ -39,6 +39,7 @@ public class DeviceSubscriptionData { private boolean unsubscribed; private String unsubscribedBy; private Timestamp unsubscribedTimestamp; + private String deviceName; public String getAction() { return action; @@ -159,4 +160,12 @@ public class DeviceSubscriptionData { public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) { this.unsubscribedTimestamp = unsubscribedTimestamp; } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } } 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/dto/SubscriptionResponseDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionResponseDTO.java index aecee2460f..3db74aeae4 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionResponseDTO.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionResponseDTO.java @@ -5,9 +5,7 @@ import java.util.List; public class SubscriptionResponseDTO { private String UUID; - private List GroupsSubscriptions; - private List UserSubscriptions; - private List RolesSubscriptions; + private List subscriptions; private List DevicesOperations; public String getUUID() { @@ -18,30 +16,6 @@ public class SubscriptionResponseDTO { this.UUID = UUID; } - public List getGroupsSubscriptions() { - return GroupsSubscriptions; - } - - public void setGroupsSubscriptions(List groupsSubscriptions) { - GroupsSubscriptions = groupsSubscriptions; - } - - public List getUserSubscriptions() { - return UserSubscriptions; - } - - public void setUserSubscriptions(List userSubscriptions) { - UserSubscriptions = userSubscriptions; - } - - public List getRolesSubscriptions() { - return RolesSubscriptions; - } - - public void setRolesSubscriptions(List rolesSubscriptions) { - RolesSubscriptions = rolesSubscriptions; - } - public List getDevicesOperations() { return DevicesOperations; } @@ -49,4 +23,12 @@ public class SubscriptionResponseDTO { public void setDevicesOperations(List devicesOperations) { DevicesOperations = devicesOperations; } + + public List getSubscriptions() { + return subscriptions; + } + + public void setSubscriptions(List subscriptions) { + this.subscriptions = subscriptions; + } } 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/dto/GroupSubscriptionDetailDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionsDTO.java similarity index 80% rename from components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/GroupSubscriptionDetailDTO.java rename to components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionsDTO.java index bc215b1e30..cb127696e3 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/GroupSubscriptionDetailDTO.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionsDTO.java @@ -23,45 +23,45 @@ import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionR import java.sql.Timestamp; import java.util.Map; -public class GroupSubscriptionDetailDTO { - private int groupId; - private String groupName; - private String groupOwner; +public class SubscriptionsDTO { + private int id; + private String owner; + private String name; private String subscribedBy; private Timestamp subscribedTimestamp; - private boolean isUnsubscribed; + private boolean unsubscribed; private String unsubscribedBy; private Timestamp unsubscribedTimestamp; + private String subscribedFrom; private int appReleaseId; private int deviceCount; private String deviceOwner; private String deviceStatus; - private CategorizedSubscriptionResult devices; private Map statusPercentages; + private CategorizedSubscriptionResult devices; - // Getters and Setters - public int getGroupId() { - return groupId; + public int getId() { + return id; } - public void setGroupId(int groupId) { - this.groupId = groupId; + public void setId(int id) { + this.id = id; } - public String getGroupName() { - return groupName; + public String getOwner() { + return owner; } - public void setGroupName(String groupName) { - this.groupName = groupName; + public void setOwner(String owner) { + this.owner = owner; } - public String getGroupOwner() { - return groupOwner; + public String getName() { + return name; } - public void setGroupOwner(String groupOwner) { - this.groupOwner = groupOwner; + public void setName(String name) { + this.name = name; } public String getSubscribedBy() { @@ -80,14 +80,6 @@ public class GroupSubscriptionDetailDTO { this.subscribedTimestamp = subscribedTimestamp; } - public boolean isUnsubscribed() { - return isUnsubscribed; - } - - public void setUnsubscribed(boolean unsubscribed) { - isUnsubscribed = unsubscribed; - } - public String getUnsubscribedBy() { return unsubscribedBy; } @@ -104,6 +96,14 @@ public class GroupSubscriptionDetailDTO { this.unsubscribedTimestamp = unsubscribedTimestamp; } + public String getSubscribedFrom() { + return subscribedFrom; + } + + public void setSubscribedFrom(String subscribedFrom) { + this.subscribedFrom = subscribedFrom; + } + public int getAppReleaseId() { return appReleaseId; } @@ -120,12 +120,20 @@ public class GroupSubscriptionDetailDTO { this.deviceCount = deviceCount; } - public CategorizedSubscriptionResult getDevices() { - return devices; + public String getDeviceOwner() { + return deviceOwner; } - public void setDevices(CategorizedSubscriptionResult devices) { - this.devices = devices; + public void setDeviceOwner(String deviceOwner) { + this.deviceOwner = deviceOwner; + } + + public String getDeviceStatus() { + return deviceStatus; + } + + public void setDeviceStatus(String deviceStatus) { + this.deviceStatus = deviceStatus; } public Map getStatusPercentages() { @@ -136,19 +144,19 @@ public class GroupSubscriptionDetailDTO { this.statusPercentages = statusPercentages; } - public String getDeviceOwner() { - return deviceOwner; + public CategorizedSubscriptionResult getDevices() { + return devices; } - public void setDeviceOwner(String deviceOwner) { - this.deviceOwner = deviceOwner; + public void setDevices(CategorizedSubscriptionResult devices) { + this.devices = devices; } - public String getDeviceStatus() { - return deviceStatus; + public boolean getUnsubscribed() { + return unsubscribed; } - public void setDeviceStatus(String deviceStatus) { - this.deviceStatus = deviceStatus; + public void setUnsubscribed(boolean unsubscribed) { + this.unsubscribed = unsubscribed; } } 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/dto/UserSubscriptionDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/UserSubscriptionDTO.java deleted file mode 100644 index d3fd89f004..0000000000 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/UserSubscriptionDTO.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.entgra.device.mgt.core.application.mgt.common.dto; - -import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult; - -import java.sql.Timestamp; -import java.util.Map; - -public class UserSubscriptionDTO { - - private String userName; - private String subscribedBy; - private Timestamp subscribedTimestamp; - private boolean unsubscribed; - private String unsubscribedBy; - private Timestamp unsubscribedTimestamp; - private int appReleaseId; - private int deviceCount; - private String deviceStatus; - private Map statusPercentages; - private CategorizedSubscriptionResult devices; - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getSubscribedBy() { - return subscribedBy; - } - - public void setSubscribedBy(String subscribedBy) { - this.subscribedBy = subscribedBy; - } - - public Timestamp getSubscribedTimestamp() { - return subscribedTimestamp; - } - - public void setSubscribedTimestamp(Timestamp subscribedTimestamp) { - this.subscribedTimestamp = subscribedTimestamp; - } - - public boolean isUnsubscribed() { - return unsubscribed; - } - - public boolean getUnsubscribed() { - return unsubscribed; - } - - public void setUnsubscribed(boolean unsubscribed) { - this.unsubscribed = unsubscribed; - } - - public String getUnsubscribedBy() { - return unsubscribedBy; - } - - public void setUnsubscribedBy(String unsubscribedBy) { - this.unsubscribedBy = unsubscribedBy; - } - - public Timestamp getUnsubscribedTimestamp() { - return unsubscribedTimestamp; - } - - public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) { - this.unsubscribedTimestamp = unsubscribedTimestamp; - } - - public int getAppReleaseId() { - return appReleaseId; - } - - public void setAppReleaseId(int appReleaseId) { - this.appReleaseId = appReleaseId; - } - - public int getDeviceCount() { - return deviceCount; - } - - public void setDeviceCount(int deviceCount) { - this.deviceCount = deviceCount; - } - - public Map getStatusPercentages() { - return statusPercentages; - } - - public void setStatusPercentages(Map statusPercentages) { - this.statusPercentages = statusPercentages; - } - - public CategorizedSubscriptionResult getDevices() { - return devices; - } - - public void setDevices(CategorizedSubscriptionResult devices) { - this.devices = devices; - } - - public String getDeviceStatus() { - return deviceStatus; - } - - public void setDeviceStatus(String deviceStatus) { - this.deviceStatus = deviceStatus; - } -} - 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/services/SubscriptionManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java index fc0463add2..500c324cd0 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java @@ -22,10 +22,8 @@ import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionR import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus; import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType; import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDetailDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO; +import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionResponseDTO; import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException; @@ -232,10 +230,10 @@ public interface SubscriptionManager { * @param subscriptionStatus the status of the subscription (subscribed or unsubscribed) * @param offset the offset for the data set * @param limit the limit for the data set - * @return {@link GroupSubscriptionDetailDTO} which contains the details of group subscriptions. + * @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @throws ApplicationManagementException if an error occurs while fetching the group details */ - List getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit) + List getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit) throws ApplicationManagementException; /** @@ -245,10 +243,10 @@ public interface SubscriptionManager { * @param subscriptionStatus the status of the subscription (subscribed or unsubscribed) * @param offset the offset for the data set * @param limit the limit for the data set - * @return {@link UserSubscriptionDTO} which contains the details of user subscriptions. + * @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @throws ApplicationManagementException if an error occurs while fetching the user details */ - List getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) + List getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) throws ApplicationManagementException; /** @@ -258,10 +256,10 @@ public interface SubscriptionManager { * @param subscriptionStatus the status of the subscription (subscribed or unsubscribed) * @param offset the offset for the data set * @param limit the limit for the data set - * @return {@link RoleSubscriptionDTO} which contains the details of role subscriptions. + * @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @throws ApplicationManagementException if an error occurs while fetching the role details */ - List getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) + List getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) throws ApplicationManagementException; /** 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/dao/SubscriptionDAO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java index a91d13eb06..cb32453082 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java @@ -19,11 +19,10 @@ package io.entgra.device.mgt.core.application.mgt.core.dao; import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus; import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO; +import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO; import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException; import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException; @@ -339,10 +338,10 @@ public interface SubscriptionDAO { * @param tenantId id of the current tenant. * @param offset the offset for the data set * @param limit the limit for the data set - * @return {@link UserSubscriptionDTO} which contains the details of user subscriptions. + * @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails. */ - List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, + List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit) throws ApplicationManagementDAOException; /** @@ -353,10 +352,10 @@ public interface SubscriptionDAO { * @param tenantId id of the current tenant. * @param offset the offset for the data set * @param limit the limit for the data set - * @return {@link RoleSubscriptionDTO} which contains the details of role subscriptions. + * @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails. */ - List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit) + List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit) throws ApplicationManagementDAOException; /** 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/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index bf25c9c2b5..ad10bde91d 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -19,8 +19,7 @@ package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription; import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO; +import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO; import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO; import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; @@ -1694,14 +1693,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, - int offset, int limit) throws ApplicationManagementDAOException { + public List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, + int offset, int limit) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get user subscriptions related to the given UUID."); } try { Connection conn = this.getDBConnection(); - List userSubscriptions = new ArrayList<>(); + List userSubscriptions = new ArrayList<>(); String subscriptionStatusTime = unsubscribe ? "US.UNSUBSCRIBED_TIMESTAMP" : "US.SUBSCRIBED_TIMESTAMP"; String sql = "SELECT US.USER_NAME, US.SUBSCRIBED_BY, US.SUBSCRIBED_TIMESTAMP, US.UNSUBSCRIBED, " + @@ -1718,9 +1717,9 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc ps.setInt(5, offset); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { - UserSubscriptionDTO userSubscription; - userSubscription = new UserSubscriptionDTO(); - userSubscription.setUserName(rs.getString("USER_NAME")); + SubscriptionsDTO userSubscription; + userSubscription = new SubscriptionsDTO(); + userSubscription.setName(rs.getString("USER_NAME")); userSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY")); userSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP")); userSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED")); @@ -1745,14 +1744,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, + public List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get role subscriptions related to the given AppReleaseID."); } try { Connection conn = this.getDBConnection(); - List roleSubscriptions = new ArrayList<>(); + List roleSubscriptions = new ArrayList<>(); String subscriptionStatusTime = unsubscribe ? "ARS.UNSUBSCRIBED_TIMESTAMP" : "ARS.SUBSCRIBED_TIMESTAMP"; String sql = "SELECT ARS.ROLE_NAME, ARS.SUBSCRIBED_BY, ARS.SUBSCRIBED_TIMESTAMP, ARS.UNSUBSCRIBED, " + @@ -1768,10 +1767,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc ps.setInt(4, limit); ps.setInt(5, offset); try (ResultSet rs = ps.executeQuery()) { - RoleSubscriptionDTO roleSubscription; + SubscriptionsDTO roleSubscription; while (rs.next()) { - roleSubscription = new RoleSubscriptionDTO(); - roleSubscription.setRoleName(rs.getString("ROLE_NAME")); + roleSubscription = new SubscriptionsDTO(); + roleSubscription.setName(rs.getString("ROLE_NAME")); roleSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY")); roleSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP")); roleSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED")); 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 aeebeb2c50..81c3f2d680 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 @@ -26,9 +26,7 @@ import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionR import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData; import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDetailDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO; +import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionResponseDTO; import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes; @@ -1706,8 +1704,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public List getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, - int limit) throws ApplicationManagementException { + public List getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, + int limit) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); String groupName; @@ -1724,7 +1722,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } int appReleaseId = applicationReleaseDTO.getId(); - List groupDetailsWithDevices = new ArrayList<>(); + List groupDetailsWithDevices = new ArrayList<>(); List groupDetails = subscriptionDAO.getGroupsSubscriptionDetailsByAppReleaseID(appReleaseId, unsubscribe, tenantId, offset, limit); @@ -1741,10 +1739,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { GroupDetailsDTO groupDetailWithDevices = groupManagementProviderService.getGroupDetailsWithDevices(groupName, offset, limit); - GroupSubscriptionDetailDTO groupDetailDTO = new GroupSubscriptionDetailDTO(); - groupDetailDTO.setGroupId(groupDetailWithDevices.getGroupId()); - groupDetailDTO.setGroupName(groupDetail.getGroupName()); - groupDetailDTO.setGroupOwner(groupDetailWithDevices.getGroupOwner()); + SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO(); + groupDetailDTO.setId(groupDetailWithDevices.getGroupId()); + groupDetailDTO.setName(groupDetail.getGroupName()); + groupDetailDTO.setOwner(groupDetailWithDevices.getGroupOwner()); groupDetailDTO.setSubscribedBy(groupDetail.getSubscribedBy()); groupDetailDTO.setSubscribedTimestamp(groupDetail.getSubscribedTimestamp()); groupDetailDTO.setUnsubscribed(groupDetail.isUnsubscribed()); @@ -1787,6 +1785,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setActionType(subscription.getActionTriggeredFrom()); deviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId)); deviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId)); + deviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId)); deviceDetail.setSubId(subscription.getId()); deviceDetail.setActionTriggeredBy(subscription.getSubscribedBy()); deviceDetail.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp()); @@ -1824,6 +1823,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId()); subscribedDeviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId)); subscribedDeviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId)); + subscribedDeviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId)); subscribedDeviceDetail.setSubId(subscribedDevice.getId()); subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy()); subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); @@ -1840,6 +1840,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceId(deviceId); newDeviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId)); newDeviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId)); + newDeviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId)); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -1886,7 +1887,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public List getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) + public List getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); @@ -1904,9 +1905,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } int appReleaseId = applicationReleaseDTO.getId(); - List userSubscriptionsWithDevices = new ArrayList<>(); + List userSubscriptionsWithDevices = new ArrayList<>(); - List userSubscriptions = + List userSubscriptions = subscriptionDAO.getUserSubscriptionsByAppReleaseID(appReleaseId, unsubscribe, tenantId, offset, limit); if (userSubscriptions == null) { throw new ApplicationManagementException("User details not found for appReleaseId: " + appReleaseId); @@ -1914,15 +1915,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); - for (UserSubscriptionDTO userSubscription : userSubscriptions) { - userName = userSubscription.getUserName(); + for (SubscriptionsDTO userSubscription : userSubscriptions) { + userName = userSubscription.getName(); // Retrieve owner details and device IDs for the user using the service layer OwnerWithDeviceDTO ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(userName); - UserSubscriptionDTO userSubscriptionDTO = new UserSubscriptionDTO(); - userSubscriptionDTO.setUserName(userSubscription.getUserName()); + SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO(); + userSubscriptionDTO.setName(userSubscription.getName()); userSubscriptionDTO.setSubscribedBy(userSubscription.getSubscribedBy()); userSubscriptionDTO.setSubscribedTimestamp(userSubscription.getSubscribedTimestamp()); userSubscriptionDTO.setUnsubscribed(userSubscription.getUnsubscribed()); @@ -1964,6 +1965,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceDetail.setSubId(subscription.getId()); deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); + deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); deviceDetail.setActionType(subscription.getActionTriggeredFrom()); deviceDetail.setStatus(subscription.getStatus()); deviceDetail.setActionType(subscription.getActionTriggeredFrom()); @@ -2001,6 +2003,7 @@ 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.setSubId(subscribedDevice.getId()); @@ -2019,6 +2022,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { newDeviceDetail.setDeviceId(deviceId); newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); + newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); newDevices.add(newDeviceDetail); statusCounts.put("NEW", statusCounts.get("NEW") + 1); } @@ -2063,7 +2067,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public List getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) + public List getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); @@ -2081,9 +2085,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } int appReleaseId = applicationReleaseDTO.getId(); - List roleSubscriptionsWithDevices = new ArrayList<>(); + List roleSubscriptionsWithDevices = new ArrayList<>(); - List roleSubscriptions = + List roleSubscriptions = subscriptionDAO.getRoleSubscriptionsByAppReleaseID(appReleaseId, unsubscribe, tenantId, offset, limit); if (roleSubscriptions == null) { throw new ApplicationManagementException("Role details not found for appReleaseId: " + appReleaseId); @@ -2091,11 +2095,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); - for (RoleSubscriptionDTO roleSubscription : roleSubscriptions) { - roleName = roleSubscription.getRoleName(); + for (SubscriptionsDTO roleSubscription : roleSubscriptions) { + roleName = roleSubscription.getName(); - RoleSubscriptionDTO roleSubscriptionDTO = new RoleSubscriptionDTO(); - roleSubscriptionDTO.setRoleName(roleSubscription.getRoleName()); + SubscriptionsDTO roleSubscriptionDTO = new SubscriptionsDTO(); + roleSubscriptionDTO.setName(roleSubscription.getName()); roleSubscriptionDTO.setSubscribedBy(roleSubscription.getSubscribedBy()); roleSubscriptionDTO.setSubscribedTimestamp(roleSubscription.getSubscribedTimestamp()); roleSubscriptionDTO.setUnsubscribed(roleSubscription.getUnsubscribed()); @@ -2148,6 +2152,7 @@ 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.setActionType(deviceSubscription.getActionTriggeredFrom()); @@ -2188,6 +2193,7 @@ 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.setSubId(subscribedDevice.getId()); @@ -2204,6 +2210,7 @@ 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()); newDevices.add(newDeviceDetail); @@ -2339,6 +2346,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); deviceDetail.setDeviceId(subscription.getDeviceId()); deviceDetail.setSubId(subscription.getId()); + deviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); deviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); deviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); deviceDetail.setActionType(subscription.getActionTriggeredFrom()); @@ -2374,6 +2382,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (!allSubscription.isUnsubscribed()) { DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData(); subscribedDeviceDetail.setDeviceId(allSubscription.getDeviceId()); + subscribedDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); subscribedDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); subscribedDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); subscribedDeviceDetail.setSubId(allSubscription.getId()); @@ -2396,6 +2405,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { && (allDevicesMap.containsKey(deviceId))) { DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData(); newDeviceDetail.setDeviceId(deviceId); + newDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); newDevices.add(newDeviceDetail); @@ -2496,6 +2506,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceSubscriptionDTO subscription = allSubscriptionMap.get(deviceId); DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); deviceDetail.setDeviceId(subscription.getDeviceId()); + deviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); deviceDetail.setSubId(subscription.getId()); deviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); deviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); @@ -2529,6 +2540,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } else { DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData(); newDeviceDetail.setDeviceId(deviceId); + newDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames()); newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName()); newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus()); newDevices.add(newDeviceDetail); 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 7f43707259..6612564fa6 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 @@ -567,9 +567,10 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { List deviceIds = new ArrayList<>(); int deviceCount = 0; - String sql = "SELECT DEVICE_ID, OWNER, STATUS AS DEVICE_STATUS " + - "FROM DM_ENROLMENT " + - "WHERE OWNER = ? AND TENANT_ID = ?"; + String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME " + + "FROM DM_ENROLMENT e " + + "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + + "WHERE e.OWNER = ? AND e.TENANT_ID = ?"; try (Connection conn = this.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -591,6 +592,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { ownerDetails.setDeviceIds(deviceIds); ownerDetails.setDeviceStatus("DEVICE_STATUS"); + ownerDetails.setDeviceNames("DEVICE_NAME"); ownerDetails.setDeviceCount(deviceCount); return ownerDetails; } @@ -600,9 +602,10 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { throws DeviceManagementDAOException { OwnerWithDeviceDTO deviceOwnerWithStatus = new OwnerWithDeviceDTO(); - String sql = "SELECT DEVICE_ID, OWNER, STATUS AS DEVICE_STATUS " + - "FROM DM_ENROLMENT " + - "WHERE DEVICE_ID = ? AND TENANT_ID = ?"; + String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME " + + "FROM DM_ENROLMENT e " + + "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + + "WHERE e.DEVICE_ID = ? AND e.TENANT_ID = ?"; try (Connection conn = this.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -616,6 +619,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { List deviceIds = new ArrayList<>(); deviceIds.add(rs.getInt("DEVICE_ID")); deviceOwnerWithStatus.setDeviceIds(deviceIds); + deviceOwnerWithStatus.setDeviceNames(rs.getString("DEVICE_NAME")); } } } catch (SQLException 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/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 858df67b3c..8794e268b7 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 @@ -1450,13 +1450,25 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { List deviceIds = new ArrayList<>(); Map deviceOwners = new HashMap<>(); Map deviceStatuses = new HashMap<>(); + Map deviceNames = new HashMap<>(); // New map for device names String sql = - "SELECT g.ID AS GROUP_ID, g.GROUP_NAME, g.OWNER, e.OWNER AS DEVICE_OWNER, e.STATUS AS DEVICE_STATUS, dgm.DEVICE_ID " - + "FROM DM_GROUP g " - + "JOIN DM_DEVICE_GROUP_MAP dgm ON g.ID = dgm.GROUP_ID " - + "JOIN DM_ENROLMENT e ON dgm.DEVICE_ID = e.DEVICE_ID " - + "WHERE g.GROUP_NAME = ? AND g.TENANT_ID = ? " + + "SELECT " + + " g.ID AS GROUP_ID, " + + " g.GROUP_NAME, " + + " g.OWNER AS GROUP_OWNER, " + + " e.OWNER AS DEVICE_OWNER, " + + " e.STATUS AS DEVICE_STATUS, " + + " dgm.DEVICE_ID, " + + " d.NAME AS DEVICE_NAME " + + "FROM " + + " DM_GROUP g " + + " JOIN DM_DEVICE_GROUP_MAP dgm ON g.ID = dgm.GROUP_ID " + + " JOIN DM_ENROLMENT e ON dgm.DEVICE_ID = e.DEVICE_ID " + + " JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + + "WHERE " + + " g.GROUP_NAME = ? " + + " AND g.TENANT_ID = ? " + "LIMIT ? OFFSET ?"; try (Connection conn = GroupManagementDAOFactory.getConnection(); @@ -1471,12 +1483,13 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { if (groupDetails.getGroupId() == 0) { groupDetails.setGroupId(rs.getInt("GROUP_ID")); groupDetails.setGroupName(rs.getString("GROUP_NAME")); - groupDetails.setGroupOwner(rs.getString("OWNER")); + 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")); } } } catch (SQLException e) { @@ -1488,6 +1501,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { groupDetails.setDeviceCount(deviceIds.size()); groupDetails.setDeviceOwners(deviceOwners); groupDetails.setDeviceStatuses(deviceStatuses); + groupDetails.setDeviceNames(deviceNames); return groupDetails; } } 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 4882bcbd3a..289fcfd472 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 @@ -31,6 +31,7 @@ public class GroupDetailsDTO { private String deviceStatus; private Map deviceOwners; private Map deviceStatuses; + private Map deviceNames; public int getGroupId() { return groupId; @@ -103,4 +104,12 @@ public class GroupDetailsDTO { public void setDeviceStatuses(Map deviceStatuses) { this.deviceStatuses = deviceStatuses; } + + public Map getDeviceNames() { + return deviceNames; + } + + public void setDeviceNames(Map deviceNames) { + this.deviceNames = deviceNames; + } } 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 5445069e8b..9d644b1930 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 @@ -26,6 +26,7 @@ public class OwnerWithDeviceDTO { private List deviceIds; private int deviceCount; private String deviceStatus; + private String deviceNames; public String getUserName() { return userName; @@ -58,4 +59,12 @@ public class OwnerWithDeviceDTO { public void setDeviceStatus(String deviceStatus) { this.deviceStatus = deviceStatus; } + + public String getDeviceNames() { + return deviceNames; + } + + public void setDeviceNames(String deviceNames) { + this.deviceNames = deviceNames; + } } From 128682ce7730fc5b2d48361521f0336917fcfe09 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Tue, 25 Jun 2024 09:12:24 +0530 Subject: [PATCH 2/2] Limit device percentages to two decimals --- .../mgt/core/impl/SubscriptionManagerImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 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 81c3f2d680..a55ea7126f 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 @@ -1851,7 +1851,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Map statusPercentages = new HashMap<>(); for (Map.Entry entry : statusCounts.entrySet()) { double percentage = ((double) entry.getValue() / totalDevices) * 100; - statusPercentages.put(entry.getKey(), percentage); + String formattedPercentage = String.format("%.2f", percentage); + statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); } CategorizedSubscriptionResult categorizedSubscriptionResult; @@ -2033,7 +2034,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Map statusPercentages = new HashMap<>(); for (Map.Entry entry : statusCounts.entrySet()) { double percentage = ((double) entry.getValue() / totalDevices) * 100; - statusPercentages.put(entry.getKey(), percentage); + String formattedPercentage = String.format("%.2f", percentage); + statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); } CategorizedSubscriptionResult categorizedSubscriptionResult; @@ -2225,7 +2227,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { 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); + String formattedPercentage = String.format("%.2f", percentage); + statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); } CategorizedSubscriptionResult categorizedSubscriptionResult; @@ -2417,7 +2420,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Map statusPercentages = new HashMap<>(); for (Map.Entry entry : statusCounts.entrySet()) { double percentage = ((double) entry.getValue() / totalDevices) * 100; - statusPercentages.put(entry.getKey(), percentage); + String formattedPercentage = String.format("%.2f", percentage); + statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); } CategorizedSubscriptionResult categorizedSubscriptionResult; @@ -2552,7 +2556,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Map statusPercentages = new HashMap<>(); for (Map.Entry entry : statusCounts.entrySet()) { double percentage = ((double) entry.getValue() / totalDevices) * 100; - statusPercentages.put(entry.getKey(), percentage); + String formattedPercentage = String.format("%.2f", percentage); + statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); } CategorizedSubscriptionResult categorizedSubscriptionResult =