From afbdd89f4d07ef26477e6f0334fae28dd4f489b4 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 8 May 2024 11:47:24 +0530 Subject: [PATCH] Fix for subscription table pagination is not loading correctly --- .../core/device/mgt/core/dao/DeviceDAO.java | 3 +++ .../core/dao/impl/AbstractDeviceDAOImpl.java | 21 +++++++++++++++++++ .../dao/impl/device/GenericDeviceDAOImpl.java | 2 +- .../DeviceManagementProviderServiceImpl.java | 5 +++-- 4 files changed, 28 insertions(+), 3 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/DeviceDAO.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/DeviceDAO.java index 2e7e69e358..c0133dd8ed 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/DeviceDAO.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/DeviceDAO.java @@ -840,4 +840,7 @@ public interface DeviceDAO { List getAgentVersions(int tenantId) throws DeviceManagementDAOException; List getDevicesEnrolledSince(Date since) throws DeviceManagementDAOException; List getDevicesEnrolledPriorTo(Date priorTo) throws DeviceManagementDAOException; + + int getSubscribedDeviceCountOfFilteredList() 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/impl/AbstractDeviceDAOImpl.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/AbstractDeviceDAOImpl.java index 8c17c204a8..5d0b0a509b 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/AbstractDeviceDAOImpl.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/AbstractDeviceDAOImpl.java @@ -3343,4 +3343,25 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } return devices; } + + + @Override + public int getSubscribedDeviceCountOfFilteredList() throws DeviceManagementDAOException { + try { + Connection conn = getConnection(); + String sql = "SELECT FOUND_ROWS();"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + return rs.getInt(1); + } + return 0; + } + } + } catch (SQLException e) { + String msg = "Error occurred while retrieving the count of devices that matches the filtering criteria"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } + } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.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/device/GenericDeviceDAOImpl.java index df408422b6..a7dc975980 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/device/GenericDeviceDAOImpl.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/device/GenericDeviceDAOImpl.java @@ -1268,7 +1268,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isOwnershipProvided = false; boolean isSerialProvided = false; - query = "SELECT " + query = "SELECT SQL_CALC_FOUND_ROWS " + "DM_DEVICE.ID AS DEVICE_ID, " + "DM_DEVICE.NAME AS DEVICE_NAME, " + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " 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 7aad6f8f2e..abea5ee1f6 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 @@ -4661,8 +4661,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv paginationResult.setRecordsTotal(0); return paginationResult; } - int count = deviceDAO.getSubscribedDeviceCount(devicesIds, tenantId, request.getStatusList()); - paginationResult.setRecordsFiltered(count); + //int count = deviceDAO.getSubscribedDeviceCount(devicesIds, tenantId, request.getStatusList()); + int count = deviceDAO.getSubscribedDeviceCountOfFilteredList(); + paginationResult.setRecordsFiltered(subscribedDeviceDetails.size()); paginationResult.setRecordsTotal(count); } catch (DeviceManagementDAOException e) { String msg = "Error occurred while retrieving device list for device ids " + devicesIds;