From e07d917ad60f07e87476e26a05372017de5f1046 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 21 May 2015 20:41:57 +0530 Subject: [PATCH 1/2] Fixing bugs --- .../mgt/core/PolicyManagerServiceImpl.java | 67 ++++++++++--------- .../mgt/core/impl/PolicyFilterImpl.java | 3 + .../decision/point/SimpleEvaluationImpl.java | 7 +- 3 files changed, 45 insertions(+), 32 deletions(-) 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 d05dd69bb7a..338170cfba5 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 @@ -86,28 +86,31 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { Policy policy = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). getEffectivePolicy(deviceIdentifier); - List effectiveFeatures =policy.getProfile().getProfileFeaturesList(); + if (policy != null) { - PolicyOperation policyOperation = new PolicyOperation(); + List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); - List profileOperationList = new ArrayList(); - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); + PolicyOperation policyOperation = new PolicyOperation(); - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); - - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); + List profileOperationList = new ArrayList(); + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation operation = new ProfileOperation(); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + operation.setCode(feature.getFeatureCode()); + operation.setPayLoad(feature.getContent()); + profileOperationList.add(operation); + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(policyOperation, deviceIdentifiers); + } else { + return null; + } return policy; } catch (PolicyEvaluationException e) { @@ -131,24 +134,28 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { List effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). getEffectiveFeatures(deviceIdentifier); - PolicyOperation policyOperation = new PolicyOperation(); + if (!effectiveFeatures.isEmpty()) { + PolicyOperation policyOperation = new PolicyOperation(); - List profileOperationList = new ArrayList(); - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); + List profileOperationList = new ArrayList(); + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation operation = new ProfileOperation(); - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); + operation.setCode(feature.getFeatureCode()); + operation.setPayLoad(feature.getContent()); + profileOperationList.add(operation); + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(policyOperation, deviceIdentifiers); + } else { + return null; + } return effectiveFeatures; } catch (PolicyEvaluationException e) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java index abcaafd3f8e..cdda237ca70 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java @@ -39,6 +39,9 @@ public class PolicyFilterImpl implements PolicyFilter { for (Policy policy : policies) { List tempRoles = policy.getRoles(); + if (tempRoles != null) { + continue; + } if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) { temp.add(policy); continue; diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java index 57d8cdffece..188a742f3d1 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java @@ -55,8 +55,11 @@ public class SimpleEvaluationImpl implements SimpleEvaluation { policyList = policyInformationPoint.getRelatedPolicies(pipDevice); sortPolicies(); - policy = policyList.get(0); - + if(!policyList.isEmpty()) { + policy = policyList.get(0); + } else { + return null; + } //TODO : UNCOMMENT THE FOLLOWING CASE // policyAdministratorPoint = policyManagerService.getPAP(); // policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy); From a1f851243c8753bd24733863861b953874ee5fb5 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 21 May 2015 21:33:53 +0530 Subject: [PATCH 2/2] Fixing null pointer issue --- .../org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java index cdda237ca70..b9552e542ef 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java @@ -39,7 +39,7 @@ public class PolicyFilterImpl implements PolicyFilter { for (Policy policy : policies) { List tempRoles = policy.getRoles(); - if (tempRoles != null) { + if (tempRoles == null) { continue; } if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) {