From a872caeefc70a74af0febcdc0a405cfba35a92af Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Tue, 5 May 2015 08:25:15 +0530 Subject: [PATCH] Code revie fixes --- .../carbon/policy/mgt/common/PIPDevice.java | 19 +++++------ .../mgt/common/PolicyEvaluationPoint.java | 4 +-- .../src/main/resources/mysql.sql | 2 +- .../mgt/core/PolicyManagerServiceImpl.java | 2 +- .../policy/mgt/core/dao/FeatureDAO.java | 6 ++-- .../mgt/core/dao/impl/FeatureDAOImpl.java | 18 +++++------ .../mgt/core/dao/impl/PolicyDAOImpl.java | 7 +--- .../PolicyManagementServiceComponent.java | 5 ++- .../src/test/resources/sql/CreateH2TestDB.sql | 2 +- .../test/resources/sql/CreateMySqlTestDB.sql | 32 ++++++++++++++++++- .../point/PolicyEvaluationServiceImpl.java | 2 +- .../decision/point/SimpleEvaluation.java | 2 +- .../decision/point/SimpleEvaluationImpl.java | 10 +++--- 13 files changed, 70 insertions(+), 41 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java index 2605895a2c9..2bef8e14971 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java @@ -27,17 +27,18 @@ import java.sql.Timestamp; import java.util.List; import java.util.Map; +//TODO : public class PIPDevice { - Device device; - DeviceType deviceType; - DeviceIdentifier deviceIdentifier; - String ownershipType; - List userIds; - String roles []; - String altitude; - String longitude; - Timestamp timestamp; + private Device device; + private DeviceType deviceType; + private DeviceIdentifier deviceIdentifier; + private String ownershipType; + private List userIds; + private String roles[]; + private String altitude; + private String longitude; + private Timestamp timestamp; /*This will be used to record attributes to which would come from other PDPs*/ Map attributes; 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 0ee56812fe5..ef4f84988de 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 @@ -34,7 +34,7 @@ public interface PolicyEvaluationPoint { * @param deviceIdentifier device information. * @return returns the effective policy. */ - Policy getEffectivePolicies(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; /** @@ -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(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql index 9102ed00c14..bd85b06e14c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql @@ -124,7 +124,7 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` ( `NAME` VARCHAR(256) NOT NULL , `CODE` VARCHAR(45) NULL DEFAULT NULL , `DESCRIPTION` TEXT NULL DEFAULT NULL , - `EVALUVATION_RULE` VARCHAR(60) NOT NULL , + `EVALUATION_RULE` VARCHAR(60) NOT NULL , PRIMARY KEY (`ID`) ) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1; 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 9fb7cbdb243..f1e67cd26a2 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 @@ -77,7 +77,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { try { return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). - getEffectivePolicies(deviceIdentifier); + getEffectivePolicy(deviceIdentifier); } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective policies from the PEP service for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java index 3f2f130a83c..79a0e4f8268 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java @@ -38,9 +38,11 @@ public interface FeatureDAO { ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; - List addProfileFeatures(List features, int profileId) throws FeatureManagerDAOException; + List addProfileFeatures(List features, int profileId) throws + FeatureManagerDAOException; - List updateProfileFeatures(List features, int profileId) throws FeatureManagerDAOException; + List updateProfileFeatures(List features, int profileId) throws + FeatureManagerDAOException; List getAllFeatures() throws FeatureManagerDAOException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java index ed740f4ab62..276cf3a2ca3 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java @@ -50,7 +50,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUVATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)"; + String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, feature.getName()); stmt.setString(2, feature.getCode()); @@ -88,7 +88,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUVATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)"; + String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); for (Feature feature : features) { @@ -133,7 +133,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ?, EVALUVATION_RULE = ? WHERE ID = ?"; + String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ?, EVALUATION_RULE = ? WHERE ID = ?"; stmt = conn.prepareStatement(query); stmt.setString(1, feature.getName()); stmt.setString(2, feature.getCode()); @@ -266,7 +266,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUVATION_RULE FROM DM_FEATURES"; + String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUATION_RULE FROM DM_FEATURES"; stmt = conn.prepareStatement(query); resultSet = stmt.executeQuery(); @@ -277,7 +277,7 @@ public class FeatureDAOImpl implements FeatureDAO { feature.setCode(resultSet.getString("CODE")); feature.setName(resultSet.getString("NAME")); feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); - feature.setRuleValue(resultSet.getString("EVALUVATION_RULE")); + feature.setRuleValue(resultSet.getString("EVALUATION_RULE")); featureList.add(feature); } @@ -303,7 +303,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " + - "F.EVALUVATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " + + "F.EVALUATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " + "JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID"; stmt = conn.prepareStatement(query); resultSet = stmt.executeQuery(); @@ -345,7 +345,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); String query = "SELECT f.ID ID, f.NAME NAME, f.CODE CODE, f.DEVICE_TYPE_ID DEVICE_TYPE_ID," + - " f.EVALUVATION_RULE EVALUVATION_RULE FROM DM_FEATURES f INNER JOIN DM_DEVICE_TYPE d " + + " f.EVALUATION_RULE EVALUATION_RULE FROM DM_FEATURES f INNER JOIN DM_DEVICE_TYPE d " + "ON d.ID=f.DEVICE_TYPE_ID WHERE d.NAME = ?"; stmt = conn.prepareStatement(query); stmt.setString(1, deviceType); @@ -358,7 +358,7 @@ public class FeatureDAOImpl implements FeatureDAO { feature.setCode(resultSet.getString("CODE")); feature.setName(resultSet.getString("NAME")); feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); - feature.setRuleValue(resultSet.getString("EVALUVATION_RULE")); + feature.setRuleValue(resultSet.getString("EVALUATION_RULE")); featureList.add(feature); } @@ -384,7 +384,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " + - "F.EVALUVATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " + + "F.EVALUATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " + "JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?"; stmt = conn.prepareStatement(query); stmt.setInt(1, profileId); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index 120937a0fe0..b57841dd4de 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -20,13 +20,8 @@ package org.wso2.carbon.policy.mgt.core.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.core.dto.Device; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyDates; -import org.wso2.carbon.policy.mgt.common.PolicyLocations; -import org.wso2.carbon.policy.mgt.common.PolicyTimes; -import org.wso2.carbon.policy.mgt.common.ProfileFeature; +import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index cb227200ef8..dc65f1a5875 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -53,7 +53,7 @@ import org.wso2.carbon.user.core.service.RealmService; * bind="setDeviceManagementService" * unbind="unsetDeviceManagementService" */ - +@SuppressWarnings("unused") public class PolicyManagementServiceComponent { private static Log log = LogFactory.getLog(PolicyManagementServiceComponent.class); @@ -70,8 +70,7 @@ public class PolicyManagementServiceComponent { PolicyManagerService.class.getName(), new PolicyManagementService(), null); } catch (Throwable t) { - String msg = "Error occurred while initializing the Policy management core."; - log.error(msg, t); + log.error("Error occurred while initializing the Policy management core.", t); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index d6eb8f0a733..9762f4d8a26 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS DM_FEATURES ( CODE VARCHAR(45) NULL DEFAULT NULL , DEVICE_TYPE_ID INT NOT NULL , DESCRIPTION TEXT NULL DEFAULT NULL , - EVALUVATION_RULE VARCHAR(60) NOT NULL , + EVALUATION_RULE VARCHAR(60) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT DM_FEATURES_DEVICE_TYPE FOREIGN KEY (DEVICE_TYPE_ID ) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql index e0959de5571..e5aa29f0bf7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql @@ -154,7 +154,7 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` ( `CODE` VARCHAR(45) NULL DEFAULT NULL , `DEVICE_TYPE_ID` INT NOT NULL , `DESCRIPTION` TEXT NULL DEFAULT NULL , - `EVALUVATION_RULE` VARCHAR(60) NOT NULL , + `EVALUATION_RULE` VARCHAR(60) NOT NULL , PRIMARY KEY (`ID`) , INDEX `DM_FEATURES_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , CONSTRAINT `DM_FEATURES_DEVICE_TYPE` @@ -286,6 +286,36 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_USER_POLICY` ( ENGINE = InnoDB; +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ( + `ID` INT NOT NULL AUTO_INCREMENT , + `DEVICE_ID` INT NOT NULL , + `POLICY_ID` INT NOT NULL , + `POLICY_CONTENT` BLOB NULL , + `APPLIED` TINYINT(1) NULL , + `CREATED_TIME` TIMESTAMP NULL , + `UPDATED_TIME` TIMESTAMP NULL , + `APPLIED_TIME` TIMESTAMP NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_DM_POLICY_DEVCIE_APPLIED` (`DEVICE_ID` ASC) , + INDEX `FK_DM_POLICY_DEVICE_APPLIED_POLICY` (`POLICY_ID` ASC) , + CONSTRAINT `FK_DM_POLICY_DEVCIE_APPLIED` + FOREIGN KEY (`DEVICE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DM_POLICY_DEVICE_APPLIED_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java index 4fbacba173d..f77c7921889 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java @@ -35,7 +35,7 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { } @Override - public Policy getEffectivePolicies(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { return evaluation.getEffectivePolicy(deviceIdentifier); } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java index 2019f3f632a..fb96100a06a 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java @@ -25,7 +25,7 @@ import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; public interface SimpleEvaluation { - void sortPolicy() throws PolicyEvaluationException; + void sortPolicies() throws PolicyEvaluationException; Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; 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 7e8a4e50e79..26ee12c15c1 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 @@ -25,14 +25,16 @@ import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder; +import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SimpleEvaluationImpl implements SimpleEvaluation { private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class); + //TODO : to revove the stale reference private PolicyManagerService policyManagerService; - private List policyList; + private List policyList = new ArrayList(); public SimpleEvaluationImpl() { policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); @@ -45,13 +47,13 @@ public class SimpleEvaluationImpl implements SimpleEvaluation { PolicyInformationPoint policyInformationPoint; try { - if (policyManagerService != null && policyList == null) { + if (policyManagerService != null) { policyInformationPoint = policyManagerService.getPIP(); PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); policyList = policyInformationPoint.getRelatedPolicies(pipDevice); - sortPolicy(); + sortPolicies(); policy = policyList.get(0); policyAdministratorPoint = policyManagerService.getPAP(); @@ -69,7 +71,7 @@ public class SimpleEvaluationImpl implements SimpleEvaluation { @Override - public void sortPolicy() throws PolicyEvaluationException { + public void sortPolicies() throws PolicyEvaluationException { Collections.sort(policyList); } }