mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Removing feature implementation from the policy, adding criteria based policy
This commit is contained in:
parent
a4485af0c9
commit
73b185e1e6
@ -17,9 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Feature {
|
public class Feature implements Serializable{
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String code;
|
private String code;
|
||||||
|
|||||||
@ -19,12 +19,10 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.evaluator;
|
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.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface FeatureFilter {
|
public interface FeatureFilter {
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
package org.wso2.carbon.policy.evaluator;
|
package org.wso2.carbon.policy.evaluator;
|
||||||
|
|
||||||
import org.wso2.carbon.policy.evaluator.utils.Constants;
|
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.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|
||||||
@ -103,17 +102,17 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
*/
|
*/
|
||||||
public void getDenyOverridesFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getDenyOverridesFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
ProfileFeature evaluatedFeature = null;
|
ProfileFeature evaluatedFeature = null;
|
||||||
for (ProfileFeature feature : featureList) {
|
// for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
if (feature.getFeature().getRuleValue().equalsIgnoreCase("Deny")) {
|
// if (feature.getFeature().getRuleValue().equalsIgnoreCase("Deny")) {
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
// effectiveFeatureList.add(evaluatedFeature);
|
||||||
return;
|
// return;
|
||||||
} else {
|
// } else {
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (evaluatedFeature != null) {
|
if (evaluatedFeature != null) {
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
effectiveFeatureList.add(evaluatedFeature);
|
||||||
}
|
}
|
||||||
@ -130,17 +129,17 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
*/
|
*/
|
||||||
public void getPermitOverridesFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getPermitOverridesFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
ProfileFeature evaluatedFeature = null;
|
ProfileFeature evaluatedFeature = null;
|
||||||
for (ProfileFeature feature : featureList) {
|
// for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
if (feature.getFeature().getRuleValue().equalsIgnoreCase("Permit")) {
|
// if (feature.getFeature().getRuleValue().equalsIgnoreCase("Permit")) {
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
// effectiveFeatureList.add(evaluatedFeature);
|
||||||
return;
|
// return;
|
||||||
} else {
|
// } else {
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (evaluatedFeature != null) {
|
if (evaluatedFeature != null) {
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
effectiveFeatureList.add(evaluatedFeature);
|
||||||
}
|
}
|
||||||
@ -157,11 +156,11 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
*/
|
*/
|
||||||
public void getFirstApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getFirstApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
for (ProfileFeature feature : featureList) {
|
for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
effectiveFeatureList.add(feature);
|
// effectiveFeatureList.add(feature);
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,11 +174,11 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
*/
|
*/
|
||||||
public void getLastApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getLastApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
ProfileFeature evaluatedFeature = null;
|
ProfileFeature evaluatedFeature = null;
|
||||||
for (ProfileFeature feature : featureList) {
|
// for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (evaluatedFeature != null) {
|
if (evaluatedFeature != null) {
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
effectiveFeatureList.add(evaluatedFeature);
|
||||||
}
|
}
|
||||||
@ -195,9 +194,9 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
*/
|
*/
|
||||||
public void getAllApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getAllApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
for (ProfileFeature feature : featureList) {
|
for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
effectiveFeatureList.add(feature);
|
// effectiveFeatureList.add(feature);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,14 +211,14 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
public void getHighestApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getHighestApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
ProfileFeature evaluatedFeature = null;
|
ProfileFeature evaluatedFeature = null;
|
||||||
int intValve = 0;
|
int intValve = 0;
|
||||||
for (ProfileFeature feature : featureList) {
|
// for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
if (Integer.parseInt(feature.getFeature().getRuleValue()) > intValve) {
|
// if (Integer.parseInt(feature.getFeature().getRuleValue()) > intValve) {
|
||||||
intValve = Integer.parseInt(feature.getFeature().getRuleValue());
|
// intValve = Integer.parseInt(feature.getFeature().getRuleValue());
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (evaluatedFeature != null) {
|
if (evaluatedFeature != null) {
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
effectiveFeatureList.add(evaluatedFeature);
|
||||||
}
|
}
|
||||||
@ -235,15 +234,15 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
*/
|
*/
|
||||||
public void getLowestApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
public void getLowestApplicableFeatures(String featureName, List<ProfileFeature> featureList, List<ProfileFeature> effectiveFeatureList) {
|
||||||
ProfileFeature evaluatedFeature = null;
|
ProfileFeature evaluatedFeature = null;
|
||||||
int intValve = 0;
|
// int intValve = 0;
|
||||||
for (ProfileFeature feature : featureList) {
|
// for (ProfileFeature feature : featureList) {
|
||||||
if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
// if (feature.getFeature().getName().equalsIgnoreCase(featureName)) {
|
||||||
if (Integer.parseInt(feature.getFeature().getRuleValue()) < intValve) {
|
// if (Integer.parseInt(feature.getFeature().getRuleValue()) < intValve) {
|
||||||
intValve = Integer.parseInt(feature.getFeature().getRuleValue());
|
// intValve = Integer.parseInt(feature.getFeature().getRuleValue());
|
||||||
evaluatedFeature = feature;
|
// evaluatedFeature = feature;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (evaluatedFeature != null) {
|
if (evaluatedFeature != null) {
|
||||||
effectiveFeatureList.add(evaluatedFeature);
|
effectiveFeatureList.add(evaluatedFeature);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
List<Policy> policies = new ArrayList<Policy>();
|
List<Policy> policies = new ArrayList<Policy>();
|
||||||
|
|
||||||
for (Policy policy : policyList) {
|
for (Policy policy : policyList) {
|
||||||
List<String> roleList = policy.getRoleList();
|
List<String> roleList = policy.getRoles();
|
||||||
|
|
||||||
for (String role : roleList) {
|
for (String role : roleList) {
|
||||||
if (roles.contains(role)) {
|
if (roles.contains(role)) {
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
package org.wso2.carbon.policy.information.point;
|
package org.wso2.carbon.policy.information.point;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
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.PIPDevice;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,67 +22,67 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
public class Feature implements Serializable {
|
public class Feature implements Serializable {
|
||||||
|
|
||||||
private int id;
|
// private int id;
|
||||||
private String code;
|
// private String code;
|
||||||
private String name;
|
// private String name;
|
||||||
private String description;
|
// private String description;
|
||||||
// private Object attribute;
|
// // private Object attribute;
|
||||||
private String ruleValue;
|
// private String ruleValue;
|
||||||
private int deviceTypeId;
|
// private int deviceTypeId;
|
||||||
|
//
|
||||||
public String getDescription() {
|
// public String getDescription() {
|
||||||
return description;
|
// return description;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setDescription(String description) {
|
// public void setDescription(String description) {
|
||||||
this.description = description;
|
// this.description = description;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String getRuleValue() {
|
// public String getRuleValue() {
|
||||||
return ruleValue;
|
// return ruleValue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setRuleValue(String ruleValue) {
|
// public void setRuleValue(String ruleValue) {
|
||||||
this.ruleValue = ruleValue;
|
// this.ruleValue = ruleValue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getId() {
|
// public int getId() {
|
||||||
return id;
|
// return id;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setId(int id) {
|
// public void setId(int id) {
|
||||||
this.id = id;
|
// this.id = id;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String getCode() {
|
// public String getCode() {
|
||||||
return code;
|
// return code;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setCode(String code) {
|
// public void setCode(String code) {
|
||||||
this.code = code;
|
// this.code = code;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String getName() {
|
// public String getName() {
|
||||||
return name;
|
// return name;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setName(String name) {
|
// public void setName(String name) {
|
||||||
this.name = name;
|
// this.name = name;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/* public Object getAttribute() {
|
///* public Object getAttribute() {
|
||||||
return attribute;
|
// return attribute;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setAttribute(Object attribute) {
|
// public void setAttribute(Object attribute) {
|
||||||
this.attribute = attribute;
|
// this.attribute = attribute;
|
||||||
}*/
|
// }*/
|
||||||
|
//
|
||||||
public int getDeviceTypeId() {
|
// public int getDeviceTypeId() {
|
||||||
return deviceTypeId;
|
// return deviceTypeId;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setDeviceTypeId(int deviceTypeId) {
|
// public void setDeviceTypeId(int deviceTypeId) {
|
||||||
this.deviceTypeId = deviceTypeId;
|
// this.deviceTypeId = deviceTypeId;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,13 +36,17 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
private Profile profile; // Profile
|
private Profile profile; // Profile
|
||||||
private String policyName; // Name of the policy.
|
private String policyName; // Name of the policy.
|
||||||
private boolean generic; // If true, this should be applied to all related device.
|
private boolean generic; // If true, this should be applied to all related device.
|
||||||
private List<String> roleList; // Roles which this policy should be applied.
|
private List<String> roles; // Roles which this policy should be applied.
|
||||||
private String ownershipType; // Ownership type (COPE, BYOD, CPE)
|
private String ownershipType; // Ownership type (COPE, BYOD, CPE)
|
||||||
private List<Device> DeviceList; // Individual devices this policy should be applied
|
private List<Device> devices; // Individual devices this policy should be applied
|
||||||
private List<String> users;
|
private List<String> users;
|
||||||
|
|
||||||
/*Dynamic policy attributes*/
|
/*Dynamic policy attributes*/
|
||||||
|
|
||||||
|
/* This is related criteria based policy */
|
||||||
|
|
||||||
|
private List<PolicyCriteria> policyCriterias;
|
||||||
|
|
||||||
/*These are related to time based policies*/
|
/*These are related to time based policies*/
|
||||||
|
|
||||||
private int startTime; // Start time to apply the policy.
|
private int startTime; // Start time to apply the policy.
|
||||||
@ -111,12 +115,12 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
this.generic = generic;
|
this.generic = generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getRoleList() {
|
public List<String> getRoles() {
|
||||||
return roleList;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoleList(List<String> roleList) {
|
public void setRoles(List<String> roles) {
|
||||||
this.roleList = roleList;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwnershipType() {
|
public String getOwnershipType() {
|
||||||
@ -127,12 +131,12 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
this.ownershipType = ownershipType;
|
this.ownershipType = ownershipType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Device> getDeviceList() {
|
public List<Device> getDevices() {
|
||||||
return DeviceList;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeviceList(List<Device> deviceList) {
|
public void setDevices(List<Device> devices) {
|
||||||
DeviceList = deviceList;
|
this.devices = devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getUsers() {
|
public List<String> getUsers() {
|
||||||
@ -143,6 +147,14 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<PolicyCriteria> getPolicyCriterias() {
|
||||||
|
return policyCriterias;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolicyCriterias(List<PolicyCriteria> policyCriterias) {
|
||||||
|
this.policyCriterias = policyCriterias;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStartTime() {
|
public int getStartTime() {
|
||||||
return startTime;
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.common;
|
package org.wso2.carbon.policy.mgt.common;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@ -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<String, Object> 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<String, Object> getObjectMap() {
|
||||||
|
return objectMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObjectMap(Map<String, Object> objectMap) {
|
||||||
|
this.objectMap = objectMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,6 +20,7 @@
|
|||||||
package org.wso2.carbon.policy.mgt.common;
|
package org.wso2.carbon.policy.mgt.common;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@ -19,12 +19,15 @@
|
|||||||
package org.wso2.carbon.policy.mgt.common;
|
package org.wso2.carbon.policy.mgt.common;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
|
||||||
public class ProfileFeature implements Serializable {
|
public class ProfileFeature implements Serializable {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private Feature feature;
|
private String featureCode;
|
||||||
|
// private Feature feature;
|
||||||
private int profileId;
|
private int profileId;
|
||||||
|
private int deviceTypeId;
|
||||||
private Object content;
|
private Object content;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -35,14 +38,22 @@ public class ProfileFeature implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feature getFeature() {
|
public String getFeatureCode() {
|
||||||
return feature;
|
return featureCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFeature(Feature feature) {
|
public void setFeatureCode(String featureCode) {
|
||||||
this.feature = feature;
|
this.featureCode = featureCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public Feature getFeature() {
|
||||||
|
// return feature;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setFeature(Feature feature) {
|
||||||
|
// this.feature = feature;
|
||||||
|
// }
|
||||||
|
|
||||||
public int getProfileId() {
|
public int getProfileId() {
|
||||||
return profileId;
|
return profileId;
|
||||||
}
|
}
|
||||||
@ -51,6 +62,14 @@ public class ProfileFeature implements Serializable {
|
|||||||
this.profileId = profileId;
|
this.profileId = profileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDeviceTypeId() {
|
||||||
|
return deviceTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceTypeId(int deviceTypeId) {
|
||||||
|
this.deviceTypeId = deviceTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getContent() {
|
public Object getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
package org.wos2.carbon.policy.mgt.common.utils;
|
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.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,15 @@
|
|||||||
package org.wso2.carbon.policy.mgt.core;
|
package org.wso2.carbon.policy.mgt.core;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,16 @@ package org.wso2.carbon.policy.mgt.core;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
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.PolicyAdministratorPointImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
|
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
|||||||
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.dao;
|
package org.wso2.carbon.policy.mgt.core.dao;
|
||||||
|
|
||||||
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.Profile;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.dao;
|
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.device.mgt.core.dto.Device;
|
||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
|
|
||||||
@ -43,6 +42,24 @@ public interface PolicyDAO {
|
|||||||
|
|
||||||
Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws PolicyManagerDAOException;
|
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<Criterion> getAllPolicyCriteria() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
Policy addPolicyCriteria(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
List<PolicyCriteria> getPolicyCriteria(int policyId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy updatePolicy(Policy policy) throws PolicyManagerDAOException;
|
Policy updatePolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getPolicy(int policyId) throws PolicyManagerDAOException;
|
Policy getPolicy(int policyId) throws PolicyManagerDAOException;
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
@ -20,7 +20,8 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.Profile;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
||||||
@ -50,13 +51,13 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
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 = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
stmt.setString(1, feature.getName());
|
stmt.setString(1, feature.getName());
|
||||||
stmt.setString(2, feature.getCode());
|
stmt.setString(2, feature.getCode());
|
||||||
stmt.setString(3, feature.getDescription());
|
stmt.setString(3, feature.getDescription());
|
||||||
stmt.setString(4, feature.getRuleValue());
|
// stmt.setString(4, feature.getRuleValue());
|
||||||
stmt.setInt(5, feature.getDeviceTypeId());
|
// stmt.setInt(5, feature.getDeviceTypeId());
|
||||||
int affectedRows = stmt.executeUpdate();
|
int affectedRows = stmt.executeUpdate();
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -88,15 +89,15 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
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 = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
for (Feature feature : features) {
|
for (Feature feature : features) {
|
||||||
stmt.setString(1, feature.getName());
|
stmt.setString(1, feature.getName());
|
||||||
stmt.setString(2, feature.getCode());
|
stmt.setString(2, feature.getCode());
|
||||||
stmt.setString(3, feature.getDescription());
|
stmt.setString(3, feature.getDescription());
|
||||||
stmt.setString(4, feature.getRuleValue());
|
// stmt.setString(4, feature.getRuleValue());
|
||||||
stmt.setInt(5, feature.getDeviceTypeId());
|
// stmt.setInt(5, feature.getDeviceTypeId());
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,13 +134,13 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
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 = conn.prepareStatement(query);
|
||||||
stmt.setString(1, feature.getName());
|
stmt.setString(1, feature.getName());
|
||||||
stmt.setString(2, feature.getCode());
|
stmt.setString(2, feature.getCode());
|
||||||
stmt.setString(3, feature.getDescription());
|
stmt.setString(3, feature.getDescription());
|
||||||
stmt.setString(4, feature.getRuleValue());
|
// stmt.setString(4, feature.getRuleValue());
|
||||||
stmt.setInt(5, feature.getId());
|
stmt.setInt(4, feature.getId());
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -172,13 +173,15 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
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);
|
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
for (ProfileFeature feature : features) {
|
for (ProfileFeature feature : features) {
|
||||||
stmt.setInt(1, profileId);
|
stmt.setInt(1, profileId);
|
||||||
stmt.setInt(2, feature.getFeature().getId());
|
stmt.setString(2, feature.getFeatureCode());
|
||||||
stmt.setObject(3, feature.getContent());
|
stmt.setInt(3, feature.getDeviceTypeId());
|
||||||
|
stmt.setObject(4, feature.getContent());
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
//Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
|
//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 {
|
try {
|
||||||
conn = this.getConnection();
|
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);
|
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
for (ProfileFeature feature : features) {
|
for (ProfileFeature feature : features) {
|
||||||
stmt.setObject(1, feature.getContent());
|
stmt.setObject(1, feature.getContent());
|
||||||
stmt.setInt(2, profileId);
|
stmt.setInt(2, profileId);
|
||||||
stmt.setInt(3, feature.getFeature().getId());
|
stmt.setString(3, feature.getFeatureCode());
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
//Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
|
//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
|
@Override
|
||||||
public List<Feature> getAllFeatures() throws FeatureManagerDAOException {
|
public List<Feature> getAllFeatures() throws FeatureManagerDAOException {
|
||||||
|
|
||||||
Connection conn;
|
// Connection conn;
|
||||||
PreparedStatement stmt = null;
|
// PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
// ResultSet resultSet = null;
|
||||||
List<Feature> featureList = new ArrayList<Feature>();
|
List<Feature> featureList = new ArrayList<Feature>();
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
conn = this.getConnection();
|
// conn = this.getConnection();
|
||||||
String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUATION_RULE FROM DM_FEATURES";
|
// String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUATION_RULE FROM DM_FEATURES";
|
||||||
stmt = conn.prepareStatement(query);
|
// stmt = conn.prepareStatement(query);
|
||||||
resultSet = stmt.executeQuery();
|
// resultSet = stmt.executeQuery();
|
||||||
|
//
|
||||||
while (resultSet.next()) {
|
// while (resultSet.next()) {
|
||||||
|
//
|
||||||
Feature feature = new Feature();
|
// Feature feature = new Feature();
|
||||||
feature.setId(resultSet.getInt("ID"));
|
// feature.setId(resultSet.getInt("ID"));
|
||||||
feature.setCode(resultSet.getString("CODE"));
|
// feature.setCode(resultSet.getString("CODE"));
|
||||||
feature.setName(resultSet.getString("NAME"));
|
// feature.setName(resultSet.getString("NAME"));
|
||||||
feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
|
// feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
|
||||||
feature.setRuleValue(resultSet.getString("EVALUATION_RULE"));
|
// feature.setRuleValue(resultSet.getString("EVALUATION_RULE"));
|
||||||
featureList.add(feature);
|
// featureList.add(feature);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
} catch (SQLException e) {
|
// } catch (SQLException e) {
|
||||||
String msg = "Unable to get the list of the features from database.";
|
// String msg = "Unable to get the list of the features from database.";
|
||||||
log.error(msg);
|
// log.error(msg);
|
||||||
throw new FeatureManagerDAOException(msg, e);
|
// throw new FeatureManagerDAOException(msg, e);
|
||||||
} finally {
|
// } finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
// PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
this.closeConnection();
|
// this.closeConnection();
|
||||||
}
|
// }
|
||||||
return featureList;
|
return featureList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,22 +305,22 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " +
|
String query = "SELECT ID, PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES";
|
||||||
"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";
|
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
|
||||||
ProfileFeature profileFeature = new ProfileFeature();
|
ProfileFeature profileFeature = new ProfileFeature();
|
||||||
Feature feature = new Feature();
|
// Feature feature = new Feature();
|
||||||
feature.setId(resultSet.getInt("FEATURE_ID"));
|
// feature.setId(resultSet.getInt("FEATURE_ID"));
|
||||||
feature.setCode(resultSet.getString("CODE"));
|
// feature.setCode(resultSet.getString("CODE"));
|
||||||
feature.setName(resultSet.getString("NAME"));
|
// feature.setName(resultSet.getString("NAME"));
|
||||||
feature.setRuleValue(resultSet.getString("RULE"));
|
// feature.setRuleValue(resultSet.getString("RULE"));
|
||||||
|
|
||||||
profileFeature.setFeature(feature);
|
// profileFeature.setFeature(feature);
|
||||||
|
profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
|
||||||
|
profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
|
||||||
profileFeature.setId(resultSet.getInt("ID"));
|
profileFeature.setId(resultSet.getInt("ID"));
|
||||||
profileFeature.setContent(resultSet.getObject("CONTENT"));
|
profileFeature.setContent(resultSet.getObject("CONTENT"));
|
||||||
profileFeature.setProfileId(resultSet.getInt("PROFILE_ID"));
|
profileFeature.setProfileId(resultSet.getInt("PROFILE_ID"));
|
||||||
@ -358,8 +361,8 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
feature.setId(resultSet.getInt("ID"));
|
feature.setId(resultSet.getInt("ID"));
|
||||||
feature.setCode(resultSet.getString("CODE"));
|
feature.setCode(resultSet.getString("CODE"));
|
||||||
feature.setName(resultSet.getString("NAME"));
|
feature.setName(resultSet.getString("NAME"));
|
||||||
feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
|
// feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
|
||||||
feature.setRuleValue(resultSet.getString("EVALUATION_RULE"));
|
// feature.setRuleValue(resultSet.getString("EVALUATION_RULE"));
|
||||||
featureList.add(feature);
|
featureList.add(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,23 +387,24 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " +
|
String query = "SELECT ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES " +
|
||||||
"F.EVALUATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " +
|
"WHERE PROFILE_ID = ?";
|
||||||
"JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?";
|
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, profileId);
|
stmt.setInt(1, profileId);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
ProfileFeature profileFeature = new ProfileFeature();
|
ProfileFeature profileFeature = new ProfileFeature();
|
||||||
Feature feature = new Feature();
|
// Feature feature = new Feature();
|
||||||
feature.setId(resultSet.getInt("FEATURE_ID"));
|
// feature.setId(resultSet.getInt("FEATURE_ID"));
|
||||||
feature.setCode(resultSet.getString("CODE"));
|
// feature.setCode(resultSet.getString("CODE"));
|
||||||
feature.setName(resultSet.getString("NAME"));
|
// feature.setName(resultSet.getString("NAME"));
|
||||||
feature.setRuleValue(resultSet.getString("RULE"));
|
// feature.setRuleValue(resultSet.getString("RULE"));
|
||||||
|
|
||||||
profileFeature.setFeature(feature);
|
// profileFeature.setFeature(feature);
|
||||||
profileFeature.setId(resultSet.getInt("ID"));
|
profileFeature.setId(resultSet.getInt("ID"));
|
||||||
|
profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
|
||||||
|
profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
|
||||||
profileFeature.setContent(resultSet.getObject("CONTENT"));
|
profileFeature.setContent(resultSet.getObject("CONTENT"));
|
||||||
featureList.add(profileFeature);
|
featureList.add(profileFeature);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -202,7 +202,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "INSERT INTO DM_LOCATION (LATITUDE, LONGITUDE, POLICY_ID) VALUES (?, ?, ?)";
|
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(1, latitude);
|
||||||
stmt.setString(2, longitude);
|
stmt.setString(2, longitude);
|
||||||
stmt.setInt(3, policy.getId());
|
stmt.setInt(3, policy.getId());
|
||||||
@ -219,12 +219,196 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
return policy;
|
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<Criterion> getAllPolicyCriteria() throws PolicyManagerDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy addPolicyCriteria(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PolicyCriteria> getPolicyCriteria(int policyId) throws PolicyManagerDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException {
|
public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet generatedKeys = null;
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ? WHERE ID = ?";
|
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);
|
log.error(msg, e);
|
||||||
throw new PolicyManagerDAOException(msg, e);
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,13 @@ package org.wso2.carbon.policy.mgt.core.impl;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
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.FeatureManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||||
|
|||||||
@ -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.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
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.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
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.PolicyManager;
|
||||||
|
|||||||
@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.mgt;
|
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.FeatureManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.FeatureManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
@ -167,7 +167,7 @@ public class FeatureManagerImpl implements FeatureManager {
|
|||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
String msg = "Error occurred while adding profile feature (" +
|
String msg = "Error occurred while adding profile feature (" +
|
||||||
feature.getFeature().getName() + " - " + profileId + ")";
|
feature.getFeatureCode() + " - " + profileId + ")";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new FeatureManagementException(msg, e);
|
throw new FeatureManagementException(msg, e);
|
||||||
} catch (FeatureManagerDAOException e) {
|
} catch (FeatureManagerDAOException e) {
|
||||||
@ -177,7 +177,7 @@ public class FeatureManagerImpl implements FeatureManager {
|
|||||||
log.warn("Unable to roll back the transaction");
|
log.warn("Unable to roll back the transaction");
|
||||||
}
|
}
|
||||||
String msg = "Error occurred while adding profile feature (" +
|
String msg = "Error occurred while adding profile feature (" +
|
||||||
feature.getFeature().getName() + " - " + profileId + ") to database.";
|
feature.getFeatureCode() + " - " + profileId + ") to database.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new FeatureManagementException(msg, e);
|
throw new FeatureManagementException(msg, e);
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ public class FeatureManagerImpl implements FeatureManager {
|
|||||||
log.warn("Unable to roll back the transaction");
|
log.warn("Unable to roll back the transaction");
|
||||||
}
|
}
|
||||||
String msg = "Error occurred while updating feature (" +
|
String msg = "Error occurred while updating feature (" +
|
||||||
feature.getFeature().getName() + " - " + profileId + ")";
|
feature.getFeatureCode() + " - " + profileId + ")";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new FeatureManagementException(msg, e);
|
throw new FeatureManagementException(msg, e);
|
||||||
} catch (FeatureManagerDAOException e) {
|
} catch (FeatureManagerDAOException e) {
|
||||||
@ -209,7 +209,7 @@ public class FeatureManagerImpl implements FeatureManager {
|
|||||||
log.warn("Unable to roll back the transaction");
|
log.warn("Unable to roll back the transaction");
|
||||||
}
|
}
|
||||||
String msg = "Error occurred while updating feature (" +
|
String msg = "Error occurred while updating feature (" +
|
||||||
feature.getFeature().getName() + " - " + profileId + ") in database.";
|
feature.getFeatureCode() + " - " + profileId + ") in database.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new FeatureManagementException(msg, e);
|
throw new FeatureManagementException(msg, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
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.Device;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
@ -70,12 +69,12 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getRoleList() != null) {
|
if (policy.getRoles() != null) {
|
||||||
policyDAO.addPolicyToRole(policy.getRoleList(), policy);
|
policyDAO.addPolicyToRole(policy.getRoles(), policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getDeviceList() != null) {
|
if (policy.getDevices() != null) {
|
||||||
policyDAO.addPolicyToDevice(policy.getDeviceList(), policy);
|
policyDAO.addPolicyToDevice(policy.getDevices(), policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
||||||
@ -138,12 +137,12 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getRoleList() != null) {
|
if (policy.getRoles() != null) {
|
||||||
policyDAO.addPolicyToRole(policy.getRoleList(), policy);
|
policyDAO.addPolicyToRole(policy.getRoles(), policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getDeviceList() != null) {
|
if (policy.getDevices() != null) {
|
||||||
policyDAO.addPolicyToDevice(policy.getDeviceList(), policy);
|
policyDAO.addPolicyToDevice(policy.getDevices(), policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
||||||
@ -213,16 +212,16 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policy = policyDAO.addPolicyToDevice(deviceList, policy);
|
policy = policyDAO.addPolicyToDevice(deviceList, policy);
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
|
||||||
if (policy.getDeviceList() != null) {
|
if (policy.getDevices() != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device list of policy is not null.");
|
log.debug("Device list of policy is not null.");
|
||||||
}
|
}
|
||||||
policy.getDeviceList().addAll(deviceList);
|
policy.getDevices().addAll(deviceList);
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device list of policy is null. So added the first device to the list.");
|
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) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -260,16 +259,16 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policy = policyDAO.addPolicyToRole(roleNames, policy);
|
policy = policyDAO.addPolicyToRole(roleNames, policy);
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
|
||||||
if (policy.getRoleList() != null) {
|
if (policy.getRoles() != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("New roles list is added to the policy ");
|
log.debug("New roles list is added to the policy ");
|
||||||
}
|
}
|
||||||
policy.getRoleList().addAll(roleNames);
|
policy.getRoles().addAll(roleNames);
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Roles list was null, new roles are added.");
|
log.debug("Roles list was null, new roles are added.");
|
||||||
}
|
}
|
||||||
policy.setRoleList(roleNames);
|
policy.setRoles(roleNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -298,16 +297,16 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policy = policyDAO.addPolicyToUser(usernameList, policy);
|
policy = policyDAO.addPolicyToUser(usernameList, policy);
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
|
||||||
if (policy.getRoleList() != null) {
|
if (policy.getRoles() != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("New users list is added to the policy ");
|
log.debug("New users list is added to the policy ");
|
||||||
}
|
}
|
||||||
policy.getRoleList().addAll(usernameList);
|
policy.getRoles().addAll(usernameList);
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Users list was null, new users list is added.");
|
log.debug("Users list was null, new users list is added.");
|
||||||
}
|
}
|
||||||
policy.setRoleList(usernameList);
|
policy.setRoles(usernameList);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -343,8 +342,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
profile = profileDAO.getProfiles(profileId);
|
profile = profileDAO.getProfiles(profileId);
|
||||||
|
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setRoleList(roleNames);
|
policy.setRoles(roleNames);
|
||||||
policy.setDeviceList(deviceList);
|
policy.setDevices(deviceList);
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
String msg = "Error occurred while getting the policy related to profile ID (" + profileId + ")";
|
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());
|
Profile profile = profileDAO.getProfiles(policy.getProfile().getProfileId());
|
||||||
|
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setRoleList(roleNames);
|
policy.setRoles(roleNames);
|
||||||
policy.setDeviceList(deviceList);
|
policy.setDevices(deviceList);
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
String msg = "Error occurred while getting the policy related to policy ID (" + policyId + ")";
|
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.setProfile(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
policy.setDeviceList(getPolicyAppliedDevicesIds(policy.getId()));
|
policy.setDevices(getPolicyAppliedDevicesIds(policy.getId()));
|
||||||
policy.setRoleList(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
||||||
policyDAO.getDatesOfPolicy(policy);
|
policyDAO.getDatesOfPolicy(policy);
|
||||||
policyDAO.getTimesOfPolicy(policy);
|
policyDAO.getTimesOfPolicy(policy);
|
||||||
policyDAO.getLocationsOfPolicy(policy);
|
policyDAO.getLocationsOfPolicy(policy);
|
||||||
|
|||||||
@ -19,7 +19,15 @@
|
|||||||
package org.wso2.carbon.policy.mgt.core.service;
|
package org.wso2.carbon.policy.mgt.core.service;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
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.PolicyManagerService;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
|
||||||
|
|
||||||
|
|||||||
@ -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.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
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.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.FeatureManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||||
@ -192,7 +192,7 @@ public class PolicyDAOTestCase {
|
|||||||
featureList = FeatureCreator.getFeatureList();
|
featureList = FeatureCreator.getFeatureList();
|
||||||
//featureManager.addFeatures(featureList);
|
//featureManager.addFeatures(featureList);
|
||||||
for (Feature feature : featureList) {
|
for (Feature feature : featureList) {
|
||||||
featureManager.addFeature(feature);
|
// featureManager.addFeature(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.util;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,84 +28,95 @@ public class FeatureCreator {
|
|||||||
public static List<Feature> getFeatureList() {
|
public static List<Feature> getFeatureList() {
|
||||||
|
|
||||||
Feature feature1 = new Feature();
|
Feature feature1 = new Feature();
|
||||||
|
feature1.setId(1);
|
||||||
feature1.setName("Camera");
|
feature1.setName("Camera");
|
||||||
feature1.setCode("C001");
|
feature1.setCode("C001");
|
||||||
feature1.setDescription("Camera");
|
feature1.setDescription("Camera");
|
||||||
feature1.setRuleValue("permit_override");
|
// feature1.setRuleValue("permit_override");
|
||||||
feature1.setDeviceTypeId(1);
|
feature1.setDeviceType("android");
|
||||||
|
|
||||||
|
|
||||||
Feature feature2 = new Feature();
|
Feature feature2 = new Feature();
|
||||||
|
feature2.setId(2);
|
||||||
feature2.setName("LOCK");
|
feature2.setName("LOCK");
|
||||||
feature2.setCode("L001");
|
feature2.setCode("L001");
|
||||||
feature2.setDescription("Lock the phone");
|
feature2.setDescription("Lock the phone");
|
||||||
feature2.setRuleValue("deny_override");
|
// feature2.setRuleValue("deny_override");
|
||||||
feature2.setDeviceTypeId(1);
|
feature2.setDeviceType("android");
|
||||||
|
|
||||||
|
|
||||||
Feature feature3 = new Feature();
|
Feature feature3 = new Feature();
|
||||||
|
feature3.setId(3);
|
||||||
feature3.setName("WIFI");
|
feature3.setName("WIFI");
|
||||||
feature3.setCode("W001");
|
feature3.setCode("W001");
|
||||||
feature3.setDescription("Wifi configuration for the device");
|
feature3.setDescription("Wifi configuration for the device");
|
||||||
feature3.setRuleValue("all_available");
|
// feature3.setRuleValue("all_available");
|
||||||
feature3.setDeviceTypeId(1);
|
feature3.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature4 = new Feature();
|
Feature feature4 = new Feature();
|
||||||
|
feature4.setId(4);
|
||||||
feature4.setName("RING");
|
feature4.setName("RING");
|
||||||
feature4.setCode("R001");
|
feature4.setCode("R001");
|
||||||
feature4.setDescription("Ring the mobile");
|
feature4.setDescription("Ring the mobile");
|
||||||
feature4.setRuleValue("first_applicable");
|
// feature4.setRuleValue("first_applicable");
|
||||||
feature4.setDeviceTypeId(1);
|
feature4.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature5 = new Feature();
|
Feature feature5 = new Feature();
|
||||||
|
feature5.setId(5);
|
||||||
feature5.setName("LDAP");
|
feature5.setName("LDAP");
|
||||||
feature5.setCode("L002");
|
feature5.setCode("L002");
|
||||||
feature5.setDescription("LDAP Configurations");
|
feature5.setDescription("LDAP Configurations");
|
||||||
feature5.setRuleValue("all_available");
|
// feature5.setRuleValue("all_available");
|
||||||
feature5.setDeviceTypeId(1);
|
feature5.setDeviceType("android");
|
||||||
|
|
||||||
|
|
||||||
Feature feature6 = new Feature();
|
Feature feature6 = new Feature();
|
||||||
|
feature6.setId(6);
|
||||||
feature6.setName("VPN");
|
feature6.setName("VPN");
|
||||||
feature6.setCode("V001");
|
feature6.setCode("V001");
|
||||||
feature6.setDescription("VPN config for accessing the company network from out side");
|
feature6.setDescription("VPN config for accessing the company network from out side");
|
||||||
feature6.setRuleValue("all_available");
|
// feature6.setRuleValue("all_available");
|
||||||
feature6.setDeviceTypeId(1);
|
feature6.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature7 = new Feature();
|
Feature feature7 = new Feature();
|
||||||
|
feature7.setId(7);
|
||||||
feature7.setName("PASSWORD");
|
feature7.setName("PASSWORD");
|
||||||
feature7.setCode("P001");
|
feature7.setCode("P001");
|
||||||
feature7.setDescription("Setting the password for the mobile");
|
feature7.setDescription("Setting the password for the mobile");
|
||||||
feature7.setRuleValue("first_applicable");
|
// feature7.setRuleValue("first_applicable");
|
||||||
feature7.setDeviceTypeId(1);
|
feature7.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature8 = new Feature();
|
Feature feature8 = new Feature();
|
||||||
|
feature8.setId(8);
|
||||||
feature8.setName("WIPE");
|
feature8.setName("WIPE");
|
||||||
feature8.setCode("W002");
|
feature8.setCode("W002");
|
||||||
feature8.setDescription("Wiping the company profile created to access the company secure data");
|
feature8.setDescription("Wiping the company profile created to access the company secure data");
|
||||||
feature8.setRuleValue("permit_override");
|
// feature8.setRuleValue("permit_override");
|
||||||
feature8.setDeviceTypeId(1);
|
feature8.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature9 = new Feature();
|
Feature feature9 = new Feature();
|
||||||
|
feature9.setId(9);
|
||||||
feature9.setName("ENCRYPTION");
|
feature9.setName("ENCRYPTION");
|
||||||
feature9.setCode("E001");
|
feature9.setCode("E001");
|
||||||
feature9.setDescription("Adding the encryption for the phone and SD card.");
|
feature9.setDescription("Adding the encryption for the phone and SD card.");
|
||||||
feature9.setRuleValue("permit_override");
|
// feature9.setRuleValue("permit_override");
|
||||||
feature9.setDeviceTypeId(1);
|
feature9.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature10 = new Feature();
|
Feature feature10 = new Feature();
|
||||||
|
feature10.setId(10);
|
||||||
feature10.setName("APP");
|
feature10.setName("APP");
|
||||||
feature10.setCode("A001");
|
feature10.setCode("A001");
|
||||||
feature10.setDescription("Installing an application to the phone");
|
feature10.setDescription("Installing an application to the phone");
|
||||||
feature10.setRuleValue("permit_override");
|
// feature10.setRuleValue("permit_override");
|
||||||
feature10.setDeviceTypeId(1);
|
feature10.setDeviceType("android");
|
||||||
|
|
||||||
Feature feature11 = new Feature();
|
Feature feature11 = new Feature();
|
||||||
|
feature11.setId(11);
|
||||||
feature11.setName("EMAIL");
|
feature11.setName("EMAIL");
|
||||||
feature11.setCode("E002");
|
feature11.setCode("E002");
|
||||||
feature11.setDescription("Email configurations of the phone.");
|
feature11.setDescription("Email configurations of the phone.");
|
||||||
feature11.setRuleValue("all_applicable");
|
// feature11.setRuleValue("all_applicable");
|
||||||
feature11.setDeviceTypeId(1);
|
feature11.setDeviceType("android");
|
||||||
|
|
||||||
|
|
||||||
List<Feature> featureList = new ArrayList<Feature>();
|
List<Feature> featureList = new ArrayList<Feature>();
|
||||||
|
|||||||
@ -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.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -49,14 +46,14 @@ public class PolicyCreator {
|
|||||||
policy.setPolicyName("New test Policy");
|
policy.setPolicyName("New test Policy");
|
||||||
policy.setGeneric(true);
|
policy.setGeneric(true);
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setDeviceList(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
|
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
|
||||||
|
|
||||||
List<String> roles = new ArrayList<String>();
|
List<String> roles = new ArrayList<String>();
|
||||||
roles.add("Role_01");
|
roles.add("Role_01");
|
||||||
roles.add("Role_02");
|
roles.add("Role_02");
|
||||||
roles.add("Role_03");
|
roles.add("Role_03");
|
||||||
|
|
||||||
policy.setRoleList(roles);
|
policy.setRoles(roles);
|
||||||
|
|
||||||
List<String> users = new ArrayList<String>();
|
List<String> users = new ArrayList<String>();
|
||||||
users.add("Geeth");
|
users.add("Geeth");
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
package org.wso2.carbon.policy.mgt.core.util;
|
package org.wso2.carbon.policy.mgt.core.util;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
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.policy.mgt.common.Profile;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.util;
|
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 org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -33,9 +33,12 @@ public class ProfileFeatureCreator {
|
|||||||
|
|
||||||
ProfileFeature profileFeature = new ProfileFeature();
|
ProfileFeature profileFeature = new ProfileFeature();
|
||||||
profileFeature.setContent(feature);
|
profileFeature.setContent(feature);
|
||||||
|
profileFeature.setDeviceTypeId(1);
|
||||||
|
profileFeature.setFeatureCode(feature.getCode());
|
||||||
|
|
||||||
// profileFeature.setContent("rrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
|
// profileFeature.setContent("rrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
|
||||||
// profileFeature.setProfileId(1);
|
// profileFeature.setProfileId(1);
|
||||||
profileFeature.setFeature(feature);
|
// profileFeature.setFeature(feature);
|
||||||
profileFeatureList.add(profileFeature);
|
profileFeatureList.add(profileFeature);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
-- Table DM_PROFILE_FEATURES
|
||||||
@ -159,19 +138,15 @@ CREATE TABLE IF NOT EXISTS DM_FEATURES (
|
|||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
|
||||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
ID INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
PROFILE_ID INT(11) NOT NULL ,
|
PROFILE_ID INT(11) NOT NULL,
|
||||||
FEATURE_ID INT(11) NOT NULL ,
|
FEATURE_CODE VARCHAR(10) NOT NULL,
|
||||||
CONTENT BLOB NULL DEFAULT NULL ,
|
DEVICE_TYPE_ID INT NOT NULL,
|
||||||
PRIMARY KEY (ID) ,
|
CONTENT BLOB NULL DEFAULT NULL,
|
||||||
CONSTRAINT FK_DM_POLICY_FEATURES_DM_FEATURES
|
PRIMARY KEY (ID),
|
||||||
FOREIGN KEY (FEATURE_ID )
|
|
||||||
REFERENCES DM_FEATURES (ID )
|
|
||||||
ON DELETE NO ACTION
|
|
||||||
ON UPDATE NO ACTION,
|
|
||||||
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
|
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
|
||||||
FOREIGN KEY (PROFILE_ID )
|
FOREIGN KEY (PROFILE_ID)
|
||||||
REFERENCES DM_PROFILE (ID )
|
REFERENCES DM_PROFILE (ID)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION)
|
ON UPDATE NO ACTION)
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,132 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
|||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
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.
|
-- 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 (1, 'android');
|
||||||
Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios');
|
--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user