get leaf organization fix

pull/238/head
Isuri Mendis 1 year ago
parent abdb1efd63
commit 826912c8a6

@ -286,8 +286,8 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
List<DeviceOrganization> deviceOrganizations = new ArrayList<>(); List<DeviceOrganization> deviceOrganizations = new ArrayList<>();
try { try {
Connection conn = ConnectionManagerUtil.getDBConnection(); Connection conn = ConnectionManagerUtil.getDBConnection();
String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE ID NOT IN (SELECT DISTINCT PARENT_DEVICE_ID " + String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE ID NOT IN " +
"FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL) " + "(SELECT DISTINCT PARENT_DEVICE_ID FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL OR ID IS NOT NULL) " +
"LIMIT ? OFFSET ?"; "LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, request.getLimit()); stmt.setInt(1, request.getLimit());

@ -261,6 +261,22 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty"); 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<DeviceOrganization> 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") @Test(dependsOnMethods = "testAddDeviceOrganization")
public void testGetLeafOrganizations() throws DeviceOrganizationMgtPluginException { public void testGetLeafOrganizations() throws DeviceOrganizationMgtPluginException {
int offset = 0; int offset = 0;
@ -275,7 +291,6 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
log.info("----------------------------------------------"); log.info("----------------------------------------------");
} }
Assert.assertNotNull(organizations, "List of organizations cannot be null"); Assert.assertNotNull(organizations, "List of organizations cannot be null");
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
} }
@Test(dependsOnMethods = "testAddMultipleDeviceOrganizations") @Test(dependsOnMethods = "testAddMultipleDeviceOrganizations")

Loading…
Cancel
Save