From 272ba7b012633a422a3a63d59971984cf1267481 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 14:01:32 +0530 Subject: [PATCH] Changed getEffectiveFeatures method --- .../point/merged/MergedEvaluationPoint.java | 25 +++++++++++-------- .../mgt/common/PolicyEvaluationPoint.java | 2 +- .../policy/mgt/core/PolicyManagerService.java | 2 +- .../mgt/core/PolicyManagerServiceImpl.java | 11 +++++--- .../services/SimplePolicyEvaluationTest.java | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java index b56c459992..88b9a36ad4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java @@ -37,24 +37,16 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { PIPDevice pipDevice; @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { PolicyAdministratorPoint policyAdministratorPoint; - PolicyInformationPoint policyInformationPoint; policyManagerService = getPolicyManagerService(); try { if (policyManagerService != null) { - policyInformationPoint = policyManagerService.getPIP(); - PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); - policyList = policyInformationPoint.getRelatedPolicies(pipDevice); - if (!policyList.isEmpty()) { - //policy = policyList.get(0); - //policyList = new ArrayList(); Policy effectivePolicy = policyResolve(policyList); effectivePolicy.setActive(true); - //TODO : UNCOMMENT THE FOLLOWING CASE policyAdministratorPoint = policyManagerService.getPAP(); policyAdministratorPoint.setPolicyUsed(deviceIdentifier, effectivePolicy); return effectivePolicy.getProfile().getProfileFeaturesList(); @@ -83,7 +75,7 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { Policy policy = new Policy(); Profile profile = new Profile(); - profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); + profile.setProfileFeaturesList(getEffectiveFeatures(policyList, deviceIdentifier)); policy.setProfile(profile); Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); profile.setCreatedDate(currentTimestamp); @@ -113,6 +105,8 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { // Iterate through all policies Map featureMap = new HashMap<>(); + // Merge roles of policies + //Map rolesMap = new HashMap<>(); Iterator policyIterator = policyList.iterator(); while (policyIterator.hasNext()) { Policy policy = policyIterator.next(); @@ -124,6 +118,16 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { featureMap.put(feature.getFeatureCode(), feature); } } +// List policyRolesList = policy.getRoles(); +// +// if (policyRolesList != null) { +// Iterator roleIterator = policyRolesList.iterator(); +// while (roleIterator.hasNext()) { +// String role = roleIterator.next(); +// rolesMap.put(role,policy.getId()); +// } +// } + } // Get prioritized features list @@ -133,6 +137,7 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { Policy effectivePolicy = new Policy(); effectivePolicy.setProfile(profile); + //effectivePolicy.setRoles(rolesList); return effectivePolicy; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java index ef4f84988d..3fbf83ff9c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java @@ -42,5 +42,5 @@ public interface PolicyEvaluationPoint { * @param deviceIdentifier device information. * @return returns the effective feature set. */ - List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index 96d7aac4d2..c8bd6e1d2f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -51,7 +51,7 @@ public interface PolicyManagerService { Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; - List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException; + List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws FeatureManagementException; List getPolicies(String deviceType) throws PolicyManagementException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index 89c244f55a..1cd88a72d0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -133,11 +133,16 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { } @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws + public List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws FeatureManagementException { try { - return PolicyManagementDataHolder.getInstance(). - getPolicyEvaluationPoint().getEffectiveFeatures(deviceIdentifier); + PolicyEvaluationPoint policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); + if (policyEvaluationPoint != null) { + return policyEvaluationPoint.getEffectiveFeatures(policyList, deviceIdentifier); + } else { + throw new FeatureManagementException("Error occurred while getting the policy evaluation point " + + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); + } } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective features from the PEP service " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java index b4bed5da4d..ee62eb3ad7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java @@ -72,7 +72,7 @@ public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint { } @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { return null; }