From 73b185e1e6b55f0dabbbe71285ef364c22b440d3 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Tue, 12 May 2015 16:20:18 +0530 Subject: [PATCH] Removing feature implementation from the policy, adding criteria based policy --- .../carbon/device/mgt/common/Feature.java | 3 +- .../policy/evaluator/FeatureFilter.java | 2 - .../policy/evaluator/FeatureFilterImpl.java | 105 +++++----- .../policy/evaluator/PolicyFilterImpl.java | 2 +- .../point/PolicyInformationServiceImpl.java | 2 +- .../carbon/policy/mgt/common/Criterion.java | 42 ++++ .../carbon/policy/mgt/common/Feature.java | 126 ++++++------ .../wso2/carbon/policy/mgt/common/Policy.java | 32 ++- .../mgt/common/PolicyAdministratorPoint.java | 2 +- .../policy/mgt/common/PolicyCriteria.java | 63 ++++++ .../mgt/common/PolicyInformationPoint.java | 1 + .../policy/mgt/common/ProfileFeature.java | 29 ++- .../mgt/common/utils/PolicyCreator.java | 3 +- .../policy/mgt/core/PolicyManagerService.java | 10 +- .../mgt/core/PolicyManagerServiceImpl.java | 11 +- .../policy/mgt/core/dao/FeatureDAO.java | 3 +- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 19 +- .../mgt/core/dao/dto/PolicyCriteriaDTO.java | 26 +++ .../mgt/core/dao/impl/FeatureDAOImpl.java | 134 ++++++------ .../mgt/core/dao/impl/PolicyDAOImpl.java | 190 +++++++++++++++++- .../impl/PolicyAdministratorPointImpl.java | 8 +- .../core/impl/PolicyInformationPointImpl.java | 7 +- .../policy/mgt/core/mgt/FeatureManager.java | 3 +- .../mgt/core/mgt/impl/FeatureManagerImpl.java | 10 +- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 47 +++-- .../core/service/PolicyManagementService.java | 10 +- .../policy/mgt/core/PolicyDAOTestCase.java | 4 +- .../policy/mgt/core/util/FeatureCreator.java | 57 +++--- .../policy/mgt/core/util/PolicyCreator.java | 7 +- .../policy/mgt/core/util/ProfileCreator.java | 2 +- .../mgt/core/util/ProfileFeatureCreator.java | 7 +- .../src/test/resources/sql/CreateH2TestDB.sql | 41 +--- .../src/main/resources/dbscripts/cdm/h2.sql | 130 +++++++++++- 33 files changed, 826 insertions(+), 312 deletions(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Criterion.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyCriteria.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/dto/PolicyCriteriaDTO.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index 050dff0bcba..ca13da6a9bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -17,9 +17,10 @@ */ package org.wso2.carbon.device.mgt.common; +import java.io.Serializable; import java.util.List; -public class Feature { +public class Feature implements Serializable{ private int id; private String code; 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 b43d1b627de..2144b60cd6a 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 @@ -19,12 +19,10 @@ 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 { 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 142ab341e14..0e4723e23fa 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 @@ -19,7 +19,6 @@ 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; @@ -103,17 +102,17 @@ public class FeatureFilterImpl implements FeatureFilter { */ 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; - } else { - evaluatedFeature = feature; - } - } - } +// for (ProfileFeature feature : featureList) { +// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { +// if (feature.getFeature().getRuleValue().equalsIgnoreCase("Deny")) { +// evaluatedFeature = feature; +// effectiveFeatureList.add(evaluatedFeature); +// return; +// } else { +// evaluatedFeature = feature; +// } +// } +// } if (evaluatedFeature != null) { effectiveFeatureList.add(evaluatedFeature); } @@ -130,17 +129,17 @@ public class FeatureFilterImpl implements FeatureFilter { */ 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; - } else { - evaluatedFeature = feature; - } - } - } +// for (ProfileFeature feature : featureList) { +// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { +// if (feature.getFeature().getRuleValue().equalsIgnoreCase("Permit")) { +// evaluatedFeature = feature; +// effectiveFeatureList.add(evaluatedFeature); +// return; +// } else { +// evaluatedFeature = feature; +// } +// } +// } if (evaluatedFeature != null) { effectiveFeatureList.add(evaluatedFeature); } @@ -157,11 +156,11 @@ public class FeatureFilterImpl implements FeatureFilter { */ public void getFirstApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { for (ProfileFeature feature : featureList) { - if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { - effectiveFeatureList.add(feature); - return; - - } +// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { +// effectiveFeatureList.add(feature); +// return; +// +// } } } @@ -175,11 +174,11 @@ public class FeatureFilterImpl implements FeatureFilter { */ public void getLastApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { ProfileFeature evaluatedFeature = null; - for (ProfileFeature feature : featureList) { - if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { - evaluatedFeature = feature; - } - } +// for (ProfileFeature feature : featureList) { +// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { +// evaluatedFeature = feature; +// } +// } if (evaluatedFeature != null) { effectiveFeatureList.add(evaluatedFeature); } @@ -195,9 +194,9 @@ public class FeatureFilterImpl implements FeatureFilter { */ public void getAllApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { for (ProfileFeature feature : featureList) { - if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { - effectiveFeatureList.add(feature); - } +// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) { +// effectiveFeatureList.add(feature); +// } } } @@ -212,14 +211,14 @@ public class FeatureFilterImpl implements FeatureFilter { public void getHighestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { ProfileFeature evaluatedFeature = null; int intValve = 0; - 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; - } - } - } +// 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; +// } +// } +// } if (evaluatedFeature != null) { effectiveFeatureList.add(evaluatedFeature); } @@ -235,15 +234,15 @@ public class FeatureFilterImpl implements FeatureFilter { */ public void getLowestApplicableFeatures(String featureName, List featureList, List effectiveFeatureList) { ProfileFeature evaluatedFeature = null; - int intValve = 0; - 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; - } - } - } +// int intValve = 0; +// 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; +// } +// } +// } if (evaluatedFeature != null) { effectiveFeatureList.add(evaluatedFeature); } diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java index 22af2787412..a4bc89bfe7d 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java @@ -39,7 +39,7 @@ public class PolicyFilterImpl implements PolicyFilter { List policies = new ArrayList(); for (Policy policy : policyList) { - List roleList = policy.getRoleList(); + List roleList = policy.getRoles(); for (String role : roleList) { if (roles.contains(role)) { 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 7ced5c7839e..788acdcdd8d 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 @@ -19,7 +19,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.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.PIPDevice; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Criterion.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Criterion.java new file mode 100644 index 00000000000..59d7a7065da --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Criterion.java @@ -0,0 +1,42 @@ +/* + * 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 Criterion { + + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} 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 90c1aae45a9..a1b2563d272 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 @@ -22,67 +22,67 @@ import java.io.Serializable; public class Feature implements Serializable { - private int id; - private String code; - private String name; - private String description; - // private Object attribute; - private String ruleValue; - private int deviceTypeId; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getRuleValue() { - return ruleValue; - } - - public void setRuleValue(String ruleValue) { - this.ruleValue = ruleValue; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - -/* 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; - } +// private int id; +// private String code; +// private String name; +// private String description; +// // private Object attribute; +// private String ruleValue; +// private int deviceTypeId; +// +// public String getDescription() { +// return description; +// } +// +// public void setDescription(String description) { +// this.description = description; +// } +// +// public String getRuleValue() { +// return ruleValue; +// } +// +// public void setRuleValue(String ruleValue) { +// this.ruleValue = ruleValue; +// } +// +// public int getId() { +// return id; +// } +// +// public void setId(int id) { +// this.id = id; +// } +// +// public String getCode() { +// return code; +// } +// +// public void setCode(String code) { +// this.code = code; +// } +// +// public String getName() { +// return name; +// } +// +// public void setName(String name) { +// this.name = name; +// } +// +///* 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/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index 714bceecaba..e23356acfba 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 @@ -36,13 +36,17 @@ public class Policy implements Comparable, Serializable { private Profile profile; // Profile private String policyName; // Name of the 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 List roles; // 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 devices; // Individual devices this policy should be applied private List users; /*Dynamic policy attributes*/ + /* This is related criteria based policy */ + + private List policyCriterias; + /*These are related to time based policies*/ private int startTime; // Start time to apply the policy. @@ -111,12 +115,12 @@ public class Policy implements Comparable, Serializable { this.generic = generic; } - public List getRoleList() { - return roleList; + public List getRoles() { + return roles; } - public void setRoleList(List roleList) { - this.roleList = roleList; + public void setRoles(List roles) { + this.roles = roles; } public String getOwnershipType() { @@ -127,12 +131,12 @@ public class Policy implements Comparable, Serializable { this.ownershipType = ownershipType; } - public List getDeviceList() { - return DeviceList; + public List getDevices() { + return devices; } - public void setDeviceList(List deviceList) { - DeviceList = deviceList; + public void setDevices(List devices) { + this.devices = devices; } public List getUsers() { @@ -143,6 +147,14 @@ public class Policy implements Comparable, Serializable { this.users = users; } + public List getPolicyCriterias() { + return policyCriterias; + } + + public void setPolicyCriterias(List policyCriterias) { + this.policyCriterias = policyCriterias; + } + public int getStartTime() { return startTime; } 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 da9ca06add7..27ab4eb547b 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 @@ -17,7 +17,7 @@ */ package org.wso2.carbon.policy.mgt.common; - +import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.util.List; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyCriteria.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyCriteria.java new file mode 100644 index 00000000000..bb474258e75 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyCriteria.java @@ -0,0 +1,63 @@ +/* + * 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; + +import java.util.Map; +import java.util.Properties; + +public class PolicyCriteria { + + private int id; + private String name; + private Properties properties; + private Map objectMap; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + public Map getObjectMap() { + return objectMap; + } + + public void setObjectMap(Map objectMap) { + this.objectMap = objectMap; + } +} 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 af81c68a276..5d74dc5663a 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,6 +20,7 @@ package org.wso2.carbon.policy.mgt.common; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.Feature; import java.util.List; 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 index 6c9f8498af6..6a8e582c207 100644 --- 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 @@ -19,12 +19,15 @@ package org.wso2.carbon.policy.mgt.common; import java.io.Serializable; +import org.wso2.carbon.device.mgt.common.Feature; public class ProfileFeature implements Serializable { private int id; - private Feature feature; + private String featureCode; +// private Feature feature; private int profileId; + private int deviceTypeId; private Object content; public int getId() { @@ -35,14 +38,22 @@ public class ProfileFeature implements Serializable { this.id = id; } - public Feature getFeature() { - return feature; + public String getFeatureCode() { + return featureCode; } - public void setFeature(Feature feature) { - this.feature = feature; + public void setFeatureCode(String featureCode) { + this.featureCode = featureCode; } +// public Feature getFeature() { +// return feature; +// } +// +// public void setFeature(Feature feature) { +// this.feature = feature; +// } + public int getProfileId() { return profileId; } @@ -51,6 +62,14 @@ public class ProfileFeature implements Serializable { this.profileId = profileId; } + public int getDeviceTypeId() { + return deviceTypeId; + } + + public void setDeviceTypeId(int deviceTypeId) { + this.deviceTypeId = deviceTypeId; + } + public Object getContent() { return 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 12ae84564df..00fc404ae3e 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 @@ -18,7 +18,8 @@ package org.wos2.carbon.policy.mgt.common.utils; -import org.wso2.carbon.policy.mgt.common.Feature; + +import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Profile; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index c4c5c7f0eb2..2cc06c00731 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -20,7 +20,15 @@ package org.wso2.carbon.policy.mgt.core; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.device.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.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import java.util.List; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index f1e67cd26a2..522e00eee7b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -21,7 +21,16 @@ package org.wso2.carbon.policy.mgt.core; 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.*; +import org.wso2.carbon.device.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.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl; import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; 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 79a0e4f8268..080dcc39211 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 @@ -19,8 +19,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.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Profile; import org.wso2.carbon.policy.mgt.common.ProfileFeature; 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 604f201543d..7ae2371c373 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,7 +18,6 @@ package org.wso2.carbon.policy.mgt.core.dao; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.policy.mgt.common.*; @@ -43,6 +42,24 @@ public interface PolicyDAO { Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws PolicyManagerDAOException; + Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException; + + Criterion updateCriterion(Criterion criteria) throws PolicyManagerDAOException; + + Criterion getCriterion(int id) throws PolicyManagerDAOException; + + Criterion getCriterion(String name) throws PolicyManagerDAOException; + + boolean checkCriterionExists(String name) throws PolicyManagerDAOException; + + boolean deleteCriterion(Criterion criteria) throws PolicyManagerDAOException; + + List getAllPolicyCriteria() throws PolicyManagerDAOException; + + Policy addPolicyCriteria(Policy policy) throws PolicyManagerDAOException; + + List getPolicyCriteria(int policyId) throws PolicyManagerDAOException; + Policy updatePolicy(Policy policy) throws PolicyManagerDAOException; Policy getPolicy(int policyId) throws PolicyManagerDAOException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/dto/PolicyCriteriaDTO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/dto/PolicyCriteriaDTO.java new file mode 100644 index 00000000000..d2b8c3e9807 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/dto/PolicyCriteriaDTO.java @@ -0,0 +1,26 @@ +/* + * 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.core.dao.dto; + +public class PolicyCriteriaDTO { + + private int id; + private String name; +} 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 59485bd155f..59b25ac507a 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 @@ -20,7 +20,8 @@ package org.wso2.carbon.policy.mgt.core.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.policy.mgt.common.Feature; + +import org.wso2.carbon.device.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.FeatureDAO; @@ -50,13 +51,13 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)"; + String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, feature.getName()); stmt.setString(2, feature.getCode()); stmt.setString(3, feature.getDescription()); - stmt.setString(4, feature.getRuleValue()); - stmt.setInt(5, feature.getDeviceTypeId()); +// stmt.setString(4, feature.getRuleValue()); +// stmt.setInt(5, feature.getDeviceTypeId()); int affectedRows = stmt.executeUpdate(); if (log.isDebugEnabled()) { @@ -88,15 +89,15 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)"; + String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); for (Feature feature : features) { stmt.setString(1, feature.getName()); stmt.setString(2, feature.getCode()); stmt.setString(3, feature.getDescription()); - stmt.setString(4, feature.getRuleValue()); - stmt.setInt(5, feature.getDeviceTypeId()); +// stmt.setString(4, feature.getRuleValue()); +// stmt.setInt(5, feature.getDeviceTypeId()); stmt.addBatch(); } @@ -133,13 +134,13 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ?, EVALUATION_RULE = ? WHERE ID = ?"; + String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ? 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.setString(4, feature.getRuleValue()); + stmt.setInt(4, feature.getId()); stmt.executeUpdate(); } catch (SQLException e) { @@ -172,13 +173,15 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_ID, CONTENT) VALUES (?, ?, ?)"; + String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT) " + + "VALUES (?, ?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); for (ProfileFeature feature : features) { stmt.setInt(1, profileId); - stmt.setInt(2, feature.getFeature().getId()); - stmt.setObject(3, feature.getContent()); + stmt.setString(2, feature.getFeatureCode()); + stmt.setInt(3, feature.getDeviceTypeId()); + stmt.setObject(4, 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 } @@ -210,13 +213,13 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ? , FEATURE_ID = ? "; + String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ?, FEATURE_CODE = ?"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); for (ProfileFeature feature : features) { stmt.setObject(1, feature.getContent()); stmt.setInt(2, profileId); - stmt.setInt(3, feature.getFeature().getId()); + stmt.setString(3, feature.getFeatureCode()); stmt.addBatch(); //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000 } @@ -259,36 +262,36 @@ public class FeatureDAOImpl implements FeatureDAO { @Override public List getAllFeatures() throws FeatureManagerDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet resultSet = null; +// Connection conn; +// PreparedStatement stmt = null; +// ResultSet resultSet = null; List featureList = new ArrayList(); - - try { - conn = this.getConnection(); - String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUATION_RULE FROM DM_FEATURES"; - stmt = conn.prepareStatement(query); - 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("EVALUATION_RULE")); - featureList.add(feature); - } - - } catch (SQLException e) { - String msg = "Unable to get the list of the features from database."; - log.error(msg); - throw new FeatureManagerDAOException(msg, e); - } finally { - PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); - this.closeConnection(); - } +// +// try { +// conn = this.getConnection(); +// String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUATION_RULE FROM DM_FEATURES"; +// stmt = conn.prepareStatement(query); +// 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("EVALUATION_RULE")); +// featureList.add(feature); +// } +// +// } catch (SQLException e) { +// String msg = "Unable to get the list of the features from database."; +// log.error(msg); +// throw new FeatureManagerDAOException(msg, e); +// } finally { +// PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); +// this.closeConnection(); +// } return featureList; } @@ -302,22 +305,22 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " + - "F.EVALUATION_RULE RULE, PF.CONTENT AS CONTENT, PF.PROFILE_ID PROFILE_ID FROM DM_PROFILE_FEATURES AS PF " + - "JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID"; + String query = "SELECT ID, PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES"; stmt = conn.prepareStatement(query); 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.setRuleValue(resultSet.getString("RULE")); - - profileFeature.setFeature(feature); +// Feature feature = new Feature(); +// feature.setId(resultSet.getInt("FEATURE_ID")); +// feature.setCode(resultSet.getString("CODE")); +// feature.setName(resultSet.getString("NAME")); +// feature.setRuleValue(resultSet.getString("RULE")); + +// profileFeature.setFeature(feature); + profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE")); + profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); profileFeature.setId(resultSet.getInt("ID")); profileFeature.setContent(resultSet.getObject("CONTENT")); profileFeature.setProfileId(resultSet.getInt("PROFILE_ID")); @@ -358,8 +361,8 @@ 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("EVALUATION_RULE")); +// feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); +// feature.setRuleValue(resultSet.getString("EVALUATION_RULE")); featureList.add(feature); } @@ -384,23 +387,24 @@ public class FeatureDAOImpl implements FeatureDAO { try { conn = this.getConnection(); - String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " + - "F.EVALUATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " + - "JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?"; + String query = "SELECT ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES " + + "WHERE PROFILE_ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, profileId); 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.setRuleValue(resultSet.getString("RULE")); +// Feature feature = new Feature(); +// feature.setId(resultSet.getInt("FEATURE_ID")); +// feature.setCode(resultSet.getString("CODE")); +// feature.setName(resultSet.getString("NAME")); +// feature.setRuleValue(resultSet.getString("RULE")); - profileFeature.setFeature(feature); +// profileFeature.setFeature(feature); profileFeature.setId(resultSet.getInt("ID")); + profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE")); + profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); profileFeature.setContent(resultSet.getObject("CONTENT")); featureList.add(profileFeature); } 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 a475279e99f..27edad84f50 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 @@ -202,7 +202,7 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "INSERT INTO DM_LOCATION (LATITUDE, LONGITUDE, POLICY_ID) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(query); + stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, latitude); stmt.setString(2, longitude); stmt.setInt(3, policy.getId()); @@ -219,12 +219,196 @@ public class PolicyDAOImpl implements PolicyDAO { return policy; } + @Override + public Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + ResultSet generatedKeys; + + int tenantId = PolicyManagerUtil.getTenantId(); + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, tenantId); + stmt.setString(2, criteria.getName()); + stmt.executeUpdate(); + + generatedKeys = stmt.getGeneratedKeys(); + + while (generatedKeys.next()) { + criteria.setId(generatedKeys.getInt(1)); + } + + } catch (SQLException e) { + String msg = "Error occurred while inserting the criterion (" + criteria.getName() + ") to database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } + return criteria; + } + + @Override + public Criterion updateCriterion(Criterion criteria) throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + int tenantId = PolicyManagerUtil.getTenantId(); + try { + conn = this.getConnection(); + String query = "UPDATE DM_CRITERIA SET TENANT_ID = ?, NAME = ? WHERE ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, tenantId); + stmt.setString(2, criteria.getName()); + stmt.setInt(3, criteria.getId()); + stmt.executeUpdate(); + + } catch (SQLException e) { + String msg = "Error occurred while inserting the criterion (" + criteria.getName() + ") to database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } + return criteria; + } + + @Override + public Criterion getCriterion(int id) throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + Criterion criterion = new Criterion(); + + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_CRITERIA WHERE ID= ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, id); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + criterion.setId(resultSet.getInt("ID")); + criterion.setName(resultSet.getString("NAME")); + } + return criterion; + + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); + } + } + + @Override + public Criterion getCriterion(String name) throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + Criterion criterion = new Criterion(); + + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_CRITERIA WHERE NAME= ?"; + stmt = conn.prepareStatement(query); + stmt.setString(1, name); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + criterion.setId(resultSet.getInt("ID")); + criterion.setName(resultSet.getString("NAME")); + } + return criterion; + + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); + } + } + + @Override + public boolean checkCriterionExists(String name) throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + boolean exist = false; + + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_CRITERIA WHERE NAME = ?"; + stmt = conn.prepareStatement(query); + stmt.setString(1, name); + resultSet = stmt.executeQuery(); + exist = resultSet.next(); + + } catch (SQLException e) { + String msg = "Error occurred while checking whether criterion (" + name + ") exists."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); + this.closeConnection(); + } + return exist; + } + + @Override + public boolean deleteCriterion(Criterion criteria) throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + + try { + conn = this.getConnection(); + String query = "DELETE FROM DM_CRITERIA WHERE ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, criteria.getId()); + stmt.executeUpdate(); + + if (log.isDebugEnabled()) { + log.debug("Criterion (" + criteria.getName() + ") delete from database."); + } + return true; + } catch (SQLException e) { + String msg = "Unable to delete the policy (" + criteria.getName() + ") from database."; + log.error(msg); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } + } + + @Override + public List getAllPolicyCriteria() throws PolicyManagerDAOException { + return null; + } + + @Override + public Policy addPolicyCriteria(Policy policy) throws PolicyManagerDAOException { + return null; + } + + @Override + public List getPolicyCriteria(int policyId) throws PolicyManagerDAOException { + return null; + } + @Override public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException { Connection conn; PreparedStatement stmt = null; - ResultSet generatedKeys = null; try { conn = this.getConnection(); String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ? WHERE ID = ?"; @@ -241,7 +425,7 @@ public class PolicyDAOImpl implements PolicyDAO { log.error(msg, e); throw new PolicyManagerDAOException(msg, e); } finally { - PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys); + PolicyManagementDAOUtil.cleanupResources(stmt, null); } return policy; } 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 f4dad99f006..b7613204de4 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 @@ -21,7 +21,13 @@ 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.*; +import org.wso2.carbon.device.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.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileManagementException; import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager; import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager; import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager; 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 12cd31c126f..412f4350b15 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 @@ -26,7 +26,12 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; -import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.PIPDevice; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager; import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java index 529d9c0d1a9..4f5b66378dc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java @@ -19,7 +19,8 @@ package org.wso2.carbon.policy.mgt.core.mgt; -import org.wso2.carbon.policy.mgt.common.Feature; + +import org.wso2.carbon.device.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; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java index 4d2e9401780..51e279d5c02 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.policy.mgt.core.mgt.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.device.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; @@ -167,7 +167,7 @@ public class FeatureManagerImpl implements FeatureManager { } catch (PolicyManagerDAOException e) { String msg = "Error occurred while adding profile feature (" + - feature.getFeature().getName() + " - " + profileId + ")"; + feature.getFeatureCode() + " - " + profileId + ")"; log.error(msg, e); throw new FeatureManagementException(msg, e); } catch (FeatureManagerDAOException e) { @@ -177,7 +177,7 @@ public class FeatureManagerImpl implements FeatureManager { log.warn("Unable to roll back the transaction"); } String msg = "Error occurred while adding profile feature (" + - feature.getFeature().getName() + " - " + profileId + ") to database."; + feature.getFeatureCode() + " - " + profileId + ") to database."; log.error(msg, e); throw new FeatureManagementException(msg, e); } @@ -199,7 +199,7 @@ public class FeatureManagerImpl implements FeatureManager { log.warn("Unable to roll back the transaction"); } String msg = "Error occurred while updating feature (" + - feature.getFeature().getName() + " - " + profileId + ")"; + feature.getFeatureCode() + " - " + profileId + ")"; log.error(msg, e); throw new FeatureManagementException(msg, e); } catch (FeatureManagerDAOException e) { @@ -209,7 +209,7 @@ public class FeatureManagerImpl implements FeatureManager { log.warn("Unable to roll back the transaction"); } String msg = "Error occurred while updating feature (" + - feature.getFeature().getName() + " - " + profileId + ") in database."; + feature.getFeatureCode() + " - " + profileId + ") in database."; 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/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 89cd3eefae5..811a7f087c2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -26,7 +26,6 @@ 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.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.mgt.PolicyManager; @@ -70,12 +69,12 @@ public class PolicyManagerImpl implements PolicyManager { policyDAO.addPolicyToUser(policy.getUsers(), policy); } - if (policy.getRoleList() != null) { - policyDAO.addPolicyToRole(policy.getRoleList(), policy); + if (policy.getRoles() != null) { + policyDAO.addPolicyToRole(policy.getRoles(), policy); } - if (policy.getDeviceList() != null) { - policyDAO.addPolicyToDevice(policy.getDeviceList(), policy); + if (policy.getDevices() != null) { + policyDAO.addPolicyToDevice(policy.getDevices(), policy); } if (policy.getEndDate() != null & policy.getStartDate() != null) { @@ -138,12 +137,12 @@ public class PolicyManagerImpl implements PolicyManager { policyDAO.addPolicyToUser(policy.getUsers(), policy); } - if (policy.getRoleList() != null) { - policyDAO.addPolicyToRole(policy.getRoleList(), policy); + if (policy.getRoles() != null) { + policyDAO.addPolicyToRole(policy.getRoles(), policy); } - if (policy.getDeviceList() != null) { - policyDAO.addPolicyToDevice(policy.getDeviceList(), policy); + if (policy.getDevices() != null) { + policyDAO.addPolicyToDevice(policy.getDevices(), policy); } if (policy.getEndDate() != null & policy.getStartDate() != null) { @@ -213,16 +212,16 @@ public class PolicyManagerImpl implements PolicyManager { policy = policyDAO.addPolicyToDevice(deviceList, policy); PolicyManagementDAOFactory.commitTransaction(); - if (policy.getDeviceList() != null) { + if (policy.getDevices() != null) { if (log.isDebugEnabled()) { log.debug("Device list of policy is not null."); } - policy.getDeviceList().addAll(deviceList); + policy.getDevices().addAll(deviceList); } else { if (log.isDebugEnabled()) { log.debug("Device list of policy is null. So added the first device to the list."); } - policy.setDeviceList(deviceList); + policy.setDevices(deviceList); } } catch (PolicyManagerDAOException e) { @@ -260,16 +259,16 @@ public class PolicyManagerImpl implements PolicyManager { policy = policyDAO.addPolicyToRole(roleNames, policy); PolicyManagementDAOFactory.commitTransaction(); - if (policy.getRoleList() != null) { + if (policy.getRoles() != null) { if (log.isDebugEnabled()) { log.debug("New roles list is added to the policy "); } - policy.getRoleList().addAll(roleNames); + policy.getRoles().addAll(roleNames); } else { if (log.isDebugEnabled()) { log.debug("Roles list was null, new roles are added."); } - policy.setRoleList(roleNames); + policy.setRoles(roleNames); } } catch (PolicyManagerDAOException e) { @@ -298,16 +297,16 @@ public class PolicyManagerImpl implements PolicyManager { policy = policyDAO.addPolicyToUser(usernameList, policy); PolicyManagementDAOFactory.commitTransaction(); - if (policy.getRoleList() != null) { + if (policy.getRoles() != null) { if (log.isDebugEnabled()) { log.debug("New users list is added to the policy "); } - policy.getRoleList().addAll(usernameList); + policy.getRoles().addAll(usernameList); } else { if (log.isDebugEnabled()) { log.debug("Users list was null, new users list is added."); } - policy.setRoleList(usernameList); + policy.setRoles(usernameList); } } catch (PolicyManagerDAOException e) { @@ -343,8 +342,8 @@ public class PolicyManagerImpl implements PolicyManager { profile = profileDAO.getProfiles(profileId); policy.setProfile(profile); - policy.setRoleList(roleNames); - policy.setDeviceList(deviceList); + policy.setRoles(roleNames); + policy.setDevices(deviceList); } catch (PolicyManagerDAOException e) { String msg = "Error occurred while getting the policy related to profile ID (" + profileId + ")"; @@ -376,8 +375,8 @@ public class PolicyManagerImpl implements PolicyManager { Profile profile = profileDAO.getProfiles(policy.getProfile().getProfileId()); policy.setProfile(profile); - policy.setRoleList(roleNames); - policy.setDeviceList(deviceList); + policy.setRoles(roleNames); + policy.setDevices(deviceList); } catch (PolicyManagerDAOException e) { String msg = "Error occurred while getting the policy related to policy ID (" + policyId + ")"; @@ -406,8 +405,8 @@ public class PolicyManagerImpl implements PolicyManager { policy.setProfile(profile); } } - policy.setDeviceList(getPolicyAppliedDevicesIds(policy.getId())); - policy.setRoleList(policyDAO.getPolicyAppliedRoles(policy.getId())); + policy.setDevices(getPolicyAppliedDevicesIds(policy.getId())); + policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId())); policyDAO.getDatesOfPolicy(policy); policyDAO.getTimesOfPolicy(policy); policyDAO.getLocationsOfPolicy(policy); 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 511b4db8b8b..2dcfbc99c5b 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 @@ -19,7 +19,15 @@ package org.wso2.carbon.policy.mgt.core.service; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.device.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.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java index 7e0621e89a3..772c1980ec7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java @@ -31,7 +31,7 @@ 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.dto.Device; -import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.device.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.PolicyAdministratorPoint; @@ -192,7 +192,7 @@ public class PolicyDAOTestCase { featureList = FeatureCreator.getFeatureList(); //featureManager.addFeatures(featureList); for (Feature feature : featureList) { - featureManager.addFeature(feature); +// featureManager.addFeature(feature); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java index 439bb7f15a9..c487e7c6ea8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java @@ -18,7 +18,7 @@ package org.wso2.carbon.policy.mgt.core.util; -import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.Feature; import java.util.ArrayList; import java.util.List; @@ -28,84 +28,95 @@ public class FeatureCreator { public static List getFeatureList() { Feature feature1 = new Feature(); + feature1.setId(1); feature1.setName("Camera"); feature1.setCode("C001"); feature1.setDescription("Camera"); - feature1.setRuleValue("permit_override"); - feature1.setDeviceTypeId(1); +// feature1.setRuleValue("permit_override"); + feature1.setDeviceType("android"); Feature feature2 = new Feature(); + feature2.setId(2); feature2.setName("LOCK"); feature2.setCode("L001"); feature2.setDescription("Lock the phone"); - feature2.setRuleValue("deny_override"); - feature2.setDeviceTypeId(1); +// feature2.setRuleValue("deny_override"); + feature2.setDeviceType("android"); Feature feature3 = new Feature(); + feature3.setId(3); feature3.setName("WIFI"); feature3.setCode("W001"); feature3.setDescription("Wifi configuration for the device"); - feature3.setRuleValue("all_available"); - feature3.setDeviceTypeId(1); +// feature3.setRuleValue("all_available"); + feature3.setDeviceType("android"); Feature feature4 = new Feature(); + feature4.setId(4); feature4.setName("RING"); feature4.setCode("R001"); feature4.setDescription("Ring the mobile"); - feature4.setRuleValue("first_applicable"); - feature4.setDeviceTypeId(1); +// feature4.setRuleValue("first_applicable"); + feature4.setDeviceType("android"); Feature feature5 = new Feature(); + feature5.setId(5); feature5.setName("LDAP"); feature5.setCode("L002"); feature5.setDescription("LDAP Configurations"); - feature5.setRuleValue("all_available"); - feature5.setDeviceTypeId(1); +// feature5.setRuleValue("all_available"); + feature5.setDeviceType("android"); Feature feature6 = new Feature(); + feature6.setId(6); feature6.setName("VPN"); feature6.setCode("V001"); feature6.setDescription("VPN config for accessing the company network from out side"); - feature6.setRuleValue("all_available"); - feature6.setDeviceTypeId(1); +// feature6.setRuleValue("all_available"); + feature6.setDeviceType("android"); Feature feature7 = new Feature(); + feature7.setId(7); feature7.setName("PASSWORD"); feature7.setCode("P001"); feature7.setDescription("Setting the password for the mobile"); - feature7.setRuleValue("first_applicable"); - feature7.setDeviceTypeId(1); +// feature7.setRuleValue("first_applicable"); + feature7.setDeviceType("android"); Feature feature8 = new Feature(); + feature8.setId(8); feature8.setName("WIPE"); feature8.setCode("W002"); feature8.setDescription("Wiping the company profile created to access the company secure data"); - feature8.setRuleValue("permit_override"); - feature8.setDeviceTypeId(1); +// feature8.setRuleValue("permit_override"); + feature8.setDeviceType("android"); Feature feature9 = new Feature(); + feature9.setId(9); feature9.setName("ENCRYPTION"); feature9.setCode("E001"); feature9.setDescription("Adding the encryption for the phone and SD card."); - feature9.setRuleValue("permit_override"); - feature9.setDeviceTypeId(1); +// feature9.setRuleValue("permit_override"); + feature9.setDeviceType("android"); Feature feature10 = new Feature(); + feature10.setId(10); feature10.setName("APP"); feature10.setCode("A001"); feature10.setDescription("Installing an application to the phone"); - feature10.setRuleValue("permit_override"); - feature10.setDeviceTypeId(1); +// feature10.setRuleValue("permit_override"); + feature10.setDeviceType("android"); Feature feature11 = new Feature(); + feature11.setId(11); feature11.setName("EMAIL"); feature11.setCode("E002"); feature11.setDescription("Email configurations of the phone."); - feature11.setRuleValue("all_applicable"); - feature11.setDeviceTypeId(1); +// feature11.setRuleValue("all_applicable"); + feature11.setDeviceType("android"); List featureList = new ArrayList(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java index 112d00b5c91..fdf603a0d4d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java @@ -21,9 +21,6 @@ package org.wso2.carbon.policy.mgt.core.util; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Profile; -import java.sql.Date; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; @@ -49,14 +46,14 @@ public class PolicyCreator { policy.setPolicyName("New test Policy"); policy.setGeneric(true); policy.setProfile(profile); - policy.setDeviceList(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType())); + policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType())); List roles = new ArrayList(); roles.add("Role_01"); roles.add("Role_02"); roles.add("Role_03"); - policy.setRoleList(roles); + policy.setRoles(roles); List users = new ArrayList(); users.add("Geeth"); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileCreator.java index 332e4644223..4bd13925902 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileCreator.java @@ -19,7 +19,7 @@ package org.wso2.carbon.policy.mgt.core.util; import org.wso2.carbon.device.mgt.core.dto.DeviceType; -import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Profile; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileFeatureCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileFeatureCreator.java index 34a358d905e..6785990ee1e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileFeatureCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/ProfileFeatureCreator.java @@ -18,7 +18,7 @@ package org.wso2.carbon.policy.mgt.core.util; -import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.ProfileFeature; import java.util.ArrayList; @@ -33,9 +33,12 @@ public class ProfileFeatureCreator { ProfileFeature profileFeature = new ProfileFeature(); profileFeature.setContent(feature); + profileFeature.setDeviceTypeId(1); + profileFeature.setFeatureCode(feature.getCode()); + // profileFeature.setContent("rrrrrrrrrrrrrrrrrrrrrrrrrrrrr"); // profileFeature.setProfileId(1); - profileFeature.setFeature(feature); +// profileFeature.setFeature(feature); profileFeatureList.add(profileFeature); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 9762f4d8a26..3005bc42bc7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -131,27 +131,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ; --- ----------------------------------------------------- --- Table DM_FEATURES --- ----------------------------------------------------- - - -CREATE TABLE IF NOT EXISTS DM_FEATURES ( - ID INT(11) NOT NULL AUTO_INCREMENT , - NAME VARCHAR(256) NOT NULL , - CODE VARCHAR(45) NULL DEFAULT NULL , - DEVICE_TYPE_ID INT NOT NULL , - DESCRIPTION TEXT NULL DEFAULT NULL , - EVALUATION_RULE VARCHAR(60) NOT NULL , - PRIMARY KEY (ID) , - CONSTRAINT DM_FEATURES_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) - ON DELETE NO ACTION - ON UPDATE NO ACTION) - -; - -- ----------------------------------------------------- -- Table DM_PROFILE_FEATURES @@ -159,19 +138,15 @@ CREATE TABLE IF NOT EXISTS DM_FEATURES ( CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( - ID INT(11) NOT NULL AUTO_INCREMENT , - PROFILE_ID INT(11) NOT NULL , - FEATURE_ID INT(11) NOT NULL , - CONTENT BLOB NULL DEFAULT NULL , - PRIMARY KEY (ID) , - CONSTRAINT FK_DM_POLICY_FEATURES_DM_FEATURES - FOREIGN KEY (FEATURE_ID ) - REFERENCES DM_FEATURES (ID ) - ON DELETE NO ACTION - ON UPDATE NO ACTION, + ID INT(11) NOT NULL AUTO_INCREMENT, + PROFILE_ID INT(11) NOT NULL, + FEATURE_CODE VARCHAR(10) NOT NULL, + DEVICE_TYPE_ID INT NOT NULL, + CONTENT BLOB NULL DEFAULT NULL, + PRIMARY KEY (ID), CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES - FOREIGN KEY (PROFILE_ID ) - REFERENCES DM_PROFILE (ID ) + FOREIGN KEY (PROFILE_ID) + REFERENCES DM_PROFILE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index dab66f36fe0..14f3265dd3c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -66,6 +66,132 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); + +--- POLICY RELATED TABLES ---- + +CREATE TABLE IF NOT EXISTS DM_PROFILE ( + ID INT NOT NULL AUTO_INCREMENT , + PROFILE_NAME VARCHAR(45) NOT NULL , + TENANT_ID INT NOT NULL , + DEVICE_TYPE_ID INT NOT NULL , + CREATED_TIME DATETIME NOT NULL , + UPDATED_TIME DATETIME NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT DM_PROFILE_DEVICE_TYPE FOREIGN KEY (DEVICE_TYPE_ID ) REFERENCES DM_DEVICE_TYPE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_POLICY ( + ID INT(11) NOT NULL AUTO_INCREMENT , + NAME VARCHAR(45) NULL DEFAULT NULL , + TENANT_ID INT(11) NOT NULL , + PROFILE_ID INT(11) NOT NULL , + PRIORITY INT NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_DM_PROFILE_DM_POLICY FOREIGN KEY (PROFILE_ID ) REFERENCES DM_PROFILE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( + ID INT(11) NOT NULL AUTO_INCREMENT , + DEVICE_ID INT(11) NOT NULL , + POLICY_ID INT(11) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_POLICY_DEVICE_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DEVICE_DEVICE_POLICY FOREIGN KEY (DEVICE_ID ) REFERENCES DM_DEVICE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( + ID INT(11) NOT NULL , + DEVICE_TYPE_ID INT(11) NOT NULL , + POLICY_ID INT(11) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_DEVICE_TYPE_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE FOREIGN KEY (DEVICE_TYPE_ID ) REFERENCES DM_DEVICE_TYPE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( + ID INT(11) NOT NULL AUTO_INCREMENT, + PROFILE_ID INT(11) NOT NULL, + FEATURE_CODE VARCHAR(10) NOT NULL, + DEVICE_TYPE_ID INT NOT NULL, + CONTENT BLOB NULL DEFAULT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES FOREIGN KEY (PROFILE_ID) REFERENCES DM_PROFILE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( + ID INT(11) NOT NULL AUTO_INCREMENT , + ROLE_NAME VARCHAR(45) NOT NULL , + POLICY_ID INT(11) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_ROLE_POLICY_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_LOCATION ( + LATITUDE VARCHAR(45) NOT NULL , + LONGITUDE VARCHAR(45) NOT NULL , + POLICY_ID INT(11) NOT NULL , + CONSTRAINT FK_DM_POLICY_DM_LOCATION FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_TIME ( + STARTING_TIME DATETIME NOT NULL , + ENDING_TIME DATETIME NOT NULL , + POLICY_ID INT(11) NOT NULL , + CONSTRAINT FK_DM_POLICY_DM_TIME FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_DATE ( + START_DATE DATE NOT NULL , + END_DATE DATE NOT NULL , + POLICY_ID INT NOT NULL , + CONSTRAINT DM_DATE_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( + ID INT NOT NULL AUTO_INCREMENT , + POLICY_ID INT NOT NULL , + USERNAME VARCHAR(45) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT DM_POLICY_USER_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +-- POLICY RELATED TABLES FINISHED -- + + -- TO:DO - Remove this INSERT sql statement. -Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android'); -Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios'); +--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android'); +--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios');