From 826912c8a67e1f904eeb76d64fd4a646c66fb50a Mon Sep 17 00:00:00 2001 From: isuri Date: Thu, 23 Nov 2023 18:58:46 +0530 Subject: [PATCH] get leaf organization fix --- .../dao/impl/DeviceOrganizationDAOImpl.java | 4 ++-- .../device/organization/ServiceTest.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java index 3bad489e79..606fd50976 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java @@ -286,8 +286,8 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO { List deviceOrganizations = new ArrayList<>(); try { Connection conn = ConnectionManagerUtil.getDBConnection(); - String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE ID NOT IN (SELECT DISTINCT PARENT_DEVICE_ID " + - "FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL) " + + String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE ID NOT IN " + + "(SELECT DISTINCT PARENT_DEVICE_ID FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL OR ID IS NOT NULL) " + "LIMIT ? OFFSET ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, request.getLimit()); diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java index 566e0e9147..c7d4c77480 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java @@ -261,6 +261,22 @@ public class ServiceTest extends BaseDeviceOrganizationTest { Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty"); } + @Test(dependsOnMethods = "testAddDeviceOrganizationWithNullParent") + public void testGetLeafOrganizationsWithNullParents() throws DeviceOrganizationMgtPluginException { + int offset = 0; + int limit = 10; + PaginationRequest request = new PaginationRequest(offset, limit); + List organizations = deviceOrganizationService.getDeviceOrganizationLeafs(request); + for (DeviceOrganization organization : organizations) { + log.info("organizationID = " + organization.getOrganizationId()); + log.info("deviceID = " + organization.getDeviceId()); + log.info("parentDeviceID = " + organization.getParentDeviceId()); + log.info("updateTime = " + organization.getUpdateTime()); + log.info("----------------------------------------------"); + } + Assert.assertTrue(organizations.isEmpty(), "List of organizations should not be empty"); + } + @Test(dependsOnMethods = "testAddDeviceOrganization") public void testGetLeafOrganizations() throws DeviceOrganizationMgtPluginException { int offset = 0; @@ -275,7 +291,6 @@ public class ServiceTest extends BaseDeviceOrganizationTest { log.info("----------------------------------------------"); } Assert.assertNotNull(organizations, "List of organizations cannot be null"); - Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty"); } @Test(dependsOnMethods = "testAddMultipleDeviceOrganizations")