deviceOrg: get leaf dao fix

backup
Isuri Mendis 12 months ago
parent dd92e5dc4c
commit bdc9fead5f

@ -320,7 +320,8 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
* {@inheritDoc}
*/
@Override
public List<DeviceOrganization> getDeviceOrganizationRoots(PaginationRequest request) throws DeviceOrganizationMgtDAOException {
public List<DeviceOrganization> getDeviceOrganizationRoots(PaginationRequest request)
throws DeviceOrganizationMgtDAOException {
List<DeviceOrganization> deviceOrganizations = new ArrayList<>();
try {
Connection conn = ConnectionManagerUtil.getDBConnection();
@ -365,9 +366,8 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
List<DeviceOrganization> deviceOrganizations = new ArrayList<>();
try {
Connection conn = ConnectionManagerUtil.getDBConnection();
String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE ORGANIZATION_ID NOT IN " +
"(SELECT DISTINCT PARENT_DEVICE_ID FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL " +
"OR ORGANIZATION_ID IS NOT NULL) " +
String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID NOT IN " +
"(SELECT DISTINCT PARENT_DEVICE_ID FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL ) " +
"LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, request.getLimit());

@ -162,7 +162,8 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
* {@inheritDoc}
*/
@Override
public List<DeviceOrganization> getDeviceOrganizationLeafs(PaginationRequest request) throws DeviceOrganizationMgtPluginException {
public List<DeviceOrganization> getDeviceOrganizationLeafs(PaginationRequest request)
throws DeviceOrganizationMgtPluginException {
try {
// Open a database connection
ConnectionManagerUtil.openDBConnection();

@ -148,7 +148,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
// Define specific combinations of deviceID and parentDeviceID
int[][] combinations = {
{20, 19}, {19, 18}, {18, 17}, {20, 5}, {20, 17}, {19, 16}, {17, 16}, {16, 17}, {2, 1}
{20, 19}, {19, 18}, {18, 17}, {20, 5}, {20, 17}, {19, 16}, {17, 16}, {16, 17}, {2, 1},{3, 2}
// Add more combinations as needed
};
@ -300,8 +300,8 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
}
@Test(dependsOnMethods = "testAddDeviceOrganizationWithNullParent")
public void testGetLeafOrganizationsWithNullParents() throws DeviceOrganizationMgtPluginException {
@Test(dependsOnMethods = "testAddMultipleDeviceOrganizations")
public void testGetLeafOrganizationsWithMultipleDeviceOrganizations() throws DeviceOrganizationMgtPluginException {
int offset = 0;
int limit = 10;
PaginationRequest request = new PaginationRequest(offset, limit);
@ -313,7 +313,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
log.info("updateTime = " + organization.getUpdateTime());
log.info("----------------------------------------------");
}
Assert.assertTrue(organizations.isEmpty(), "List of organizations should not be empty");
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
}
@Test(dependsOnMethods = "testAddDeviceOrganization")

Loading…
Cancel
Save