From f9cea050aefb7b559ac78a7b899b8cf2a19fcebc Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Wed, 10 Jul 2024 11:22:17 +0530 Subject: [PATCH 1/4] Fix user,role removed devices --- .../core/device/mgt/core/dao/EnrollmentDAO.java | 3 ++- .../dao/impl/AbstractEnrollmentDAOImpl.java | 17 ++++++++++++++--- .../DeviceManagementProviderServiceImpl.java | 7 ++++++- 3 files changed, 22 insertions(+), 5 deletions(-) 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/EnrollmentDAO.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/EnrollmentDAO.java index 93c456f929..df812fc62f 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/EnrollmentDAO.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/EnrollmentDAO.java @@ -101,11 +101,12 @@ public interface EnrollmentDAO { * Retrieves owners and the list of device IDs related to an owner. * * @param owner the owner whose device IDs need to be retrieved + * @param allowingDeviceStatuses statuses of devices need to be retrieved * @param tenantId the ID of the tenant * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user * @throws DeviceManagementDAOException if an error occurs while fetching the data */ - OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId) throws DeviceManagementDAOException; + OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId) throws DeviceManagementDAOException; /** * Retrieves a list of device IDs with owners and device status. 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 dad35f0795..7e02bd7ac0 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 @@ -564,23 +564,34 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } @Override - public OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId) + public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId) throws DeviceManagementDAOException { Connection conn = null; OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO(); List deviceIds = new ArrayList<>(); int deviceCount = 0; + StringBuilder deviceFilters = new StringBuilder(); + for (int i = 0; i < allowingDeviceStatuses.size(); i++) { + deviceFilters.append("?"); + if (i < allowingDeviceStatuses.size() - 1) { + deviceFilters.append(","); + } + } + 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 = ?"; + "WHERE e.OWNER = ? AND e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")"; + try { conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, owner); stmt.setInt(2, tenantId); - + for (int i = 0; i < allowingDeviceStatuses.size(); i++) { + stmt.setString(3 + i, allowingDeviceStatuses.get(i)); + } try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { if (ownerDetails.getUserName() == null) { 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/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index a3039ba356..d2d73dc92a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -5358,9 +5358,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); OwnerWithDeviceDTO ownerWithDeviceDTO; + List allowingDeviceStatuses = new ArrayList<>(); + allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString()); + allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString()); + allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString()); + try { DeviceManagementDAOFactory.openConnection(); - ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, tenantId); + ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, allowingDeviceStatuses, tenantId); if (ownerWithDeviceDTO == null) { String msg = "No data found for owner: " + owner; log.error(msg); From 68a4de92d654ea38244610d51358b0896c0258c3 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 11 Jul 2024 00:49:59 +0530 Subject: [PATCH 2/4] Fix all,device,group removed devices --- .../device/mgt/core/dao/EnrollmentDAO.java | 2 +- .../core/device/mgt/core/dao/GroupDAO.java | 2 +- .../dao/impl/AbstractEnrollmentDAOImpl.java | 23 +++++++-- .../core/dao/impl/AbstractGroupDAOImpl.java | 49 ++++++++++++------- .../DeviceManagementProviderServiceImpl.java | 6 ++- .../GroupManagementProviderServiceImpl.java | 12 ++--- 6 files changed, 64 insertions(+), 30 deletions(-) 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/EnrollmentDAO.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/EnrollmentDAO.java index df812fc62f..4a4be1e0c3 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/EnrollmentDAO.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/EnrollmentDAO.java @@ -126,5 +126,5 @@ public interface EnrollmentDAO { * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user * @throws DeviceManagementDAOException if an error occurs while fetching the data */ - List getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException; + List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses) throws DeviceManagementDAOException; } 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/GroupDAO.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/GroupDAO.java index 5071f7a400..3e3fde8205 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/GroupDAO.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/GroupDAO.java @@ -479,7 +479,7 @@ public interface GroupDAO { * @return {@link GroupDetailsDTO} which containing group details and a list of device IDs * @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices */ - GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int tenantId, int offset, int limit) + GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowingDeviceStatuses, int tenantId, int offset, int limit) throws GroupManagementDAOException; } \ 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/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 7e02bd7ac0..b8ad6f86df 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 @@ -654,18 +654,34 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } @Override - public List getDevicesByTenantId(int tenantId) + public List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses) throws DeviceManagementDAOException { List devices = new ArrayList<>(); + if (allowingDeviceStatuses.isEmpty()) { + return devices; + } + + StringBuilder deviceFilters = new StringBuilder(); + for (int i = 0; i < allowingDeviceStatuses.size(); i++) { + deviceFilters.append("?"); + if (i < allowingDeviceStatuses.size() - 1) { + deviceFilters.append(","); + } + } + String sql = "SELECT DEVICE_ID, OWNER, STATUS, DEVICE_TYPE, DEVICE_IDENTIFICATION " + "FROM DM_ENROLMENT " + - "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ? AND STATUS IN (" + deviceFilters.toString() + ")"; Connection conn = null; try { conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setInt(1, tenantId); + int index = 1; + stmt.setInt(index++, tenantId); + for (String status : allowingDeviceStatuses) { + stmt.setString(index++, status); + } try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { @@ -687,4 +703,5 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { return devices; } + } 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 780ba43cc6..1d9084eb7b 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 @@ -1441,7 +1441,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } @Override - public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int tenantId, int offset, int limit) + public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowedStatuses, int tenantId, int offset, int limit) throws GroupManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName); @@ -1454,6 +1454,14 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { Map deviceTypes = new HashMap<>(); Map deviceIdentifiers = new HashMap<>(); + StringBuilder deviceFilters = new StringBuilder(); + for (int i = 0; i < allowedStatuses.size(); i++) { + deviceFilters.append("?"); + if (i < allowedStatuses.size() - 1) { + deviceFilters.append(","); + } + } + String sql = "SELECT " + " g.ID AS GROUP_ID, " + @@ -1473,16 +1481,21 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { "WHERE " + " g.GROUP_NAME = ? " + " AND g.TENANT_ID = ? " + + " AND e.STATUS IN (" + deviceFilters.toString() + ") " + "LIMIT ? OFFSET ?"; Connection conn = null; try { conn = GroupManagementDAOFactory.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, groupName); - stmt.setInt(2, tenantId); - stmt.setInt(3, limit); - stmt.setInt(4, offset); + int index = 1; + stmt.setString(index++, groupName); + stmt.setInt(index++, tenantId); + for (String status : allowedStatuses) { + stmt.setString(index++, status); + } + stmt.setInt(index++, limit); + stmt.setInt(index++, offset); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { @@ -1500,19 +1513,19 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { deviceIdentifiers.put(deviceId, rs.getString("DEVICE_IDENTIFICATION")); } } - groupDetails.setDeviceIds(deviceIds); - groupDetails.setDeviceCount(deviceIds.size()); - groupDetails.setDeviceOwners(deviceOwners); - groupDetails.setDeviceStatuses(deviceStatuses); - groupDetails.setDeviceNames(deviceNames); - groupDetails.setDeviceTypes(deviceTypes); - groupDetails.setDeviceIdentifiers(deviceIdentifiers); - return groupDetails; + groupDetails.setDeviceIds(deviceIds); + groupDetails.setDeviceCount(deviceIds.size()); + groupDetails.setDeviceOwners(deviceOwners); + groupDetails.setDeviceStatuses(deviceStatuses); + groupDetails.setDeviceNames(deviceNames); + groupDetails.setDeviceTypes(deviceTypes); + groupDetails.setDeviceIdentifiers(deviceIdentifiers); + return groupDetails; + } + } catch (SQLException e) { + String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName; + log.error(msg, e); + throw new GroupManagementDAOException(msg, e); } - } catch (SQLException e) { - String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName; - log.error(msg, e); - throw new GroupManagementDAOException(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/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index d2d73dc92a..5d33953a56 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -5418,9 +5418,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException { List devices; + List allowingDeviceStatuses = new ArrayList<>(); + allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString()); + allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString()); + allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString()); try { DeviceManagementDAOFactory.openConnection(); - devices = enrollmentDAO.getDevicesByTenantId(tenantId); + devices = enrollmentDAO.getDevicesByTenantId(tenantId, allowingDeviceStatuses); if (devices == null || devices.isEmpty()) { String msg = "No devices found for tenant ID: " + tenantId; log.error(msg); 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/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java index c42feed9b8..bd10cac78a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.service; +import io.entgra.device.mgt.core.device.mgt.common.*; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; @@ -39,13 +40,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; -import io.entgra.device.mgt.core.device.mgt.common.Device; -import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; -import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException; -import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; -import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; import io.entgra.device.mgt.core.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor; import io.entgra.device.mgt.core.device.mgt.core.geo.task.GeoFenceEventOperationManager; @@ -1695,10 +1691,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupDetailsDTO groupDetailsWithDevices; + List allowingDeviceStatuses = new ArrayList<>(); + allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString()); + allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString()); + allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString()); try { GroupManagementDAOFactory.openConnection(); - groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, tenantId, offset, limit); + groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses, tenantId, offset, limit); } catch (GroupManagementDAOException | SQLException e) { String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName; log.error(msg, e); From 953f72afdccc06439f5e3e8ffe7abc794984afdf Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 11 Jul 2024 07:56:34 +0530 Subject: [PATCH 3/4] Filter devices according to their devicetype --- .../core/impl/SubscriptionManagerImpl.java | 23 ++++++++++++------- .../device/mgt/core/dao/EnrollmentDAO.java | 6 +++-- .../core/device/mgt/core/dao/GroupDAO.java | 4 +++- .../dao/impl/AbstractEnrollmentDAOImpl.java | 19 +++++++-------- .../core/dao/impl/AbstractGroupDAOImpl.java | 4 +++- .../DeviceManagementProviderService.java | 6 +++-- .../DeviceManagementProviderServiceImpl.java | 8 +++---- .../GroupManagementProviderService.java | 3 ++- .../GroupManagementProviderServiceImpl.java | 4 ++-- 9 files changed, 47 insertions(+), 30 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 498abe0b02..6bb902d6b3 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 @@ -1720,8 +1720,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } + ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - + int deviceTypeId = applicationDTO.getDeviceTypeId(); List groupDetailsWithDevices = new ArrayList<>(); List groupDetails = @@ -1737,7 +1738,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // Retrieve group details and device IDs for the group using the service layer GroupDetailsDTO groupDetailWithDevices = - groupManagementProviderService.getGroupDetailsWithDevices(groupName, offset, limit); + groupManagementProviderService.getGroupDetailsWithDevices(groupName, deviceTypeId, offset, limit); SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO(); groupDetailDTO.setId(groupDetailWithDevices.getGroupId()); @@ -1910,8 +1911,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } + ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - + int deviceTypeId = applicationDTO.getDeviceTypeId(); List userSubscriptionsWithDevices = new ArrayList<>(); List userSubscriptions = @@ -1927,7 +1929,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // Retrieve owner details and device IDs for the user using the service layer OwnerWithDeviceDTO ownerDetailsWithDevices = - deviceManagementProviderService.getOwnersWithDeviceIds(userName); + deviceManagementProviderService.getOwnersWithDeviceIds(userName, deviceTypeId); SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO(); userSubscriptionDTO.setName(userSubscription.getName()); @@ -2097,8 +2099,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } + ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - + int deviceTypeId = applicationDTO.getDeviceTypeId(); List roleSubscriptionsWithDevices = new ArrayList<>(); List roleSubscriptions = @@ -2139,7 +2142,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { for (String user : users) { OwnerWithDeviceDTO ownerDetailsWithDevices; try { - ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user); + ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user, deviceTypeId); } catch (DeviceManagementDAOException e) { throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e); } @@ -2307,7 +2310,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } + ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); + int deviceTypeId = applicationDTO.getDeviceTypeId(); DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); List deviceSubscriptions = @@ -2321,7 +2326,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } List allDevices = - deviceManagementProviderService.getDevicesByTenantId(tenantId); + deviceManagementProviderService.getDevicesByTenantId(tenantId, deviceTypeId); List deviceIds = allDevices.stream() .map(DeviceDetailsDTO::getDeviceId) @@ -2493,7 +2498,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new NotFoundException(msg); } + ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); + int deviceTypeId = applicationDTO.getDeviceTypeId(); List allSubscriptions = subscriptionDAO.getAllSubscriptionsDetails(appReleaseId, unsubscribe, tenantId, offset, limit); @@ -2522,7 +2529,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { statusCounts.put("NEW", 0); List allDevices = - deviceManagementProviderService.getDevicesByTenantId(tenantId); + deviceManagementProviderService.getDevicesByTenantId(tenantId, deviceTypeId); for (DeviceDetailsDTO device : allDevices) { Integer deviceId = device.getDeviceId(); 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/EnrollmentDAO.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/EnrollmentDAO.java index 4a4be1e0c3..158b86e0a3 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/EnrollmentDAO.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/EnrollmentDAO.java @@ -106,7 +106,7 @@ public interface EnrollmentDAO { * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user * @throws DeviceManagementDAOException if an error occurs while fetching the data */ - OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId) throws DeviceManagementDAOException; + OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId, int deviceTypeId) throws DeviceManagementDAOException; /** * Retrieves a list of device IDs with owners and device status. @@ -123,8 +123,10 @@ public interface EnrollmentDAO { * Retrieves owners and the list of device IDs with device status. * * @param tenantId the ID of the tenant + * @param allowingDeviceStatuses the allowed device statuses of devices + * @param deviceTypeId the device type id * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user * @throws DeviceManagementDAOException if an error occurs while fetching the data */ - List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses) throws DeviceManagementDAOException; + List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses, int deviceTypeId) throws DeviceManagementDAOException; } 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/GroupDAO.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/GroupDAO.java index 3e3fde8205..2bb6c48fb4 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/GroupDAO.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/GroupDAO.java @@ -473,13 +473,15 @@ public interface GroupDAO { * Get group details and list of device IDs related to the group. * * @param groupName Group name + * @param allowingDeviceStatuses the statuses of devices + * @param deviceTypeId the device type id * @param tenantId Tenant ID * @param offset the offset for the data set * @param limit the limit for the data set * @return {@link GroupDetailsDTO} which containing group details and a list of device IDs * @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices */ - GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowingDeviceStatuses, int tenantId, int offset, int limit) + GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowingDeviceStatuses, int deviceTypeId, int tenantId, int offset, int limit) throws GroupManagementDAOException; } \ 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/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 b8ad6f86df..6f9d3e727f 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 @@ -564,7 +564,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } @Override - public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId) + public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId, int deviceTypeId) throws DeviceManagementDAOException { Connection conn = null; OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO(); @@ -582,15 +582,16 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { 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 = ? AND e.STATUS IN (" + deviceFilters.toString() + ")"; + "WHERE e.OWNER = ? AND e.TENANT_ID = ? AND d.DEVICE_TYPE_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")"; try { conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, owner); stmt.setInt(2, tenantId); + stmt.setInt(3, deviceTypeId); for (int i = 0; i < allowingDeviceStatuses.size(); i++) { - stmt.setString(3 + i, allowingDeviceStatuses.get(i)); + stmt.setString(4 + i, allowingDeviceStatuses.get(i)); } try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { @@ -654,7 +655,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } @Override - public List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses) + public List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses, int deviceTypeId) throws DeviceManagementDAOException { List devices = new ArrayList<>(); if (allowingDeviceStatuses.isEmpty()) { @@ -669,9 +670,10 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } } - String sql = "SELECT DEVICE_ID, OWNER, STATUS, DEVICE_TYPE, DEVICE_IDENTIFICATION " + - "FROM DM_ENROLMENT " + - "WHERE TENANT_ID = ? AND STATUS IN (" + deviceFilters.toString() + ")"; + String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION " + + "FROM DM_ENROLMENT e " + + "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + + "WHERE e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ") AND d.DEVICE_TYPE_ID = ?"; Connection conn = null; try { @@ -682,6 +684,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { for (String status : allowingDeviceStatuses) { stmt.setString(index++, status); } + stmt.setInt(index++, deviceTypeId); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { @@ -702,6 +705,4 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { } return devices; } - - } 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 1d9084eb7b..22e9fb18aa 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 @@ -1441,7 +1441,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } @Override - public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowedStatuses, int tenantId, int offset, int limit) + public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowedStatuses, int deviceTypeId, int tenantId, int offset, int limit) throws GroupManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName); @@ -1481,6 +1481,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { "WHERE " + " g.GROUP_NAME = ? " + " AND g.TENANT_ID = ? " + + " AND d.DEVICE_TYPE_ID = ? " + " AND e.STATUS IN (" + deviceFilters.toString() + ") " + "LIMIT ? OFFSET ?"; @@ -1491,6 +1492,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { int index = 1; stmt.setString(index++, groupName); stmt.setInt(index++, tenantId); + stmt.setInt(index++, deviceTypeId); for (String status : allowedStatuses) { stmt.setString(index++, status); } 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/service/DeviceManagementProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java index 9ab44929a1..8a892474ff 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java @@ -1082,10 +1082,11 @@ public interface DeviceManagementProviderService { * Get owner details and device IDs for a given owner and tenant. * * @param owner the name of the owner. + * @param deviceTypeId the device type id * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user. * @throws DeviceManagementException if an error occurs while fetching owner details. */ - OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException; + OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId) throws DeviceManagementDAOException; /** * Get owner details and device IDs for a given owner and tenant. @@ -1099,10 +1100,11 @@ public interface DeviceManagementProviderService { /** * Get owner details and device IDs for a given owner and tenant. * @param tenantId the tenant id which devices need to be retried + * @param deviceTypeId the device type id * @return {@link DeviceDetailsDTO} which contains devices details. * @throws DeviceManagementException if an error occurs while fetching owner details. */ - List getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException; + List getDevicesByTenantId(int tenantId, int deviceTypeId) throws DeviceManagementDAOException; /** * Get operation details by operation code. 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/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 5d33953a56..0f035a5bf9 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -5354,7 +5354,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException { + public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId) throws DeviceManagementDAOException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); OwnerWithDeviceDTO ownerWithDeviceDTO; @@ -5365,7 +5365,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv try { DeviceManagementDAOFactory.openConnection(); - ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, allowingDeviceStatuses, tenantId); + ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, allowingDeviceStatuses, tenantId, deviceTypeId); if (ownerWithDeviceDTO == null) { String msg = "No data found for owner: " + owner; log.error(msg); @@ -5416,7 +5416,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public List getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException { + public List getDevicesByTenantId(int tenantId, int deviceTypeId) throws DeviceManagementDAOException { List devices; List allowingDeviceStatuses = new ArrayList<>(); allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString()); @@ -5424,7 +5424,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString()); try { DeviceManagementDAOFactory.openConnection(); - devices = enrollmentDAO.getDevicesByTenantId(tenantId, allowingDeviceStatuses); + devices = enrollmentDAO.getDevicesByTenantId(tenantId, allowingDeviceStatuses, deviceTypeId); if (devices == null || devices.isEmpty()) { String msg = "No devices found for tenant ID: " + tenantId; log.error(msg); 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/service/GroupManagementProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java index fac06bfccf..b1200772a4 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java @@ -377,11 +377,12 @@ public interface GroupManagementProviderService { * Get group details and device IDs for a given group name. * * @param groupName the name of the group. + * @param deviceTypeId the device type id * @param offset the offset for the data set * @param limit the limit for the data set * @return {@link GroupDetailsDTO} which containing group details and a list of device IDs * @throws GroupManagementException if an error occurs while fetching group details. */ - GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit) throws GroupManagementException; + GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, int offset, int limit) throws GroupManagementException; } 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/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java index bd10cac78a..0d0e23cc48 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -1684,7 +1684,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } @Override - public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit) + public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, int offset, int limit) throws GroupManagementException { if (log.isDebugEnabled()) { log.debug("Retrieving group details and device IDs for group: " + groupName); @@ -1698,7 +1698,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid try { GroupManagementDAOFactory.openConnection(); - groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses, tenantId, offset, limit); + groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses, deviceTypeId, tenantId, offset, limit); } catch (GroupManagementDAOException | SQLException e) { String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName; log.error(msg, e); From 1a1df9725333bcf8abbe9bfc4c87d6311284f14a Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 11 Jul 2024 12:32:39 +0530 Subject: [PATCH 4/4] Resolve comments --- .../mgt/core/impl/SubscriptionManagerImpl.java | 16 ++++++---------- .../core/device/mgt/core/dao/EnrollmentDAO.java | 6 ++++-- .../mgt/core/device/mgt/core/dao/GroupDAO.java | 3 ++- .../mgt/core/dao/impl/AbstractGroupDAOImpl.java | 3 ++- .../GroupManagementProviderServiceImpl.java | 3 ++- 5 files changed, 16 insertions(+), 15 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 6bb902d6b3..203740c6da 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 @@ -1722,7 +1722,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - int deviceTypeId = applicationDTO.getDeviceTypeId(); List groupDetailsWithDevices = new ArrayList<>(); List groupDetails = @@ -1738,7 +1737,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // Retrieve group details and device IDs for the group using the service layer GroupDetailsDTO groupDetailWithDevices = - groupManagementProviderService.getGroupDetailsWithDevices(groupName, deviceTypeId, offset, limit); + groupManagementProviderService.getGroupDetailsWithDevices(groupName, applicationDTO.getDeviceTypeId(), + offset, limit); SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO(); groupDetailDTO.setId(groupDetailWithDevices.getGroupId()); @@ -1913,7 +1913,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - int deviceTypeId = applicationDTO.getDeviceTypeId(); List userSubscriptionsWithDevices = new ArrayList<>(); List userSubscriptions = @@ -1929,7 +1928,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // Retrieve owner details and device IDs for the user using the service layer OwnerWithDeviceDTO ownerDetailsWithDevices = - deviceManagementProviderService.getOwnersWithDeviceIds(userName, deviceTypeId); + deviceManagementProviderService.getOwnersWithDeviceIds(userName, applicationDTO.getDeviceTypeId()); SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO(); userSubscriptionDTO.setName(userSubscription.getName()); @@ -2101,7 +2100,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - int deviceTypeId = applicationDTO.getDeviceTypeId(); List roleSubscriptionsWithDevices = new ArrayList<>(); List roleSubscriptions = @@ -2142,7 +2140,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { for (String user : users) { OwnerWithDeviceDTO ownerDetailsWithDevices; try { - ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user, deviceTypeId); + ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user, applicationDTO.getDeviceTypeId()); } catch (DeviceManagementDAOException e) { throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e); } @@ -2312,7 +2310,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - int deviceTypeId = applicationDTO.getDeviceTypeId(); DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); List deviceSubscriptions = @@ -2326,7 +2323,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } List allDevices = - deviceManagementProviderService.getDevicesByTenantId(tenantId, deviceTypeId); + deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId()); List deviceIds = allDevices.stream() .map(DeviceDetailsDTO::getDeviceId) @@ -2500,7 +2497,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId); int appReleaseId = applicationReleaseDTO.getId(); - int deviceTypeId = applicationDTO.getDeviceTypeId(); List allSubscriptions = subscriptionDAO.getAllSubscriptionsDetails(appReleaseId, unsubscribe, tenantId, offset, limit); @@ -2529,7 +2525,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { statusCounts.put("NEW", 0); List allDevices = - deviceManagementProviderService.getDevicesByTenantId(tenantId, deviceTypeId); + deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId()); for (DeviceDetailsDTO device : allDevices) { Integer deviceId = device.getDeviceId(); 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/EnrollmentDAO.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/EnrollmentDAO.java index 158b86e0a3..e7419aa013 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/EnrollmentDAO.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/EnrollmentDAO.java @@ -106,7 +106,8 @@ public interface EnrollmentDAO { * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user * @throws DeviceManagementDAOException if an error occurs while fetching the data */ - OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId, int deviceTypeId) throws DeviceManagementDAOException; + OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId, int deviceTypeId) + throws DeviceManagementDAOException; /** * Retrieves a list of device IDs with owners and device status. @@ -128,5 +129,6 @@ public interface EnrollmentDAO { * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user * @throws DeviceManagementDAOException if an error occurs while fetching the data */ - List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses, int deviceTypeId) throws DeviceManagementDAOException; + List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses, int deviceTypeId) + throws DeviceManagementDAOException; } 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/GroupDAO.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/GroupDAO.java index 2bb6c48fb4..abb12a6ea0 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/GroupDAO.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/GroupDAO.java @@ -481,7 +481,8 @@ public interface GroupDAO { * @return {@link GroupDetailsDTO} which containing group details and a list of device IDs * @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices */ - GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowingDeviceStatuses, int deviceTypeId, int tenantId, int offset, int limit) + GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowingDeviceStatuses, int deviceTypeId, + int tenantId, int offset, int limit) throws GroupManagementDAOException; } \ 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/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 22e9fb18aa..7b9e918000 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 @@ -1441,7 +1441,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } @Override - public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowedStatuses, int deviceTypeId, int tenantId, int offset, int limit) + public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowedStatuses, int deviceTypeId, + int tenantId, int offset, int limit) throws GroupManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName); 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/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 0d0e23cc48..d6114b5c04 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -1698,7 +1698,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid try { GroupManagementDAOFactory.openConnection(); - groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses, deviceTypeId, tenantId, offset, limit); + groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses, + deviceTypeId, tenantId, offset, limit); } catch (GroupManagementDAOException | SQLException e) { String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName; log.error(msg, e);