mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding effective policy service
This commit is contained in:
parent
c91da9219d
commit
33b79dcbba
@ -562,5 +562,9 @@ public interface PolicyManagementService {
|
||||
required = true)
|
||||
List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies);
|
||||
|
||||
@GET
|
||||
@Path("/effective-policy/{deviceType}/{deviceId}")
|
||||
@Permission(name = "Get Effective Policy of Devices", permission = "/device-mgt/policies/view")
|
||||
Response getEffectivePolicy(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType);
|
||||
|
||||
}
|
||||
|
||||
@ -373,4 +373,29 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/effective-policy/{deviceType}/{deviceId}")
|
||||
@Override
|
||||
public Response getEffectivePolicy(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType) {
|
||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||
final org.wso2.carbon.policy.mgt.common.Policy policy;
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(deviceId);
|
||||
deviceIdentifier.setType(deviceType);
|
||||
policy = policyManagementService.getEffectivePolicy(deviceIdentifier);
|
||||
if (policy == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"No policy found for device ID '" + deviceId + "'"+ deviceId).build()).build();
|
||||
}
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred while retrieving policy corresponding to the id '" + deviceType + "'"+ deviceId;
|
||||
log.error(msg, e);
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(policy).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint {
|
||||
//TODO : to revove the stale reference
|
||||
private PolicyManagerService policyManagerService;
|
||||
private List<Policy> policyList;
|
||||
PIPDevice pipDevice;
|
||||
// public SimpleEvaluationPoint() {
|
||||
// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
|
||||
// }
|
||||
@ -73,15 +74,26 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint {
|
||||
@Override
|
||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
||||
|
||||
if (policyManagerService == null || policyList.size() == 0) {
|
||||
return null;
|
||||
try {
|
||||
policyManagerService = getPolicyManagerService();
|
||||
PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP();
|
||||
pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
|
||||
policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
|
||||
|
||||
if (policyManagerService == null || policyList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Policy policy = new Policy();
|
||||
Profile profile = new Profile();
|
||||
profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier));
|
||||
policy.setProfile(profile);
|
||||
return policy;
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred when retrieving the policy related data from policy management service.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyEvaluationException(msg, e);
|
||||
}
|
||||
|
||||
Policy policy = new Policy();
|
||||
Profile profile = new Profile();
|
||||
profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier));
|
||||
policy.setProfile(profile);
|
||||
return policy;
|
||||
}
|
||||
|
||||
private Policy policyResolve(List<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user