deviceOrg: get children of root best practices apply

appm_improvement
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. * @return A response containing a list of root device organizations.
*/ */
@GET @GET
@Path("roots-children") @Path("roots/children")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",

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

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

Loading…
Cancel
Save