mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
deviceOrg: get children of root nodes api implementation
This commit is contained in:
parent
45d6a27caa
commit
89bd784a57
@ -346,14 +346,14 @@ public interface DeviceOrganizationMgtService {
|
||||
Response getDeviceOrganizationLeafs(
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "The starting pagination index for the complete list of qualified items",
|
||||
value = "leaf node offset",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@DefaultValue("0") @QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many policy details you require from the starting pagination index/offset.",
|
||||
value = "leaf node limit",
|
||||
required = false,
|
||||
defaultValue = "5")
|
||||
@DefaultValue("20") @QueryParam("limit")
|
||||
@ -369,8 +369,8 @@ public interface DeviceOrganizationMgtService {
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Retrieve leaf Device Organizations",
|
||||
notes = "Get a list of leaf device organizations.",
|
||||
value = "Retrieve root Device Organizations",
|
||||
notes = "Get a list of root device organizations.",
|
||||
tags = "Device Organization Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ -414,19 +414,97 @@ public interface DeviceOrganizationMgtService {
|
||||
Response getDeviceOrganizationRoots(
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "The starting pagination index for the complete list of qualified items",
|
||||
value = "root node offset",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@DefaultValue("0") @QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many policy details you require from the starting pagination index/offset.",
|
||||
value = "root node limit",
|
||||
required = false,
|
||||
defaultValue = "5")
|
||||
defaultValue = "20")
|
||||
@DefaultValue("20") @QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
/**
|
||||
* Retrieves a list of root device organizations.
|
||||
*
|
||||
* @return A response containing a list of root device organizations.
|
||||
*/
|
||||
@GET
|
||||
@Path("roots-children")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Retrieve children for root Device Organizations",
|
||||
notes = "Get a list of children for root device organizations.",
|
||||
tags = "Device Organization Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "dm:device-org:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched the all devices.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description =
|
||||
"Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}
|
||||
),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message =
|
||||
"Bad Request. \n"),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the " +
|
||||
"list of supported device types.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getDeviceOrganizationChildrenForRoots(
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "root offset",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@DefaultValue("0") @QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "root limit.",
|
||||
required = false,
|
||||
defaultValue = "20")
|
||||
@DefaultValue("20") @QueryParam("limit")
|
||||
int limit,
|
||||
@ApiParam(
|
||||
name= "maxDepth",
|
||||
value = "The maximum depth of child nodes to retrieve for each root.",
|
||||
required = true) @QueryParam("maxDepth")
|
||||
int maxDepth,
|
||||
@ApiParam(
|
||||
name= "includeDevice",
|
||||
value = "Indicates whether to include device information in the retrieved child nodes.",
|
||||
required = true) @QueryParam("includeDevice")
|
||||
boolean includeDevice);
|
||||
|
||||
/**
|
||||
* Retrieves a specific device organization by its organization ID.
|
||||
*
|
||||
|
||||
@ -24,6 +24,7 @@ import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.u
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceNodeResult;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.RootChildrenRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtPluginException;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.spi.DeviceOrganizationService;
|
||||
import org.apache.commons.logging.Log;
|
||||
@ -154,6 +155,29 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("roots-children")
|
||||
@Override
|
||||
public Response getDeviceOrganizationChildrenForRoots(
|
||||
@DefaultValue("0") @QueryParam("offset") int offset,
|
||||
@DefaultValue("20") @QueryParam("limit") int limit,
|
||||
@QueryParam("maxDepth") int maxDepth,
|
||||
@QueryParam("includeDevice") boolean includeDevice) {
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
try {
|
||||
DeviceOrganizationService deviceOrganizationService = DeviceOrgAPIUtils.getDeviceOrganizationService();
|
||||
RootChildrenRequest request = new RootChildrenRequest(offset, limit);
|
||||
request.setMaxDepth(maxDepth);
|
||||
request.setIncludeDevice(includeDevice);
|
||||
List<DeviceNodeResult> nodeResultList = deviceOrganizationService.getAllDeviceOrganizationsForRoots(request);
|
||||
return Response.status(Response.Status.OK).entity(nodeResultList).build();
|
||||
} catch (DeviceOrganizationMgtPluginException e) {
|
||||
String errorMessage = "get children for root organizations failed";
|
||||
log.error(errorMessage);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@Path("{organizationId}")
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto;
|
||||
|
||||
public class RootChildrenRequest extends PaginationRequest{
|
||||
|
||||
int maxDepth;
|
||||
boolean includeDevice;
|
||||
|
||||
public RootChildrenRequest(int start, int limit) {
|
||||
super(start, limit);
|
||||
}
|
||||
|
||||
public int getMaxDepth() {
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
public void setMaxDepth(int maxDepth) {
|
||||
this.maxDepth = maxDepth;
|
||||
}
|
||||
|
||||
public boolean isIncludeDevice() {
|
||||
return includeDevice;
|
||||
}
|
||||
|
||||
public void setIncludeDevice(boolean includeDevice) {
|
||||
this.includeDevice = includeDevice;
|
||||
}
|
||||
}
|
||||
@ -20,10 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.impl
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.DeviceOrganizationDAO;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.DeviceOrganizationDAOFactory;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.util.ConnectionManagerUtil;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.AdditionResult;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceNodeResult;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.*;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.BadRequestException;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DBConnectionException;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtDAOException;
|
||||
@ -34,6 +31,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceOrganizationServiceImpl implements DeviceOrganizationService {
|
||||
@ -164,6 +162,32 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceNodeResult> getAllDeviceOrganizationsForRoots(RootChildrenRequest request) throws DeviceOrganizationMgtPluginException {
|
||||
List<DeviceNodeResult> allDeviceOrganizations = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// Get all root device organizations
|
||||
PaginationRequest paginationRequest = new PaginationRequest(request.getOffSet(), request.getLimit());
|
||||
List<DeviceOrganization> roots = getDeviceOrganizationRoots(paginationRequest);
|
||||
|
||||
// Iterate over each root and fetch its children
|
||||
for (DeviceOrganization root : roots) {
|
||||
DeviceNodeResult childrenResult = getChildrenOfDeviceNode(root.getDeviceId(), request.getMaxDepth(), request.isIncludeDevice());
|
||||
allDeviceOrganizations.add(childrenResult);
|
||||
}
|
||||
return allDeviceOrganizations;
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred while retrieving all device organizations for roots.";
|
||||
log.error(msg);
|
||||
throw new DeviceOrganizationMgtPluginException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.spi;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceNodeResult;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.RootChildrenRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtPluginException;
|
||||
|
||||
import java.util.List;
|
||||
@ -71,6 +72,15 @@ public interface DeviceOrganizationService {
|
||||
*/
|
||||
List<DeviceOrganization> getAllDeviceOrganizations() throws DeviceOrganizationMgtPluginException;
|
||||
|
||||
/**
|
||||
* Retrieves a list of all device organizations for roots.
|
||||
* @param request
|
||||
* @return
|
||||
* @throws DeviceOrganizationMgtPluginException
|
||||
*/
|
||||
List<DeviceNodeResult> getAllDeviceOrganizationsForRoots(RootChildrenRequest request)
|
||||
throws DeviceOrganizationMgtPluginException;
|
||||
|
||||
/**
|
||||
* Retrieves device Organization Leafs
|
||||
*
|
||||
|
||||
@ -22,6 +22,7 @@ import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.D
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceNodeResult;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.RootChildrenRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtPluginException;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.impl.DeviceOrganizationServiceImpl;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.mock.BaseDeviceOrganizationTest;
|
||||
@ -285,6 +286,21 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
|
||||
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddDeviceOrganizationWithNullParent")
|
||||
public void testGetAllOrganizationsForRoots() throws DeviceOrganizationMgtPluginException {
|
||||
|
||||
int offSet = 0;
|
||||
int limit = 100;
|
||||
boolean includeDevice = true;
|
||||
int maxDepth =100;
|
||||
RootChildrenRequest request = new RootChildrenRequest(offSet, limit);
|
||||
request.setMaxDepth(maxDepth);
|
||||
request.setIncludeDevice(includeDevice);
|
||||
List<DeviceNodeResult> nodeResultList = deviceOrganizationService.getAllDeviceOrganizationsForRoots(request);
|
||||
Assert.assertNotNull(nodeResultList, "Cannot be null");
|
||||
Assert.assertFalse(nodeResultList.isEmpty(), "List of node result should not be empty");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddDeviceOrganizationWithNullParent")
|
||||
public void testGetRootOrganizations() throws DeviceOrganizationMgtPluginException {
|
||||
int offset = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user