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} * {@inheritDoc}
*/ */
@Override @Override
public List<DeviceOrganization> getDeviceOrganizationRoots(PaginationRequest request) throws DeviceOrganizationMgtDAOException { public List<DeviceOrganization> getDeviceOrganizationRoots(PaginationRequest request)
throws DeviceOrganizationMgtDAOException {
List<DeviceOrganization> deviceOrganizations = new ArrayList<>(); List<DeviceOrganization> deviceOrganizations = new ArrayList<>();
try { try {
Connection conn = ConnectionManagerUtil.getDBConnection(); Connection conn = ConnectionManagerUtil.getDBConnection();
@ -365,9 +366,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 ORGANIZATION_ID NOT IN " + 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 " + "(SELECT DISTINCT PARENT_DEVICE_ID FROM DM_DEVICE_ORGANIZATION WHERE PARENT_DEVICE_ID IS NOT NULL ) " +
"OR ORGANIZATION_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());

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

@ -148,7 +148,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
// Define specific combinations of deviceID and parentDeviceID // Define specific combinations of deviceID and parentDeviceID
int[][] combinations = { 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 // 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"); Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
} }
@Test(dependsOnMethods = "testAddDeviceOrganizationWithNullParent") @Test(dependsOnMethods = "testAddMultipleDeviceOrganizations")
public void testGetLeafOrganizationsWithNullParents() throws DeviceOrganizationMgtPluginException { public void testGetLeafOrganizationsWithMultipleDeviceOrganizations() throws DeviceOrganizationMgtPluginException {
int offset = 0; int offset = 0;
int limit = 10; int limit = 10;
PaginationRequest request = new PaginationRequest(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit);
@ -313,7 +313,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
log.info("updateTime = " + organization.getUpdateTime()); log.info("updateTime = " + organization.getUpdateTime());
log.info("----------------------------------------------"); 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") @Test(dependsOnMethods = "testAddDeviceOrganization")

Loading…
Cancel
Save