mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add new API to fetch UI policy list
This commit is contained in:
parent
946a12b84d
commit
340be6ed65
@ -860,4 +860,81 @@ public interface PolicyManagementService {
|
||||
@QueryParam("limit")
|
||||
int limit
|
||||
);
|
||||
|
||||
@GET
|
||||
@Path("/list")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting list of Policies",
|
||||
responseContainer = "List",
|
||||
notes = "Retrieve the details of all the policies in WSO2 EMM.",
|
||||
response = Policy.class,
|
||||
tags = "Device Policy Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:policies:get-details")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched policies.",
|
||||
response = Policy.class,
|
||||
responseContainer = "List",
|
||||
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 = 304,
|
||||
message = "Not Modified. \n Empty body because the client already has the latest version " +
|
||||
"of the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@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 policies."),
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getPolicyList(
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Checks if the requested variant was modified, since the specified date-time. \n" +
|
||||
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
|
||||
"Example: Mon, 05 Jan 2014 15:10:00 +0200",
|
||||
required = false)
|
||||
@HeaderParam("If-Modified-Since")
|
||||
String ifModifiedSince,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "The starting pagination index for the complete list of qualified items",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many policy details you require from the starting pagination index/offset.",
|
||||
required = false,
|
||||
defaultValue = "5")
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
}
|
||||
|
||||
@ -498,4 +498,35 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/list")
|
||||
@Override
|
||||
public Response getPolicyList(
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||
List<Policy> policies;
|
||||
List<Policy> filteredPolicies;
|
||||
PolicyList targetPolicies = new PolicyList();
|
||||
try {
|
||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||
policies = policyAdministratorPoint.getPolicyList();
|
||||
targetPolicies.setCount(policies.size());
|
||||
if (offset == 0 && limit == 0) {
|
||||
targetPolicies.setList(policies);
|
||||
} else {
|
||||
filteredPolicies = FilteringUtil.getFilteredList(policies, offset, limit);
|
||||
targetPolicies.setList(filteredPolicies);
|
||||
}
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred while retrieving all available policies";
|
||||
log.error(msg, e);
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(targetPolicies).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -163,4 +163,6 @@ public interface PolicyAdministratorPoint {
|
||||
* @throws PolicyManagementException
|
||||
*/
|
||||
List<Policy> getPolicies(String policyType) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPolicyList() throws PolicyManagementException;
|
||||
}
|
||||
|
||||
@ -332,4 +332,9 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||
return policyManager.getPolicies(policyType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPolicyList() throws PolicyManagementException {
|
||||
return policyManager.getPolicyList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,4 +89,6 @@ public interface PolicyManager {
|
||||
HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPolicies(String type) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPolicyList() throws PolicyManagementException;
|
||||
}
|
||||
|
||||
@ -1502,4 +1502,33 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
correctiveAction.setAssociatedGeneralPolicyId(null); //avoiding send in payload
|
||||
correctiveAction.setFeatureId(null); //avoiding send in payload
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPolicyList() throws PolicyManagementException {
|
||||
|
||||
List<Policy> policyList;
|
||||
try {
|
||||
PolicyManagementDAOFactory.openConnection();
|
||||
policyList = policyDAO.getAllPolicies();
|
||||
for (Policy policy : policyList) {
|
||||
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
||||
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
|
||||
List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId());
|
||||
if (!deviceGroupWrappers.isEmpty()) {
|
||||
deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);
|
||||
}
|
||||
policy.setDeviceGroups(deviceGroupWrappers);
|
||||
}
|
||||
Collections.sort(policyList);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
throw new PolicyManagementException("Error occurred while getting all the policies.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
||||
} catch (GroupManagementException e) {
|
||||
throw new PolicyManagementException("Error occurred while getting device groups.", e);
|
||||
} finally {
|
||||
PolicyManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return policyList;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user