From 014889b2376192d2a6f3500d0d07d9812a480f23 Mon Sep 17 00:00:00 2001 From: ruwin Date: Mon, 4 Nov 2024 14:24:35 +0530 Subject: [PATCH] Fix to display statistics in webapps Fixed to display the subscription statistics in web apps also by appending the sql query only to have DEVICE_TYPE_ID if it is not equals to 0. --- .../mgt/core/dao/impl/AbstractGroupDAOImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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/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 94b675d723..fc6f6b23c8 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 @@ -1590,20 +1590,23 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { int deviceCount = 0; try { Connection connection = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT COUNT(e.ID) AS COUNT " + + StringBuilder sql = new StringBuilder("SELECT COUNT(e.ID) AS COUNT " + "FROM DM_GROUP d " + "INNER JOIN DM_DEVICE_GROUP_MAP m ON d.ID = m.GROUP_ID " + "INNER JOIN DM_ENROLMENT e ON m.DEVICE_ID = e.DEVICE_ID " + "INNER JOIN DM_DEVICE r ON e.DEVICE_ID = r.ID " + "WHERE d.TENANT_ID = ? " + "AND d.GROUP_NAME = ? " + - "AND r.DEVICE_TYPE_ID = ? " + - "AND e.STATUS NOT IN ('REMOVED', 'DELETED')"; - - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + "AND e.STATUS NOT IN ('REMOVED', 'DELETED')"); + if (deviceTypeId != 0) { + sql.append(" AND r.DEVICE_TYPE_ID = ?"); + } + try (PreparedStatement preparedStatement = connection.prepareStatement(sql.toString())) { preparedStatement.setInt(1, tenantId); preparedStatement.setString(2, groupName); - preparedStatement.setInt(3, deviceTypeId); + if (deviceTypeId != 0) { + preparedStatement.setInt(3, deviceTypeId); + } try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { deviceCount = resultSet.getInt("COUNT"); @@ -1617,4 +1620,4 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { throw new GroupManagementDAOException(msg, e); } } -} +} \ No newline at end of file