deviceOrg: get children of root best practices apply

uddhika-device-mgt
Isuri Mendis 9 months ago
parent d2593114b7
commit 0de808229f

@ -433,7 +433,7 @@ public interface DeviceOrganizationMgtService {
* @return A response containing a list of root device organizations.
*/
@GET
@Path("roots-children")
@Path("roots/children")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",

@ -158,7 +158,7 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
}
@GET
@Path("roots-children")
@Path("roots/children")
@Override
public Response getDeviceOrganizationChildrenForRoots(
@DefaultValue("0") @QueryParam("offset") int offset,

@ -177,22 +177,15 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
PaginationRequest paginationRequest = new PaginationRequest(request.getOffSet(), request.getLimit());
List<DeviceOrganization> roots = getDeviceOrganizationRoots(paginationRequest);
if (roots == null || roots.isEmpty()) {
log.warn("No root device organizations found.");
return allDeviceOrganizations; // Return an empty list
}
// Iterate over each root and fetch its children
for (DeviceOrganization root : roots) {
DeviceNodeResult childrenResult = getChildrenOfDeviceNode(root.getDeviceId(), request.getMaxDepth(), request.isIncludeDevice());
if (childrenResult != null) {
allDeviceOrganizations.add(childrenResult);
} else {
log.warn("no children found for roots.");
}
}
return allDeviceOrganizations;
} catch (NullPointerException | DeviceOrganizationMgtPluginException e) {
} catch (DeviceOrganizationMgtPluginException e) {
String msg = "Error occurred while retrieving all device organizations for roots.";
log.error(msg, e);
throw new DeviceOrganizationMgtPluginException(msg, e);

Loading…
Cancel
Save