From 16ee68d8a38efe6ef471e561bddb6069db29901b Mon Sep 17 00:00:00 2001 From: ruwin Date: Thu, 19 Sep 2024 22:51:12 +0530 Subject: [PATCH] Completed the requested changes --- .../device/mgt/core/device/mgt/core/dao/GroupDAO.java | 9 +++++++++ .../mgt/core/service/GroupManagementProviderService.java | 9 ++++++++- .../core/service/GroupManagementProviderServiceImpl.java | 8 ++++++-- 3 files changed, 23 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/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 513995fab1..c883e2790e 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 @@ -490,5 +490,14 @@ public interface GroupDAO { int getDeviceCount(String groupName, int tenantId) throws GroupManagementDAOException; + /** + * Retrieves the count of devices for a specific group, device type, and tenant. + * + * @param groupName the name of the group + * @param deviceTypeId the ID of the device type (e.g., Android, iOS, Windows) + * @param tenantId the ID of the tenant + * @return the count of devices for the given group, device type, and tenant + * @throws GroupManagementDAOException if an error occurs during the retrieval of the device count + */ int getDeviceCountWithGroup(String groupName, int deviceTypeId, int tenantId) 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/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 90049beef9..9750b7471e 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 @@ -392,6 +392,13 @@ public interface GroupManagementProviderService { int getDeviceCount(String groupName) throws GroupManagementException; - + /** + * Retrieves the count of devices for a specific group and device type. + * + * @param groupName the name of the group + * @param deviceTypeId the ID of the device type (e.g., Android, iOS, Windows) + * @return the count of devices for the given group and device type + * @throws GroupManagementException if an error occurs during the retrieval of the device count + */ int getDeviceCountWithGroup(String groupName, int deviceTypeId) 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 825d89184d..575f2b3fa1 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 @@ -1753,8 +1753,12 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid try { GroupManagementDAOFactory.openConnection(); return groupDAO.getDeviceCountWithGroup(groupName,deviceTypeId, tenantId); - } catch (SQLException | GroupManagementDAOException e) { - String msg = "Error occurred while retrieving device count."; + } catch (SQLException e) { + String msg = "SQL error occurred while retrieving device count."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (GroupManagementDAOException e) { + String msg = "DAO error occurred while retrieving device count."; log.error(msg, e); throw new GroupManagementException(msg, e); } finally {