diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java index 0636e1689a..b43d1b627d 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java @@ -21,29 +21,30 @@ package org.wso2.carbon.policy.evaluator; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import java.util.List; import java.util.Map; public interface FeatureFilter { - List evaluate(List policyList, List featureRulesList); + List evaluate(List policyList, List featureRulesList); - List extractFeatures(List policyList); + List extractFeatures(List policyList); - List evaluateFeatures(List featureList, List featureRulesList); + List evaluateFeatures(List featureList, List featureRulesList); - void getDenyOverridesFeatures(String featureName, List featureList, List effectiveFeatureList); + void getDenyOverridesFeatures(String featureName, List featureList, List effectiveFeatureList); - void getPermitOverridesFeatures(String featureName, List featureList, List effectiveFeatureList); + void getPermitOverridesFeatures(String featureName, List featureList, List effectiveFeatureList); - void getFirstApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); + void getFirstApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); - void getLastApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); + void getLastApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); - void getAllApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); + void getAllApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); - void getHighestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); + void getHighestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); - void getLowestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); + void getLowestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList); } diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java index a43922b4ab..142ab341e1 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java @@ -21,6 +21,7 @@ package org.wso2.carbon.policy.evaluator; import org.wso2.carbon.policy.evaluator.utils.Constants; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import java.util.ArrayList; import java.util.List; @@ -39,7 +40,7 @@ public class FeatureFilterImpl implements FeatureFilter { * @return */ @Override - public List evaluate(List policyList, List featureRulesList) { + public List evaluate(List policyList, List featureRulesList) { return evaluateFeatures(extractFeatures(policyList), featureRulesList); } @@ -48,10 +49,10 @@ public class FeatureFilterImpl implements FeatureFilter { * @param policyList * @return */ - public List extractFeatures(List policyList) { - List featureList = new ArrayList(); + public List extractFeatures(List policyList) { + List featureList = new ArrayList(); for (Policy policy : policyList) { - featureList.addAll(policy.getProfile().getFeaturesList()); + featureList.addAll(policy.getProfile().getProfileFeaturesList()); } return featureList; } @@ -62,8 +63,8 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureRulesList * @return */ - public List evaluateFeatures(List featureList, List featureRulesList) { - List effectiveFeatureList = new ArrayList(); + public List evaluateFeatures(List featureList, List featureRulesList) { + List effectiveFeatureList = new ArrayList(); for (FeatureRules rule : featureRulesList) { String ruleName = rule.getEvaluationCriteria(); String featureName = rule.getName(); @@ -100,11 +101,11 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getDenyOverridesFeatures(String featureName, List featureList, List effectiveFeatureList) { - Feature evaluatedFeature = null; - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { - if (feature.getRuleValue().equalsIgnoreCase("Deny")) { + public void getDenyOverridesFeatures(String featureName, List featureList, List effectiveFeatureList) { + ProfileFeature evaluatedFeature = null; + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { + if (feature.getFeature().getRuleValue().equalsIgnoreCase("Deny")) { evaluatedFeature = feature; effectiveFeatureList.add(evaluatedFeature); return; @@ -127,11 +128,11 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getPermitOverridesFeatures(String featureName, List featureList, List effectiveFeatureList) { - Feature evaluatedFeature = null; - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { - if (feature.getRuleValue().equalsIgnoreCase("Permit")) { + public void getPermitOverridesFeatures(String featureName, List featureList, List effectiveFeatureList) { + ProfileFeature evaluatedFeature = null; + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { + if (feature.getFeature().getRuleValue().equalsIgnoreCase("Permit")) { evaluatedFeature = feature; effectiveFeatureList.add(evaluatedFeature); return; @@ -154,9 +155,9 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getFirstApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { + public void getFirstApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { effectiveFeatureList.add(feature); return; @@ -172,10 +173,10 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getLastApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { - Feature evaluatedFeature = null; - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { + public void getLastApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { + ProfileFeature evaluatedFeature = null; + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { evaluatedFeature = feature; } } @@ -192,9 +193,9 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getAllApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { + public void getAllApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { effectiveFeatureList.add(feature); } } @@ -208,13 +209,13 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getHighestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { - Feature evaluatedFeature = null; + public void getHighestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { + ProfileFeature evaluatedFeature = null; int intValve = 0; - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { - if (Integer.parseInt(feature.getRuleValue()) > intValve) { - intValve = Integer.parseInt(feature.getRuleValue()); + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { + if (Integer.parseInt(feature.getFeature().getRuleValue()) > intValve) { + intValve = Integer.parseInt(feature.getFeature().getRuleValue()); evaluatedFeature = feature; } } @@ -232,13 +233,13 @@ public class FeatureFilterImpl implements FeatureFilter { * @param featureList * @param effectiveFeatureList */ - public void getLowestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { - Feature evaluatedFeature = null; + public void getLowestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { + ProfileFeature evaluatedFeature = null; int intValve = 0; - for (Feature feature : featureList) { - if (feature.getName().equalsIgnoreCase(featureName)) { - if (Integer.parseInt(feature.getRuleValue()) < intValve) { - intValve = Integer.parseInt(feature.getRuleValue()); + for (ProfileFeature feature : featureList) { + if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { + if (Integer.parseInt(feature.getFeature().getRuleValue()) < intValve) { + intValve = Integer.parseInt(feature.getFeature().getRuleValue()); evaluatedFeature = feature; } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java index 2cdb6bcf9f..7ced5c7839 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.policy.information.point; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.PIPDevice; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; @@ -28,12 +28,12 @@ import java.util.List; public class PolicyInformationServiceImpl implements PolicyInformationPoint { @Override - public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) { + public PIPDevice getDeviceData(DeviceIdentifier deviceIdentifier) { return null; } @Override - public List getRelatedPolicies(PIPDeviceData pipDeviceData) { + public List getRelatedPolicies(PIPDevice pipDevice) { return null; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java index 0023cf6326..87d6dcf034 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java @@ -24,8 +24,9 @@ public class Feature { private String code; private String name; private String description; - private Object attribute; + // private Object attribute; private String ruleValue; + private int deviceTypeId; public String getDescription() { return description; @@ -67,11 +68,19 @@ public class Feature { this.name = name; } - public Object getAttribute() { +/* public Object getAttribute() { return attribute; } public void setAttribute(Object attribute) { this.attribute = attribute; + }*/ + + public int getDeviceTypeId() { + return deviceTypeId; + } + + public void setDeviceTypeId(int deviceTypeId) { + this.deviceTypeId = deviceTypeId; } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java similarity index 85% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java index d234fa96b1..5cdaa1f070 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java @@ -19,6 +19,7 @@ package org.wso2.carbon.policy.mgt.common; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.dto.DeviceType; @@ -26,13 +27,14 @@ import java.sql.Timestamp; import java.util.List; import java.util.Map; -public class PIPDeviceData { +public class PIPDevice { Device device; DeviceType deviceType; + DeviceIdentifier deviceIdentifier; String ownershipType; List userIds; - List roles; + String roles []; String altitude; String longitude; Timestamp timestamp; @@ -72,11 +74,11 @@ public class PIPDeviceData { this.userIds = userIds; } - public List getRoles() { + public String[] getRoles() { return roles; } - public void setRoles(List roles) { + public void setRoles(String roles[]) { this.roles = roles; } @@ -111,4 +113,12 @@ public class PIPDeviceData { public void setAttributes(Map attributes) { this.attributes = attributes; } + + public DeviceIdentifier getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index 130f367fd5..b2b80acbb8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java @@ -18,6 +18,9 @@ package org.wso2.carbon.policy.mgt.common; + +import org.wso2.carbon.device.mgt.core.dto.Device; + import java.sql.Date; import java.util.List; import java.util.Map; @@ -33,7 +36,7 @@ public class Policy { private boolean generic; // If true, this should be applied to all related device. private List roleList; // Roles which this policy should be applied. private String ownershipType; // Ownership type (COPE, BYOD, CPE) - private List DeviceList; // Individual devices this policy should be applied + private List DeviceList; // Individual devices this policy should be applied /*Dynamic policy attributes*/ @@ -47,9 +50,11 @@ public class Policy { /*These are related to location based policies*/ - private String altitude; // Altitude + private String latitude; // Latitude private String longitude; // Longitude + private int tenantId; + /*This will be used to record attributes which will be used by customer extended PDPs and PIPs*/ private Map attributes; @@ -110,11 +115,11 @@ public class Policy { this.ownershipType = ownershipType; } - public List getDeviceList() { + public List getDeviceList() { return DeviceList; } - public void setDeviceList(List deviceList) { + public void setDeviceList(List deviceList) { DeviceList = deviceList; } @@ -150,12 +155,12 @@ public class Policy { this.endDate = endDate; } - public String getAltitude() { - return altitude; + public String getLatitude() { + return latitude; } - public void setAltitude(String altitude) { - this.altitude = altitude; + public void setLatitude(String latitude) { + this.latitude = latitude; } public String getLongitude() { @@ -173,4 +178,12 @@ public class Policy { public void setAttributes(Map attributes) { this.attributes = attributes; } + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } } \ No newline at end of file diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 2174b64c12..557647955b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -18,6 +18,10 @@ package org.wso2.carbon.policy.mgt.common; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + +import java.util.List; + /** * This interface defines the policy management which should be implemented by the plugins */ @@ -39,13 +43,12 @@ public interface PolicyAdministratorPoint { /** * This method adds a policy per device which should be implemented by the related plugins. * - * @param deviceId - * @param deviceType + * @param deviceIdentifierr * @param policy * @return primary key (generated key) */ - Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; + Policy addPolicyToDevice(DeviceIdentifier deviceIdentifierr, Policy policy) throws FeatureManagementException, PolicyManagementException; /** * This method adds the policy to specific role. @@ -62,7 +65,7 @@ public interface PolicyAdministratorPoint { * @return */ - Policy getPolicy(); + List getPolicies() throws PolicyManagementException; /** * This method gives the device specific policy. @@ -72,7 +75,7 @@ public interface PolicyAdministratorPoint { * @return Policy */ - Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException; + List getPoliciesOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException; /** * This method returns the device type specific policy. @@ -81,7 +84,7 @@ public interface PolicyAdministratorPoint { * @return Policy */ - Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException; + List getPoliciesOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException; /** * This method returns the role specific policy. @@ -90,38 +93,35 @@ public interface PolicyAdministratorPoint { * @return */ - Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException; + List getPoliciesOfRole(String roleName) throws FeatureManagementException, PolicyManagementException; /** * This method checks weather a policy is available for a device. * - * @param deviceId - * @param deviceType + * @param deviceIdentifier * @return * @throws PolicyManagementException */ - boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException; + boolean isPolicyAvailableForDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; /** * This method checks weather a policy is used by a particular device. * - * @param deviceId - * @param deviceType + * @param deviceIdentifier * @return * @throws PolicyManagementException */ - boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException; + boolean isPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; /** - * @param deviceId - * @param deviceType + * @param deviceIdentifier * @param policy * @throws PolicyManagementException */ - void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException; + void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException; /** * This method will add the profile to database, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java index 0ba6f912ff..af81c68a27 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java @@ -20,7 +20,6 @@ package org.wso2.carbon.policy.mgt.common; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.core.dto.Device; import java.util.List; @@ -33,16 +32,16 @@ public interface PolicyInformationPoint { * This method will return the data related Device, Some of the device data will provided in the initial pipDeviceData object such as * device id, device time and location, Other data such as roles, owned users and ownership type will be filled by this method. * @param deviceIdentifier device data. - * @return PIPDeviceData + * @return PIPDevice */ - PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; + PIPDevice getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; /** * This method will retrieve the policies related given device Data. - * @param pipDeviceData + * @param pipDevice * @return */ - List getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException; + List getRelatedPolicies(PIPDevice pipDevice) throws PolicyManagementException; /** * This is will retrieve the features related to device type. This feature list will be used for dynamically diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java index 9df30554a0..14e182036f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java @@ -33,7 +33,8 @@ public class Profile { private DeviceType deviceType; private Timestamp createdDate; private Timestamp updatedDate; - private List featuresList; // Features included in the policies. +// private List featuresList; // Features included in the policies. + private List profileFeaturesList; // Features included in the policies. public DeviceType getDeviceType() { return deviceType; @@ -51,13 +52,13 @@ public class Profile { this.tenantId = tenantId; } - public List getFeaturesList() { +/* public List getFeaturesList() { return featuresList; } public void setFeaturesList(List featuresList) { this.featuresList = featuresList; - } + }*/ public int getProfileId() { return profileId; @@ -90,4 +91,12 @@ public class Profile { public void setUpdatedDate(Timestamp updatedDate) { this.updatedDate = updatedDate; } + + public List getProfileFeaturesList() { + return profileFeaturesList; + } + + public void setProfileFeaturesList(List profileFeaturesList) { + this.profileFeaturesList = profileFeaturesList; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java new file mode 100644 index 0000000000..85075a0418 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.mgt.common; + +public class ProfileFeature { + + private int id; + private Feature feature; + private int profileId; + private Object content; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Feature getFeature() { + return feature; + } + + public void setFeature(Feature feature) { + this.feature = feature; + } + + public int getProfileId() { + return profileId; + } + + public void setProfileId(int profileId) { + this.profileId = profileId; + } + + public Object getContent() { + return content; + } + + public void setContent(Object content) { + this.content = content; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java index 6ea9e58422..12ae84564d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java @@ -34,7 +34,7 @@ public class PolicyCreator { Feature feature = new Feature(); feature.setName("Camera"); feature.setCode("502A"); - feature.setAttribute("disable"); + // feature.setAttribute("disable"); List featureList = new ArrayList(); featureList.add(feature); @@ -45,7 +45,7 @@ public class PolicyCreator { profile.setTenantId(-1234); policy.setProfile(profile); - profile.setFeaturesList(featureList); + //profile.setFeaturesList(featureList); policy.setPolicyName("Camera_related_policy"); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 9f4a752714..4cba9ee01b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -68,6 +68,8 @@ org.wso2.carbon.policy.mgt.common.*, org.wso2.carbon.user.core.*, org.wso2.carbon.utils.*, + org.wso2.carbon.context.*, + org.wso2.carbon.user.api.*, org.wso2.carbon.device.mgt.core.*, org.wso2.carbon.device.mgt.common.* diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java index 4aa1a1b828..533365b8a2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java @@ -47,4 +47,7 @@ public interface PolicyManager { List getFeatures() throws FeatureManagementException; + PolicyAdministratorPoint getPAP() throws PolicyManagementException; + + PolicyInformationPoint getPIP() throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java index 7b86d252e3..919cf07673 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java @@ -22,12 +22,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.policy.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl; +import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl; import java.util.List; @@ -90,4 +87,14 @@ public class PolicyManagerImpl implements PolicyManager { public List getFeatures() throws FeatureManagementException { return null; } + + @Override + public PolicyAdministratorPoint getPAP() throws PolicyManagementException { + return new PolicyAdministratorPointImpl(); + } + + @Override + public PolicyInformationPoint getPIP() throws PolicyManagementException { + return new PolicyInformationPointImpl(); + } } 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 1014756202..33de73c16e 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 @@ -22,6 +22,7 @@ package org.wso2.carbon.policy.mgt.core.dao; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import java.util.List; @@ -31,12 +32,22 @@ public interface FeatureDAO { Feature updateFeature(Feature feature) throws FeatureManagerDAOException; + ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; + + ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; + + List addProfileFeatures(List features, int profileId) throws FeatureManagerDAOException; + + List updateProfileFeatures(List features, int profileId) throws FeatureManagerDAOException; + List getAllFeatures() throws FeatureManagerDAOException; - List getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException; + List getAllFeatures(String deviceType) throws FeatureManagerDAOException; + + List getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException; - void deleteFeature(int featureId) throws FeatureManagerDAOException; + boolean deleteFeature(int featureId) throws FeatureManagerDAOException; - void deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; + boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index 8915e234ec..b61ff5a60f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -18,6 +18,7 @@ package org.wso2.carbon.policy.mgt.core.dao; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.Policy; @@ -33,46 +34,22 @@ public interface PolicyDAO { Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException; - Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException; + Policy addPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagerDAOException; Policy updatePolicy(Policy policy) throws PolicyManagerDAOException; - Policy getPolicy() throws PolicyManagerDAOException; + Policy getPolicy(int policyId) throws PolicyManagerDAOException; - Policy getPolicy(String deviceType) throws PolicyManagerDAOException; + Policy getPolicyByProfileID(int profileId) throws PolicyManagerDAOException; - Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException; + List getPolicy() throws PolicyManagerDAOException; - void deletePolicy(Policy policy) throws PolicyManagerDAOException; - - - - - - - - /* Profile addProfile(Profile profile) throws PolicyManagerDAOException; - - Profile updateProfile(Profile profile) throws PolicyManagerDAOException; + List getPolicy(String deviceType) throws PolicyManagerDAOException; - void deleteProfile(Profile profile) throws PolicyManagerDAOException; + List getPolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagerDAOException; - List getAllProfiles() throws PolicyManagerDAOException; + List getPolicyOfRole(String roleName) throws PolicyManagerDAOException; - List getProfilesOfDeviceType(String deviceType) throws PolicyManagerDAOException; - - - - - List getAllFeatures() throws PolicyManagerDAOException; - - List getFeaturesForProfile(int ProfileId) throws PolicyManagerDAOException; - - void deleteFeature(int featureId) throws PolicyManagerDAOException; - - void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException; - - Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; + void deletePolicy(Policy policy) throws PolicyManagerDAOException; - Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException;*/ } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java index b35354d8ad..32835c4e9a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java @@ -31,6 +31,8 @@ public interface ProfileDAO { void deleteProfile(Profile profile) throws ProfileManagerDAOException; + Profile getProfiles(int profileId) throws ProfileManagerDAOException; + List getAllProfiles() throws ProfileManagerDAOException; List getProfilesOfDeviceType(String deviceType) throws ProfileManagerDAOException; 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 42913cc7d6..2af11af6a5 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 @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.dao.*; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; @@ -75,11 +76,106 @@ public class FeatureDAOImpl implements FeatureDAO { @Override public Feature updateFeature(Feature feature) throws FeatureManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ?, EVALUVATION_RULE = ? WHERE ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setString(1, feature.getName()); + stmt.setString(2, feature.getCode()); + stmt.setString(3, feature.getDescription()); + stmt.setString(4, feature.getRuleValue()); + stmt.setInt(5, feature.getId()); + + stmt.executeUpdate(); + } catch (SQLException e) { + String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the database."; + log.error(msg, e); + throw new FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return feature; } @Override - public void deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException { + public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { + return null; + } + + @Override + public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { + return null; + } + + @Override + public List addProfileFeatures(List features, int profileId) throws FeatureManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_ID, CONTENT) VALUES (?, ?, ?)"; + + stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + for (ProfileFeature feature : features) { + stmt.setInt(1, profileId); + stmt.setInt(2, feature.getId()); + stmt.setObject(3, feature.getContent()); + stmt.addBatch(); + //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000 + } + stmt.executeBatch(); + + generatedKeys = stmt.getGeneratedKeys(); + int i = 0; + while (generatedKeys.next()) { + features.get(i).setId(generatedKeys.getInt(i)); + i++; + } + } catch (SQLException e) { + String msg = "Error occurred while adding the feature list to the database."; + log.error(msg, e); + throw new FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return features; + } + + @Override + public List updateProfileFeatures(List features, int profileId) throws FeatureManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ? , FEATURE_ID = ? "; + + stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + for (ProfileFeature feature : features) { + stmt.setObject(1, feature.getContent()); + stmt.setInt(2, profileId); + stmt.setInt(3, feature.getId()); + stmt.addBatch(); + //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000 + } + stmt.executeBatch(); + + } catch (SQLException e) { + String msg = "Error occurred while adding the feature list to the database."; + log.error(msg, e); + throw new FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return features; + } + + @Override + public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -89,6 +185,7 @@ public class FeatureDAOImpl implements FeatureDAO { stmt = conn.prepareStatement(query); stmt.setInt(1, profile.getProfileId()); stmt.executeUpdate(); + return true; } catch (SQLException e) { String msg = "Error occurred while deleting the feature related to a profile."; log.error(msg); @@ -109,7 +206,7 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "SELECT ID, NAME, CODE, EVALUVATION_RULE FROM DM_FEATURES"; + String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUVATION_RULE FROM DM_FEATURES"; stmt = conn.prepareStatement(query); resultSet = stmt.executeQuery(); @@ -118,6 +215,7 @@ public class FeatureDAOImpl implements FeatureDAO { feature.setId(resultSet.getInt("ID")); feature.setCode(resultSet.getString("CODE")); feature.setName(resultSet.getString("NAME")); + feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); feature.setRuleValue(resultSet.getString("EVALUVATION_RULE")); featureList.add(feature); } @@ -133,16 +231,52 @@ public class FeatureDAOImpl implements FeatureDAO { } @Override - public List getFeaturesForProfile(int profileId) throws FeatureManagerDAOException { + public List getAllFeatures(String deviceType) throws FeatureManagerDAOException { + Connection conn = null; PreparedStatement stmt = null; ResultSet resultSet = null; - List featureList = new ArrayList(); + 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 " + + "ON d.ID=f.DEVICE_TYPE_ID WHERE d.NAME = ?"; + stmt = conn.prepareStatement(query); + stmt.setString(1, deviceType); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + Feature feature = new Feature(); + feature.setId(resultSet.getInt("ID")); + feature.setCode(resultSet.getString("CODE")); + feature.setName(resultSet.getString("NAME")); + feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); + feature.setRuleValue(resultSet.getString("EVALUVATION_RULE")); + featureList.add(feature); + } + return featureList; + } catch (SQLException e) { + String msg = "Unable to get the list of the features related device type from database."; + log.error(msg); + throw new FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + } + + @Override + public List getFeaturesForProfile(int profileId) throws FeatureManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + List featureList = new ArrayList(); try { conn = this.getConnection(); - String query = "SELECT PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " + + 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 " + "JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?"; stmt = conn.prepareStatement(query); @@ -150,13 +284,18 @@ public class FeatureDAOImpl implements FeatureDAO { resultSet = stmt.executeQuery(); while (resultSet.next()) { + ProfileFeature profileFeature = new ProfileFeature(); Feature feature = new Feature(); feature.setId(resultSet.getInt("FEATURE_ID")); feature.setCode(resultSet.getString("CODE")); feature.setName(resultSet.getString("NAME")); - feature.setAttribute(resultSet.getObject("CONTENT")); + // feature.setAttribute(resultSet.getObject("CONTENT")); feature.setRuleValue(resultSet.getString("RULE")); - featureList.add(feature); + + profileFeature.setFeature(feature); + profileFeature.setId(resultSet.getInt("ID")); + profileFeature.setContent(resultSet.getObject("CONTENT")); + featureList.add(profileFeature); } } catch (SQLException e) { @@ -170,18 +309,24 @@ public class FeatureDAOImpl implements FeatureDAO { } @Override - public void deleteFeature(int featureId) throws FeatureManagerDAOException { + public boolean deleteFeature(int featureId) throws FeatureManagerDAOException { Connection conn = null; PreparedStatement stmt = null; - ResultSet generatedKeys = null; try { conn = this.getConnection(); - String query = ""; + String query = "DELETE FROM DM_FEATURES WHERE ID = ?"; stmt = conn.prepareStatement(query); + stmt.setInt(1, featureId); + stmt.executeUpdate(); + return true; } catch (SQLException e) { - + String msg = "Unable to delete the feature " + featureId + " (Feature ID) from database."; + log.error(msg); + throw new FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); } } 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 c28a5ca087..74a986e19e 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,31 +20,33 @@ 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.policy.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Profile; -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; +import org.wso2.carbon.policy.mgt.core.dao.*; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.ArrayList; import java.util.List; public class PolicyDAOImpl implements PolicyDAO { private static final Log log = LogFactory.getLog(PolicyDAOImpl.class); + DeviceDAOImpl deviceDAO = new DeviceDAOImpl(PolicyManagementDAOFactory.getDataSource()); + DeviceTypeDAO deviceTypeDAO = new DeviceTypeDAOImpl(PolicyManagementDAOFactory.getDataSource()); + ProfileDAO profileDAO = new ProfileDAOImpl(); @Override - public Policy addPolicy(Policy policy) throws PolicyManagerDAOException { - persistPolicy(policy); - return policy; + public Policy addPolicy(Policy policy) throws PolicyManagerDAOException { + return persistPolicy(policy); } @Override @@ -79,11 +81,34 @@ public class PolicyDAOImpl implements PolicyDAO { @Override public Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException { - return null; + // First persist the policy to the data base. + persistPolicy(policy); + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)"; + stmt = conn.prepareStatement(query); + stmt.setString(1, roleName); + stmt.setInt(2, policy.getId()); + + stmt.executeQuery(); + policy.getRoleList().add(roleName); + } catch (SQLException e) { + String msg = "Error occurred while adding the role name with policy to database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + return policy; } @Override - public Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { + public Policy addPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagerDAOException { // First persist the policy to the data base. persistPolicy(policy); @@ -92,11 +117,23 @@ public class PolicyDAOImpl implements PolicyDAO { PreparedStatement stmt = null; ResultSet generatedKeys = null; try { + Device device = deviceDAO.getDevice(deviceIdentifier); conn = this.getConnection(); - String query = ""; + String query = "INSERT INTO DM_DEVICE_POLICY (DEVICE_ID, POLICY_ID) VALUES (?, ?)"; stmt = conn.prepareStatement(query); - } catch (SQLException e) { + stmt.setInt(1, device.getId()); + stmt.setInt(2, policy.getId()); + stmt.executeUpdate(); + policy.getDeviceList().add(device); + } catch (SQLException e) { + String msg = "Error occurred while adding the device ids with policy to database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while reading the device data from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } @@ -112,10 +149,18 @@ public class PolicyDAOImpl implements PolicyDAO { ResultSet generatedKeys = null; try { conn = this.getConnection(); - String query = ""; + String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ? WHERE ID = ?"; stmt = conn.prepareStatement(query); - } catch (Exception e) { + stmt.setString(1, policy.getPolicyName()); + stmt.setInt(2, policy.getTenantId()); + stmt.setInt(3, policy.getProfile().getProfileId()); + stmt.setInt(4, policy.getId()); + stmt.executeUpdate(); + } catch (SQLException e) { + String msg = "Error occurred while updating policy " + policy.getPolicyName() + " (Policy Name) in database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } @@ -124,60 +169,430 @@ public class PolicyDAOImpl implements PolicyDAO { } @Override - public Policy getPolicy() throws PolicyManagerDAOException { + public Policy getPolicy(int policyId) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; - ResultSet generatedKeys = null; + ResultSet resultSet = null; + Policy policy = new Policy(); try { conn = this.getConnection(); - String query = ""; + String query = "SELECT * FROM DM_POLICY WHERE ID= ?"; stmt = conn.prepareStatement(query); - } catch (Exception e) { + stmt.setInt(1, policyId); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + + Profile profile = profileDAO.getProfiles(resultSet.getInt("PROFILE_ID")); + List deviceList = getPolicyAppliedDevices(policyId); + List roleNames = getPolicyAppliedRoles(policyId); + + policy.setId(policyId); + policy.setPolicyName(resultSet.getString("NAME")); + policy.setTenantId(resultSet.getInt("TENANT_ID")); + policy.setProfile(profile); + policy.setDeviceList(deviceList); + policy.setRoleList(roleNames); + setDatesOfPolicy(policy); + setTimesOfPolicy(policy); + setLocationsOfPolicy(policy); + } + + return policy; + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (ProfileManagerDAOException e) { + String msg = "Error occurred while getting the profiles."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); } finally { - PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + } + + + @Override + public Policy getPolicyByProfileID(int profileId) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + Policy policy = new Policy(); + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_POLICY WHERE PROFILE_ID= ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, profileId); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + + int policyId = resultSet.getInt("ID"); + Profile profile = profileDAO.getProfiles(profileId); + List deviceList = getPolicyAppliedDevices(policyId); + List roleNames = getPolicyAppliedRoles(policyId); + + policy.setId(policyId); + policy.setPolicyName(resultSet.getString("NAME")); + policy.setTenantId(resultSet.getInt("TENANT_ID")); + policy.setProfile(profile); + policy.setDeviceList(deviceList); + policy.setRoleList(roleNames); + + setDatesOfPolicy(policy); + setTimesOfPolicy(policy); + setLocationsOfPolicy(policy); + } + + return policy; + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (ProfileManagerDAOException e) { + String msg = "Error occurred while getting the profiles."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + } + + @Override + public List getPolicy() throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + List policies = new ArrayList(); + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_POLICY"; + stmt = conn.prepareStatement(query); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + Policy policy = new Policy(); + + int policyId = resultSet.getInt("ID"); + Profile profile = profileDAO.getProfiles(resultSet.getInt("PROFILE_ID")); + List deviceList = getPolicyAppliedDevices(policyId); + List roleNames = getPolicyAppliedRoles(policyId); + + policy.setId(policyId); + policy.setPolicyName(resultSet.getString("NAME")); + policy.setTenantId(resultSet.getInt("TENANT_ID")); + policy.setProfile(profile); + policy.setDeviceList(deviceList); + policy.setRoleList(roleNames); + + setDatesOfPolicy(policy); + setTimesOfPolicy(policy); + setLocationsOfPolicy(policy); + + policies.add(policy); + } + return policies; + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (ProfileManagerDAOException e) { + String msg = "Error occurred while getting the profiles."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + } + + @Override + public List getPolicy(String deviceTypeName) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + List policies = new ArrayList(); + try { + DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName); + + // This gives the profiles related to given device types. + List profileList = profileDAO.getProfilesOfDeviceType(deviceTypeName); + + for (Profile profile : profileList) { + policies.add(getPolicyByProfileID(profile.getProfileId())); + } + + /* conn = this.getConnection(); + + // TODO : Change the query for device type + String query = "SELECT dp.ID PID, dp.NAME PNAME, dp.TENANT_ID PTD, dp.PROFILE_ID PPID FROM DM_POLICY dp " + + "INNER JOIN DM_PROFILE dpr ON dpr.ID = dp.PROFILE_ID WHERE dpr.ID = ?"; + stmt = conn.prepareStatement(query); + + resultSet = stmt.executeQuery(); + + //ID NAME TENANT_ID PROFILE_ID + while (resultSet.next()) { + Policy policy = new Policy(); + + int policyId = resultSet.getInt("PID"); + Profile profile = profileDAO.getProfiles(resultSet.getInt("PID")); + List deviceList = getPolicyAppliedDevices(policyId); + List roleNames = getPolicyAppliedRoles(policyId); + + policy.setId(policyId); + policy.setPolicyName(resultSet.getString("PNAME")); + policy.setTenantId(resultSet.getInt("PTD")); + policy.setProfile(profile); + policy.setDeviceList(deviceList); + policy.setRoleList(roleNames); + + setDatesOfPolicy(policy); + setTimesOfPolicy(policy); + setLocationsOfPolicy(policy); + + policies.add(policy); + }*/ + + return policies; + /* } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e);*/ + } catch (ProfileManagerDAOException e) { + String msg = "Error occurred while getting the profiles."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while getting the device type."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + } + + // TODO : + private List getPolicyAppliedDevices(int policyId) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + List deviceList = new ArrayList(); + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policyId); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + deviceList.add(deviceDAO.getDevice(resultSet.getInt("DEVICE_ID"))); + } + return deviceList; + } catch (SQLException e) { + String msg = "Error occurred while getting the device related to policies."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while getting device data."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + } + + // TODO : + private List getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + List roleNames = new ArrayList(); + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_ROLE_POLICY WHERE POLICY_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policyId); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + roleNames.add(resultSet.getString("ROLE_NAME")); + } + + return roleNames; + } catch (SQLException e) { + String msg = "Error occurred while getting the roles related to policies."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + } + + // TODO : + private void setTimesOfPolicy(Policy policy) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + try { + conn = this.getConnection(); + String query = "SELECT STARTING_TIME, ENDING_TIME FROM DM_TIME WHERE POLICY_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policy.getId()); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + policy.setStartTime(resultSet.getInt("STARTING_TIME")); + policy.setEndTime(resultSet.getInt("ENDING_TIME")); + } + + } catch (SQLException e) { + String msg = "Error occurred while getting the start time and end time related to policies."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + } + + // TODO : + private void setDatesOfPolicy(Policy policy) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + try { + conn = this.getConnection(); + String query = "SELECT START_DATE, END_DATE FROM DM_DATE WHERE POLICY_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policy.getId()); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + policy.setStartDate(resultSet.getDate("START_DATE")); + policy.setEndDate(resultSet.getDate("END_DATE")); + } + + } catch (SQLException e) { + String msg = "Error occurred while getting the start date and end date related to policies."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); } + } + + // TODO: + private void setLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + try { + conn = this.getConnection(); + String query = "SELECT LAT, LONG FROM DM_LOCATION WHERE POLICY_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policy.getId()); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + policy.setLatitude(resultSet.getString("LAT")); + policy.setLongitude(resultSet.getString("LONG")); + } - return null; + } catch (SQLException e) { + String msg = "Error occurred while getting the start time and end time related to policies."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } } @Override - public Policy getPolicy(String deviceType) throws PolicyManagerDAOException { + public List getPolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; ResultSet generatedKeys = null; + List policies = new ArrayList(); try { conn = this.getConnection(); - String query = ""; + String query = "SELECT * FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ? "; stmt = conn.prepareStatement(query); - } catch (Exception e) { + stmt.setInt(1, deviceDAO.getDevice(deviceIdentifier).getId().intValue()); + + generatedKeys = stmt.executeQuery(); + while (generatedKeys.next()){ + policies.add(getPolicy(generatedKeys.getInt("POLICY_ID"))); + } + + return policies; + } catch (SQLException e) { + String msg = "Error occurred while reading the device policy table."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while getting device data from the device identifier."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } - return null; } @Override - public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException { + public List getPolicyOfRole(String roleName) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; ResultSet generatedKeys = null; + List policies = new ArrayList(); try { conn = this.getConnection(); - String query = ""; + String query = "SELECT * FROM DM_ROLE_POLICY WHERE ROLE_NAME = ? "; stmt = conn.prepareStatement(query); - } catch (Exception e) { + stmt.setString(1, roleName); + + generatedKeys = stmt.executeQuery(); + while (generatedKeys.next()){ + policies.add(getPolicy(generatedKeys.getInt("POLICY_ID"))); + } + + return policies; + } catch (SQLException e) { + String msg = "Error occurred while reading the role policy table."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } - - return null; } @Override @@ -196,7 +611,7 @@ public class PolicyDAOImpl implements PolicyDAO { if (log.isDebugEnabled()) { log.debug("Policy (" + policy.getPolicyName() + ") delete from database."); } - } catch (Exception e) { + } catch (SQLException e) { String msg = "Unable to delete the policy (" + policy.getPolicyName() + ") from database."; log.error(msg); throw new PolicyManagerDAOException(msg, e); @@ -216,7 +631,7 @@ public class PolicyDAOImpl implements PolicyDAO { } - private void persistPolicy(Policy policy) throws PolicyManagerDAOException { + private Policy persistPolicy(Policy policy) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -248,22 +663,24 @@ public class PolicyDAOImpl implements PolicyDAO { if (policy.getId() == 0) { throw new RuntimeException("No rows were inserted, policy id cannot be null."); } + + profileDAO.addProfile(policy.getProfile()); + + return policy; } catch (SQLException e) { String msg = "Error occurred while adding policy to the database."; log.error(msg, e); throw new PolicyManagerDAOException(msg, e); + } catch (ProfileManagerDAOException e) { + String msg = "Error occurred while adding profile to the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } } - - - - - - /** * This method returns the device type id when supplied with device type name. * diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java index 0c09c36eb9..36ac7a4b73 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java @@ -20,29 +20,37 @@ 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.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.dao.*; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class ProfileDAOImpl implements ProfileDAO { private static final Log log = LogFactory.getLog(ProfileDAOImpl.class); - + FeatureDAOImpl featureDAO = new FeatureDAOImpl(); + DeviceTypeDAO deviceTypeDAO = new DeviceTypeDAOImpl(PolicyManagementDAOFactory.getDataSource()); public Profile addProfile(Profile profile) throws ProfileManagerDAOException { + Connection conn = null; PreparedStatement stmt = null; ResultSet generatedKeys = null; - // TODO : find a way to get the tenant Id. - int tenantId = -1234; + int tenantId = MultitenantConstants.SUPER_TENANT_ID; try { conn = this.getConnection(); String query = "INSERT INTO DM_PROFILE (PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?)"; @@ -70,12 +78,17 @@ public class ProfileDAOImpl implements ProfileDAO { throw new RuntimeException("Profile id is 0, this could be an issue."); } - persistFeatures(profile); + featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId()); + // persistFeatures(profile); } catch (SQLException e) { String msg = "Error occurred while adding the profile to database."; log.error(msg, e); throw new ProfileManagerDAOException(msg, e); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred while adding the features to database."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } @@ -85,6 +98,56 @@ public class ProfileDAOImpl implements ProfileDAO { public Profile updateProfile(Profile profile) throws ProfileManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + int tenantId = MultitenantConstants.SUPER_TENANT_ID; + try { + conn = this.getConnection(); + String query = "UPDATE DM_PROFILE SET PROFILE_NAME = ? ,TENANT_ID = ?, DEVICE_TYPE_ID = ? , UPDATED_TIME = ? " + + "WHERE ID = ?"; + stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + + stmt.setString(1, profile.getProfileName()); + stmt.setInt(2, tenantId); + stmt.setLong(3, profile.getDeviceType().getId()); + stmt.setTimestamp(4, profile.getUpdatedDate()); + stmt.setInt(5, profile.getProfileId()); + + int affectedRows = stmt.executeUpdate(); + + if (affectedRows == 0 && log.isDebugEnabled()) { + String msg = "No rows are updated on the profile table."; + log.debug(msg); + } + generatedKeys = stmt.getGeneratedKeys(); + + if (generatedKeys.next()) { + profile.setProfileId(generatedKeys.getInt(1)); + } + // Checking the profile id here, because profile id could have been passed from the calling method. + if (profile.getProfileId() == 0) { + throw new RuntimeException("Profile id is 0, this could be an issue."); + } + + // TODO : Check to update the features. + featureDAO.updateProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId()); + //persistFeatures(profile); + + } catch (SQLException e) { + String msg = "Error occurred while updating the profile ("+profile.getProfileName()+") in database."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred while updating the profile in database."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return profile; } @@ -92,7 +155,7 @@ public class ProfileDAOImpl implements ProfileDAO { public void deleteProfile(Profile profile) throws ProfileManagerDAOException { // First delete the features related to the profile - FeatureDAOImpl featureDAO = new FeatureDAOImpl(); + try { featureDAO.deleteFeaturesOfProfile(profile); } catch (FeatureManagerDAOException e) { @@ -101,7 +164,6 @@ public class ProfileDAOImpl implements ProfileDAO { throw new ProfileManagerDAOException(msg, e); } - Connection conn = null; PreparedStatement stmt = null; @@ -120,7 +182,54 @@ public class ProfileDAOImpl implements ProfileDAO { } } + @Override + public Profile getProfiles(int profileId) throws ProfileManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + Profile profile = new Profile(); + try { + List featureList = featureDAO.getFeaturesForProfile(profileId); + conn = this.getConnection(); + String query = "SELECT * FROM DM_PROFILE WHERE ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, profileId); + + resultSet = stmt.executeQuery(); + + //ID PROFILE_NAME TENANT_ID DEVICE_TYPE_ID CREATED_TIME UPDATED_TIME + while (resultSet.next()) { + profile.setProfileFeaturesList(featureList); + profile.setProfileId(profileId); + profile.setProfileName(resultSet.getString("PROFILE_NAME")); + profile.setTenantId(resultSet.getInt("TENANT_ID")); + profile.setDeviceType(deviceTypeDAO.getDeviceType(resultSet.getInt("DEVICE_TYPE_ID"))); + profile.setCreatedDate(resultSet.getTimestamp("CREATED_TIME")); + profile.setUpdatedDate(resultSet.getTimestamp("UPDATED_TIME")); + } + return profile; + } catch (SQLException e) { + String msg = "Error occurred while reading the profile from the database."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred when getting the device type name by device type id."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred when getting the features related to a profile."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + } + private void persistFeatures(Profile profile) throws ProfileManagerDAOException { + Connection conn = null; PreparedStatement stmt = null; try { @@ -128,10 +237,10 @@ public class ProfileDAOImpl implements ProfileDAO { String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_ID, CONTENT) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(query); - for (Feature feature : profile.getFeaturesList()) { + for (ProfileFeature feature : profile.getProfileFeaturesList()) { stmt.setInt(1, profile.getProfileId()); stmt.setInt(2, feature.getId()); - stmt.setObject(3, feature.getAttribute()); + stmt.setObject(3, feature.getContent()); stmt.addBatch(); //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000 } @@ -148,38 +257,95 @@ public class ProfileDAOImpl implements ProfileDAO { @Override public List getAllProfiles() throws ProfileManagerDAOException { + Connection conn = null; PreparedStatement stmt = null; - ResultSet generatedKeys = null; - + ResultSet resultSet = null; + List profileList = new ArrayList(); try { conn = this.getConnection(); - String query = ""; + String query = "SELECT * FROM DM_PROFILE"; stmt = conn.prepareStatement(query); - } catch (SQLException e) { + resultSet = stmt.executeQuery(); + + //ID PROFILE_NAME TENANT_ID DEVICE_TYPE_ID CREATED_TIME UPDATED_TIME + while (resultSet.next()) { + Profile profile = new Profile(); + int profileId = resultSet.getInt("ID"); + List featureList = featureDAO.getFeaturesForProfile(profileId); + profile.setProfileFeaturesList(featureList); + profile.setProfileId(profileId); + profile.setProfileName(resultSet.getString("PROFILE_NAME")); + profile.setTenantId(resultSet.getInt("TENANT_ID")); + profile.setDeviceType(deviceTypeDAO.getDeviceType(resultSet.getInt("DEVICE_TYPE_ID"))); + profile.setCreatedDate(resultSet.getTimestamp("CREATED_TIME")); + profile.setUpdatedDate(resultSet.getTimestamp("UPDATED_TIME")); + + profileList.add(profile); + } + return profileList; + } catch (SQLException e) { + String msg = "Error occurred while reading the profile list from the database."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while getting the device type."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred while getting the features related to a profile."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); } - - return null; } @Override - public List getProfilesOfDeviceType(String deviceType) throws ProfileManagerDAOException { - + public List getProfilesOfDeviceType(String deviceTypeName) throws ProfileManagerDAOException { Connection conn = null; PreparedStatement stmt = null; - ResultSet generatedKeys = null; - + ResultSet resultSet = null; + List profileList = new ArrayList(); try { + DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName); conn = this.getConnection(); - String query = ""; + String query = "SELECT * FROM DM_PROFILE WHERE DEVICE_TYPE_ID = ?"; stmt = conn.prepareStatement(query); + stmt.setInt(1, deviceType.getId()); + + resultSet = stmt.executeQuery(); + + //ID PROFILE_NAME TENANT_ID DEVICE_TYPE_ID CREATED_TIME UPDATED_TIME + while (resultSet.next()) { + Profile profile = new Profile(); + int profileId = resultSet.getInt("ID"); + List featureList = featureDAO.getFeaturesForProfile(profileId); + profile.setProfileFeaturesList(featureList); + profile.setProfileId(profileId); + profile.setProfileName(resultSet.getString("PROFILE_NAME")); + profile.setTenantId(resultSet.getInt("TENANT_ID")); + profile.setDeviceType(deviceType); + profile.setCreatedDate(resultSet.getTimestamp("CREATED_TIME")); + profile.setUpdatedDate(resultSet.getTimestamp("UPDATED_TIME")); + + profileList.add(profile); + } + return profileList; } catch (SQLException e) { - + String msg = "Error occurred while reading the profile list from the database."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while getting the device type."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred while getting the features related to a profile."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); } - return null; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index c21bf86d69..961a4b6365 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.policy.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.Policy; @@ -33,6 +34,8 @@ import org.wso2.carbon.policy.mgt.core.dao.impl.FeatureDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl; +import java.util.List; + public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class); @@ -71,11 +74,11 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { } @Override - public Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) + public Policy addPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws FeatureManagementException, PolicyManagementException { try { - policy = policyDAO.addPolicy(deviceId, deviceType, policy); + policy = policyDAO.addPolicyToDevice(deviceIdentifier, policy); } catch (PolicyManagerDAOException e) { String msg = "Error occurred while persisting the policy."; log.error(msg, e); @@ -98,39 +101,57 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { } @Override - public Policy getPolicy() { - return null; + public List getPolicies() throws PolicyManagementException { + try { + return policyDAO.getPolicy(); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while getting the policies."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } } @Override - public Policy getPolicyOfDevice(String deviceId, String deviceType) + public List getPoliciesOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException { return null; } @Override - public Policy getPolicyOfDeviceType(String deviceType) + public List getPoliciesOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException { - return null; + try { + return policyDAO.getPolicy(deviceType); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while getting the policy related to device type."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } } @Override - public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { - return null; + public List getPoliciesOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { + try { + return policyDAO.getPolicyOfRole(roleName); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while getting the policy related to role name."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } } @Override - public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException { + public boolean isPolicyAvailableForDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { return false; } @Override - public boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException { + public boolean isPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { return false; } @Override - public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException { + public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException { } @@ -192,6 +213,12 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public void deleteFeature(int featureId) throws FeatureManagementException { - + try { + featureDAO.deleteFeature(featureId); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred while deleting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java index 4bec7d6980..905c096962 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java @@ -20,48 +20,124 @@ package org.wso2.carbon.policy.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.policy.mgt.core.dao.*; +import org.wso2.carbon.policy.mgt.core.dao.impl.FeatureDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; +import org.wso2.carbon.user.api.UserStoreException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class PolicyInformationPointImpl implements PolicyInformationPoint { private static final Log log = LogFactory.getLog(PolicyInformationPointImpl.class); - DeviceDAOImpl deviceDAO; + DeviceDAOImpl deviceDAO = new DeviceDAOImpl(PolicyManagementDAOFactory.getDataSource()); + DeviceTypeDAO deviceTypeDAO = new DeviceTypeDAOImpl(PolicyManagementDAOFactory.getDataSource()); + FeatureDAO featureDAO = new FeatureDAOImpl(); + PolicyDAO policyDAO = new PolicyDAOImpl(); public PolicyInformationPointImpl() { deviceDAO = new DeviceDAOImpl(DeviceManagementDAOFactory.getDataSource()); } @Override - public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { - PIPDeviceData pipDeviceData = new PIPDeviceData(); + public PIPDevice getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + PIPDevice pipDevice = new PIPDevice(); Device device; try { device = deviceDAO.getDevice(deviceIdentifier); - pipDeviceData.setDevice(device); + DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceIdentifier.getType()); + pipDevice.setDevice(device); + pipDevice.setRoles(getRoleOfDevice(device)); + pipDevice.setDeviceType(deviceType); + pipDevice.setDeviceIdentifier(deviceIdentifier); + // TODO : Find a way to retrieve the timestamp and location (lat, long) of the device + // pipDevice.setLongitude(); + // pipDevice.setAltitude(); + // pipDevice.setTimestamp(); } catch (DeviceManagementDAOException e) { String msg = "Error occurred when retrieving the data related to device from the database."; log.error(msg, e); throw new PolicyManagementException(msg, e); } - return pipDeviceData; + return pipDevice; } @Override - public List getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException { - return null; + public List getRelatedPolicies(PIPDevice pipDevice) throws PolicyManagementException { + + List> policies = new ArrayList>(); + try { + // Get the device type related policies + policies.add(policyDAO.getPolicy(pipDevice.getDeviceType().getName())); + + // Get the roles related policies + for (String role : pipDevice.getRoles()) { + policies.add(policyDAO.getPolicyOfRole(role)); + } + // Get policy related to the device + policies.add(policyDAO.getPolicy(pipDevice.getDeviceIdentifier())); + + return removeDuplicatePolicies(policies); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred when retrieving related to given device " + + pipDevice.getDeviceIdentifier().getId() + " " + pipDevice.getDeviceIdentifier().getType() + "."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } } @Override public List getRelatedFeatures(String deviceType) throws FeatureManagementException { - return null; + try { + return featureDAO.getAllFeatures(deviceType); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred when retrieving features related to device type."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } } + + private String[] getRoleOfDevice(Device device) throws PolicyManagementException { + try { + return CarbonContext.getThreadLocalCarbonContext().getUserRealm(). + getUserStoreManager().getRoleListOfUser(device.getOwnerId()); + } catch (UserStoreException e) { + String msg = "Error occurred when retrieving roles related to user name."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + } + + + private List removeDuplicatePolicies(List> policies) { + + Map map = new HashMap(); + List finalPolicies = new ArrayList(); + for (List policyList : policies) { + for (Policy policy : policyList) { + if (!map.containsKey(policy.getId())) { + map.put(policy.getId(), policy); + finalPolicies.add(policy); + } + } + } + + return finalPolicies; + } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java index 4154c2bc84..d670d9a779 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java @@ -84,4 +84,14 @@ public class PolicyManagementService implements PolicyManager { public List getFeatures() throws FeatureManagementException { return policyManager.getFeatures(); } + + @Override + public PolicyAdministratorPoint getPAP() throws PolicyManagementException { + return policyManager.getPAP(); + } + + @Override + public PolicyInformationPoint getPIP() throws PolicyManagementException { + return policyManager.getPIP(); + } } 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 554847059b..cca3f4321a 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 @@ -241,6 +241,24 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` ( ENGINE = InnoDB; +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DATE` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_DATE` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DATE` ( + `START_DATE` DATE NOT NULL , + `END_DATE` DATE NOT NULL , + `POLICY_ID` INT NOT NULL , + INDEX `DM_DATE_POLICY` (`POLICY_ID` ASC) , + CONSTRAINT `DM_DATE_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 21e3888e80..b66d5e143f 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 @@ -20,7 +20,6 @@ package org.wso2.carbon.simple.policy.decision.point; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; 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 f1d076d0fd..8e4a55ab9d 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 @@ -19,13 +19,13 @@ package org.wso2.carbon.simple.policy.decision.point; -import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.PIPDevice; import org.wso2.carbon.policy.mgt.common.Policy; public interface SimpleEvaluation { void sortPolicy(Policy policy) throws PolicyEvaluationException; - Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException; + Policy getEffectivePolicy(PIPDevice pipDevice) 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 95f902a985..f1697fc4ec 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 @@ -20,7 +20,7 @@ package org.wso2.carbon.simple.policy.decision.point; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.PIPDevice; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; @@ -41,7 +41,7 @@ public class SimpleEvaluationImpl implements SimpleEvaluation { } @Override - public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException { + public Policy getEffectivePolicy(PIPDevice pipDevice) throws PolicyEvaluationException { return null; } }