Adding effective policy service

revert-70aa11f8
Supun94 8 years ago
parent c91da9219d
commit 33b79dcbba

@ -562,5 +562,9 @@ public interface PolicyManagementService {
required = true) required = true)
List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies); 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 //TODO : to revove the stale reference
private PolicyManagerService policyManagerService; private PolicyManagerService policyManagerService;
private List<Policy> policyList; private List<Policy> policyList;
PIPDevice pipDevice;
// public SimpleEvaluationPoint() { // public SimpleEvaluationPoint() {
// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); // policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
// } // }
@ -73,15 +74,26 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint {
@Override @Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
if (policyManagerService == null || policyList.size() == 0) { try {
return null; policyManagerService = getPolicyManagerService();
} PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP();
pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
Policy policy = new Policy(); if (policyManagerService == null || policyList.size() == 0) {
Profile profile = new Profile(); return null;
profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); }
policy.setProfile(profile);
return policy; 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);
}
} }
private Policy policyResolve(List<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException { private Policy policyResolve(List<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException {

Loading…
Cancel
Save