From e07d917ad60f07e87476e26a05372017de5f1046 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 21 May 2015 20:41:57 +0530 Subject: [PATCH] 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 d05dd69bb7..338170cfba 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 abcaafd3f8..cdda237ca7 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 57d8cdffec..188a742f3d 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);