Fixing bugs and fixing the criteria based policies

revert-70aa11f8
geethkokila 10 years ago
parent f83d919ed1
commit 38e09d49bb

@ -46,6 +46,10 @@ public class Policy implements Comparable<Policy>, Serializable {
private List<Device> devices; // 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;
/* Compliance data*/
private String Compliance;
/*Dynamic policy attributes*/ /*Dynamic policy attributes*/
/* This is related criteria based policy */ /* This is related criteria based policy */
@ -54,17 +58,17 @@ public class Policy implements Comparable<Policy>, Serializable {
/*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.
private int endTime; // After this time policy will not be applied // private int endTime; // After this time policy will not be applied
private Date startDate; // Start date to apply the policy // private Date startDate; // Start date to apply the policy
private Date endDate; // After this date policy will not be applied. // private Date endDate; // After this date policy will not be applied.
/*These are related to location based policies*/ /*These are related to location based policies*/
private String latitude; // Latitude // private String latitude; // Latitude
private String longitude; // Longitude // private String longitude; // Longitude
//
private int tenantId; private int tenantId;
private int profileId; private int profileId;
@ -171,58 +175,66 @@ public class Policy implements Comparable<Policy>, Serializable {
this.policyCriterias = policyCriterias; this.policyCriterias = policyCriterias;
} }
public int getStartTime() { public String getCompliance() {
return startTime; return Compliance;
} }
public void setStartTime(int startTime) { public void setCompliance(String compliance) {
this.startTime = startTime; Compliance = compliance;
} }
@XmlElement // public int getStartTime() {
public int getEndTime() { // return startTime;
return endTime; // }
} //
// public void setStartTime(int startTime) {
public void setEndTime(int endTime) { // this.startTime = startTime;
this.endTime = endTime; // }
} //
// @XmlElement
@XmlElement // public int getEndTime() {
public Date getStartDate() { // return endTime;
return startDate; // }
} //
// public void setEndTime(int endTime) {
public void setStartDate(Date startDate) { // this.endTime = endTime;
this.startDate = startDate; // }
} //
// @XmlElement
@XmlElement // public Date getStartDate() {
public Date getEndDate() { // return startDate;
return endDate; // }
} //
// public void setStartDate(Date startDate) {
public void setEndDate(Date endDate) { // this.startDate = startDate;
this.endDate = endDate; // }
} //
// @XmlElement
@XmlElement // public Date getEndDate() {
public String getLatitude() { // return endDate;
return latitude; // }
} //
// public void setEndDate(Date endDate) {
public void setLatitude(String latitude) { // this.endDate = endDate;
this.latitude = latitude; // }
} //
// @XmlElement
@XmlElement // public String getLatitude() {
public String getLongitude() { // return latitude;
return longitude; // }
} //
// public void setLatitude(String latitude) {
public void setLongitude(String longitude) { // this.latitude = latitude;
this.longitude = longitude; // }
} //
// @XmlElement
// public String getLongitude() {
// return longitude;
// }
//
// public void setLongitude(String longitude) {
// this.longitude = longitude;
// }
@XmlElement @XmlElement
public Map<String, Object> getAttributes() { public Map<String, Object> getAttributes() {

@ -1,43 +0,0 @@
/*
* 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.sql.Date;
public class PolicyDates {
private Date startDate; // Start date to apply the policy
private Date endDate; // After this date policy will not be applied.
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}

@ -1,41 +0,0 @@
/*
* 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 PolicyLocations {
private String latitude; // Latitude
private String longitude; // Longitude
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
}

@ -1,43 +0,0 @@
/*
* 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.sql.Date;
public class PolicyTimes {
private int startTime; // Start time to apply the policy.
private int endTime; // After this time policy will not be applied
public int getStartTime() {
return startTime;
}
public void setStartTime(int startTime) {
this.startTime = startTime;
}
public int getEndTime() {
return endTime;
}
public void setEndTime(int endTime) {
this.endTime = endTime;
}
}

@ -43,8 +43,6 @@ public interface FeatureDAO {
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException; FeatureManagerDAOException;
List<Feature> getAllFeatures() throws FeatureManagerDAOException;
List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException; List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException;
List<Feature> getAllFeatures(String deviceType) throws FeatureManagerDAOException; List<Feature> getAllFeatures(String deviceType) throws FeatureManagerDAOException;

@ -36,11 +36,11 @@ public interface PolicyDAO {
Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException; Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException;
Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException; // Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException;
//
Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException; // Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException;
//
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 addCriterion(Criterion criteria) throws PolicyManagerDAOException;
@ -86,11 +86,11 @@ public interface PolicyDAO {
List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException; List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException;
PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException; // PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException;
//
PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException; // PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException;
//
PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException; // PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException;
void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures) void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
throws PolicyManagerDAOException; throws PolicyManagerDAOException;

@ -30,10 +30,10 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import java.sql.Connection; import java.io.ByteArrayInputStream;
import java.sql.PreparedStatement; import java.io.IOException;
import java.sql.ResultSet; import java.io.ObjectInputStream;
import java.sql.SQLException; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -181,7 +181,11 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
stmt.setString(2, feature.getFeatureCode()); stmt.setString(2, feature.getFeatureCode());
stmt.setInt(3, feature.getDeviceTypeId()); stmt.setInt(3, feature.getDeviceTypeId());
stmt.setObject(4, feature.getContent()); if (conn.getMetaData().getDriverName().contains("H2")) {
stmt.setObject(4, feature.getContent(), Types.JAVA_OBJECT);
} else {
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
} }
@ -217,7 +221,11 @@ public class FeatureDAOImpl implements FeatureDAO {
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()); if (conn.getMetaData().getDriverName().contains("H2")) {
stmt.setObject(4, feature.getContent(), Types.JAVA_OBJECT);
} else {
stmt.setObject(4, feature.getContent());
}
stmt.setInt(2, profileId); stmt.setInt(2, profileId);
stmt.setString(3, feature.getFeatureCode()); stmt.setString(3, feature.getFeatureCode());
stmt.addBatch(); stmt.addBatch();
@ -259,42 +267,6 @@ public class FeatureDAOImpl implements FeatureDAO {
} }
@Override
public List<Feature> getAllFeatures() throws FeatureManagerDAOException {
// Connection conn;
// PreparedStatement stmt = null;
// ResultSet resultSet = null;
List<Feature> featureList = new ArrayList<Feature>();
//
// 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;
}
@Override @Override
public List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException { public List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException {
@ -322,8 +294,34 @@ public class FeatureDAOImpl implements FeatureDAO {
profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE")); profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); 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"));
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
byte[] contentBytes;
try {
contentBytes = (byte[]) resultSet.getBytes("CONTENT");
bais = new ByteArrayInputStream(contentBytes);
ois = new ObjectInputStream(bais);
profileFeature.setContent(ois.readObject().toString());
} finally {
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
}
featureList.add(profileFeature); featureList.add(profileFeature);
} }
@ -331,6 +329,14 @@ public class FeatureDAOImpl implements FeatureDAO {
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);
} catch (IOException e) {
String msg = "Unable to read the byte stream for content";
log.error(msg);
throw new FeatureManagerDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found while converting the object";
log.error(msg);
throw new FeatureManagerDAOException(msg, e);
} finally { } finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection(); this.closeConnection();
@ -395,17 +401,35 @@ public class FeatureDAOImpl implements FeatureDAO {
while (resultSet.next()) { while (resultSet.next()) {
ProfileFeature profileFeature = new ProfileFeature(); 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);
profileFeature.setId(resultSet.getInt("ID")); profileFeature.setId(resultSet.getInt("ID"));
profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE")); profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID")); profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
profileFeature.setContent(resultSet.getObject("CONTENT"));
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
byte[] contentBytes;
try {
contentBytes = resultSet.getBytes("CONTENT");
bais = new ByteArrayInputStream(contentBytes);
ois = new ObjectInputStream(bais);
profileFeature.setContent(ois.readObject().toString());
} finally {
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
}
featureList.add(profileFeature); featureList.add(profileFeature);
} }
@ -413,6 +437,14 @@ public class FeatureDAOImpl implements FeatureDAO {
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);
} catch (IOException e) {
String msg = "Unable to read the byte stream for content";
log.error(msg);
throw new FeatureManagerDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found while converting the object";
log.error(msg);
throw new FeatureManagerDAOException(msg, e);
} finally { } finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection(); this.closeConnection();

@ -142,81 +142,81 @@ public class PolicyDAOImpl implements PolicyDAO {
return policy; return policy;
} }
@Override // @Override
public Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException { // public Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException {
//
Connection conn; // Connection conn;
PreparedStatement stmt = null; // PreparedStatement stmt = null;
try { // try {
conn = this.getConnection(); // conn = this.getConnection();
String query = "INSERT INTO DM_DATE (START_DATE, END_DATE, POLICY_ID) VALUES (?, ?, ?)"; // String query = "INSERT INTO DM_DATE (START_DATE, END_DATE, POLICY_ID) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query); // stmt = conn.prepareStatement(query);
stmt.setDate(1, startDate); // stmt.setDate(1, startDate);
stmt.setDate(2, endDate); // stmt.setDate(2, endDate);
stmt.setInt(3, policy.getId()); // stmt.setInt(3, policy.getId());
stmt.executeUpdate(); // stmt.executeUpdate();
//
} catch (SQLException e) { // } catch (SQLException e) {
String msg = "Error occurred while adding the start date (" + startDate + ") and end date (" + // String msg = "Error occurred while adding the start date (" + startDate + ") and end date (" +
endDate + ") with policy to database."; // endDate + ") with policy to database.";
log.error(msg, e); // log.error(msg, e);
throw new PolicyManagerDAOException(msg, e); // throw new PolicyManagerDAOException(msg, e);
} finally { // } finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null); // PolicyManagementDAOUtil.cleanupResources(stmt, null);
} // }
return policy; // return policy;
} // }
@Override // @Override
public Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException { // public Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException {
//
Connection conn; // Connection conn;
PreparedStatement stmt = null; // PreparedStatement stmt = null;
try { // try {
conn = this.getConnection(); // conn = this.getConnection();
String query = "INSERT INTO DM_TIME (STARTING_TIME, ENDING_TIME, POLICY_ID) VALUES (?, ?, ?)"; // String query = "INSERT INTO DM_TIME (STARTING_TIME, ENDING_TIME, POLICY_ID) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query); // stmt = conn.prepareStatement(query);
stmt.setInt(1, startTime); // stmt.setInt(1, startTime);
stmt.setInt(2, endTime); // stmt.setInt(2, endTime);
stmt.setInt(3, policy.getId()); // stmt.setInt(3, policy.getId());
stmt.executeUpdate(); // stmt.executeUpdate();
//
} catch (SQLException e) { // } catch (SQLException e) {
String msg = "Error occurred while adding the start time (" + startTime + ") and end time (" + // String msg = "Error occurred while adding the start time (" + startTime + ") and end time (" +
endTime + ") with policy to database."; // endTime + ") with policy to database.";
log.error(msg, e); // log.error(msg, e);
throw new PolicyManagerDAOException(msg, e); // throw new PolicyManagerDAOException(msg, e);
} finally { // } finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null); // PolicyManagementDAOUtil.cleanupResources(stmt, null);
} // }
return policy; // return policy;
} // }
@Override // @Override
public Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws // public Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws
PolicyManagerDAOException { // PolicyManagerDAOException {
//
Connection conn; // Connection conn;
PreparedStatement stmt = null; // PreparedStatement stmt = null;
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, PreparedStatement.RETURN_GENERATED_KEYS); // 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());
stmt.executeUpdate(); // stmt.executeUpdate();
//
} catch (SQLException e) { // } catch (SQLException e) {
String msg = "Error occurred while adding the Location (" + latitude + ") (" + // String msg = "Error occurred while adding the Location (" + latitude + ") (" +
longitude + ") with policy to database."; // longitude + ") with policy to database.";
log.error(msg, e); // log.error(msg, e);
throw new PolicyManagerDAOException(msg, e); // throw new PolicyManagerDAOException(msg, e);
} finally { // } finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null); // PolicyManagementDAOUtil.cleanupResources(stmt, null);
} // }
return policy; // return policy;
} // }
@Override @Override
public Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException { public Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException {
@ -229,7 +229,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)"; String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setString(2, criteria.getName()); stmt.setString(2, criteria.getName());
stmt.executeUpdate(); stmt.executeUpdate();
@ -427,12 +427,12 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet generatedKeys; ResultSet generatedKeys = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_CRITERIA (CRITERIA_ID, POLICY_ID) VALUES (?, ?)"; String query = "INSERT INTO DM_POLICY_CRITERIA (CRITERIA_ID, POLICY_ID) VALUES (?, ?)";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
List<PolicyCriterion> criteria = policy.getPolicyCriterias(); List<PolicyCriterion> criteria = policy.getPolicyCriterias();
for (PolicyCriterion criterion : criteria) { for (PolicyCriterion criterion : criteria) {
@ -457,7 +457,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, null); PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
} }
return policy; return policy;
@ -472,21 +472,23 @@ public class PolicyDAOImpl implements PolicyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, KEY, VALUE, CONTENT) VALUES (?, ?, ?, ?)"; String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, CONTENT) VALUES (?, ?, ?, ?)";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
for (PolicyCriterion criterion : policyCriteria) { for (PolicyCriterion criterion : policyCriteria) {
for (String name : criterion.getProperties().stringPropertyNames()) { Properties prop = criterion.getProperties();
for (String name : prop.stringPropertyNames()) {
stmt.setInt(1, criterion.getId()); stmt.setInt(1, criterion.getId());
stmt.setString(2, name); stmt.setString(2, name);
stmt.setString(3, criterion.getProperties().getProperty(name)); stmt.setString(3, prop.getProperty(name));
stmt.setObject(4, criterion.getObjectMap()); stmt.setObject(4, criterion.getObjectMap());
stmt.addBatch(); stmt.addBatch();
} }
stmt.executeBatch();
} }
stmt.executeUpdate(); // stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while inserting the criterion properties to database."; String msg = "Error occurred while inserting the criterion properties to database.";
@ -510,7 +512,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT DPC.ID, DPC.CRITERIA_ID, DPCP.KEY, DPCP.VALUE, DPCP.CONTENT FROM " + String query = "SELECT DPC.ID, DPC.CRITERIA_ID, DPCP.PROP_KEY, DPCP.PROP_VALUE, DPCP.CONTENT FROM " +
"DM_POLICY_CRITERIA DPC LEFT JOIN DM_POLICY_CRITERIA_PROPERTIES DPCP " + "DM_POLICY_CRITERIA DPC LEFT JOIN DM_POLICY_CRITERIA_PROPERTIES DPCP " +
"ON DPCP.POLICY_CRITERION_ID = DPC.ID RIGHT JOIN DM_CRITERIA DC " + "ON DPCP.POLICY_CRITERION_ID = DPC.ID RIGHT JOIN DM_CRITERIA DC " +
"ON DC.ID=DPC.CRITERIA_ID WHERE DPC.POLICY_ID = ?"; "ON DC.ID=DPC.CRITERIA_ID WHERE DPC.POLICY_ID = ?";
@ -536,7 +538,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policyCriterion.setId(resultSet.getInt("ID")); policyCriterion.setId(resultSet.getInt("ID"));
policyCriterion.setCriteriaId(resultSet.getInt("CRITERIA_ID")); policyCriterion.setCriteriaId(resultSet.getInt("CRITERIA_ID"));
} else { } else {
prop.setProperty(resultSet.getString("KEY"), resultSet.getString("VALUE")); prop.setProperty(resultSet.getString("PROP_KEY"), resultSet.getString("PROP_VALUE"));
} }
} }
@ -558,13 +560,14 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null; PreparedStatement stmt = 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 = ?, COMPLIANCE = ? WHERE ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setString(1, policy.getPolicyName()); stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getTenantId()); stmt.setInt(2, policy.getTenantId());
stmt.setInt(3, policy.getProfile().getProfileId()); stmt.setInt(3, policy.getProfile().getProfileId());
stmt.setInt(4, policy.getPriorityId()); stmt.setInt(4, policy.getPriorityId());
stmt.setInt(5, policy.getId()); stmt.setString(5, policy.getCompliance());
stmt.setInt(6, policy.getId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -597,6 +600,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setTenantId(resultSet.getInt("TENANT_ID")); policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY")); policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setProfileId(resultSet.getInt("PROFILE_ID")); policy.setProfileId(resultSet.getInt("PROFILE_ID"));
policy.setCompliance(resultSet.getString("COMPLIANCE"));
} }
return policy; return policy;
@ -630,6 +634,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setPolicyName(resultSet.getString("NAME")); policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID")); policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY")); policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setCompliance(resultSet.getString("COMPLIANCE"));
} }
return policy; return policy;
@ -664,6 +669,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setPolicyName(resultSet.getString("NAME")); policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID")); policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY")); policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setCompliance(resultSet.getString("COMPLIANCE"));
policies.add(policy); policies.add(policy);
} }
return policies; return policies;
@ -746,108 +752,98 @@ public class PolicyDAOImpl implements PolicyDAO {
} }
public PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException { // public PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException {
//
Connection conn; // Connection conn;
PreparedStatement stmt = null; // PreparedStatement stmt = null;
ResultSet resultSet = null; // ResultSet resultSet = null;
PolicyTimes times = new PolicyTimes(); // PolicyTimes times = new PolicyTimes();
//
try { // try {
conn = this.getConnection(); // conn = this.getConnection();
String query = "SELECT STARTING_TIME, ENDING_TIME FROM DM_TIME WHERE POLICY_ID = ?"; // String query = "SELECT STARTING_TIME, ENDING_TIME FROM DM_TIME WHERE POLICY_ID = ?";
stmt = conn.prepareStatement(query); // stmt = conn.prepareStatement(query);
stmt.setInt(1, policy.getId()); // stmt.setInt(1, policy.getId());
resultSet = stmt.executeQuery(); // resultSet = stmt.executeQuery();
//
while (resultSet.next()) { // while (resultSet.next()) {
policy.setStartTime(resultSet.getInt("STARTING_TIME")); //
policy.setEndTime(resultSet.getInt("ENDING_TIME")); // times.setStartTime(resultSet.getInt("STARTING_TIME"));
// times.setEndTime(resultSet.getInt("ENDING_TIME"));
times.setStartTime(resultSet.getInt("STARTING_TIME")); // }
times.setEndTime(resultSet.getInt("ENDING_TIME")); //
} // } catch (SQLException e) {
// String msg = "Error occurred while getting the start time and end time related to policies.";
} catch (SQLException e) { // log.error(msg, e);
String msg = "Error occurred while getting the start time and end time related to policies."; // throw new PolicyManagerDAOException(msg, e);
log.error(msg, e); // } finally {
throw new PolicyManagerDAOException(msg, e); // PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
} finally { // this.closeConnection();
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); // }
this.closeConnection(); // return times;
} // }
return times;
}
// public PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException {
//
public PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException { // Connection conn;
// PreparedStatement stmt = null;
Connection conn; // ResultSet resultSet = null;
PreparedStatement stmt = null; // PolicyDates dates = new PolicyDates();
ResultSet resultSet = null; //
PolicyDates dates = new PolicyDates(); // try {
// conn = this.getConnection();
try { // String query = "SELECT START_DATE, END_DATE FROM DM_DATE WHERE POLICY_ID = ?";
conn = this.getConnection(); // stmt = conn.prepareStatement(query);
String query = "SELECT START_DATE, END_DATE FROM DM_DATE WHERE POLICY_ID = ?"; // stmt.setInt(1, policy.getId());
stmt = conn.prepareStatement(query); // resultSet = stmt.executeQuery();
stmt.setInt(1, policy.getId()); //
resultSet = stmt.executeQuery(); // while (resultSet.next()) {
// dates.setStartDate(resultSet.getDate("START_DATE"));
while (resultSet.next()) { // dates.setEndDate(resultSet.getDate("END_DATE"));
// }
policy.setStartDate(resultSet.getDate("START_DATE")); //
policy.setEndDate(resultSet.getDate("END_DATE")); // } catch (SQLException e) {
// String msg = "Error occurred while getting the start date and end date related to policies.";
dates.setStartDate(resultSet.getDate("START_DATE")); // log.error(msg, e);
dates.setEndDate(resultSet.getDate("END_DATE")); // throw new PolicyManagerDAOException(msg, e);
} // } finally {
// PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
} catch (SQLException e) { // this.closeConnection();
String msg = "Error occurred while getting the start date and end date related to policies."; // }
log.error(msg, e); // return dates;
throw new PolicyManagerDAOException(msg, e); // }
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection(); // public PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException {
} //
return dates; // Connection conn;
} // PreparedStatement stmt = null;
// ResultSet resultSet = null;
// PolicyLocations locations = new PolicyLocations();
public PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException { //
// try {
Connection conn; // conn = this.getConnection();
PreparedStatement stmt = null; // String query = "SELECT LATITUDE, LONGITUDE FROM DM_LOCATION WHERE POLICY_ID = ?";
ResultSet resultSet = null; // stmt = conn.prepareStatement(query);
PolicyLocations locations = new PolicyLocations(); // stmt.setInt(1, policy.getId());
// resultSet = stmt.executeQuery();
try { //
conn = this.getConnection(); // while (resultSet.next()) {
String query = "SELECT LATITUDE, LONGITUDE FROM DM_LOCATION WHERE POLICY_ID = ?"; // locations.setLatitude(resultSet.getString("LATITUDE"));
stmt = conn.prepareStatement(query); // locations.setLongitude(resultSet.getString("LONGITUDE"));
stmt.setInt(1, policy.getId()); // }
resultSet = stmt.executeQuery(); //
// } catch (SQLException e) {
while (resultSet.next()) { // String msg = "Error occurred while getting the start time and end time related to policies.";
// log.error(msg, e);
policy.setLatitude(resultSet.getString("LATITUDE")); // throw new PolicyManagerDAOException(msg, e);
policy.setLongitude(resultSet.getString("LONGITUDE")); // } finally {
// PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
locations.setLatitude(resultSet.getString("LATITUDE")); // this.closeConnection();
locations.setLongitude(resultSet.getString("LONGITUDE")); // }
} // return locations;
// }
} catch (SQLException e) {
String msg = "Error occurred while getting the start time and end time related to policies.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
}
return locations;
}
@Override @Override
public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures) public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
@ -1161,13 +1157,14 @@ public class PolicyDAOImpl implements PolicyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY) VALUES (?, ?, ?, ?)"; String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, policy.getPolicyName()); stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getProfile().getProfileId()); stmt.setInt(2, policy.getProfile().getProfileId());
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setInt(4, readHighestPriorityOfPolicies()); stmt.setInt(4, readHighestPriorityOfPolicies());
stmt.setString(5, policy.getCompliance());
int affectedRows = stmt.executeUpdate(); int affectedRows = stmt.executeUpdate();

@ -0,0 +1,35 @@
/*
* 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.impl;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.List;
public interface PolicyFilter {
void filterRolesBasedPolicies(String roles[], List<Policy> policies);
void filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies);
void filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies);
}

@ -0,0 +1,83 @@
/*
* 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.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
import java.util.ArrayList;
import java.util.List;
public class PolicyFilterImpl implements PolicyFilter {
private static final Log log = LogFactory.getLog(PolicyFilterImpl.class);
@Override
public void filterRolesBasedPolicies(String roles[], List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) {
List<String> tempRoles = policy.getRoles();
if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) {
temp.add(policy);
continue;
}
for (String role : roles) {
for (String policyRole : tempRoles) {
if (role.equalsIgnoreCase(policyRole)) {
temp.add(policy);
continue;
}
}
}
}
policies = temp;
}
@Override
public void filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) {
if (ownershipType.equalsIgnoreCase(policy.getOwnershipType())) {
temp.add(policy);
}
}
policies = temp;
}
@Override
public void filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) {
if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) {
temp.add(policy);
}
}
policies = temp;
}
}

@ -92,19 +92,30 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
@Override @Override
public List<Policy> getRelatedPolicies(PIPDevice pipDevice) throws PolicyManagementException { public List<Policy> getRelatedPolicies(PIPDevice pipDevice) throws PolicyManagementException {
List<List<Policy>> policies = new ArrayList<List<Policy>>(); // List<List<Policy>> policies = new ArrayList<List<Policy>>();
List<Policy> policies = new ArrayList<Policy>();
try { try {
// Get the device type related policies // Get the device type related policies
policies.add(policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName())); // policies.add(policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName()));
// Get the roles related policies
for (String role : pipDevice.getRoles()) {
policies.add(policyManager.getPoliciesOfRole(role));
}
// Get policy related to the device
policies.add(policyManager.getPoliciesOfDevice(pipDevice.getDeviceIdentifier()));
return removeDuplicatePolicies(policies); // Commented out because these are already taken when device type based policies retrieved
// // Get the roles related policies
// for (String role : pipDevice.getRoles()) {
// policies.add(policyManager.getPoliciesOfRole(role));
// }
// // Get policy related to the device
// policies.add(policyManager.getPoliciesOfDevice(pipDevice.getDeviceIdentifier()));
policies = policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName());
PolicyFilter policyFilter = new PolicyFilterImpl();
policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies);
policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies);
policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies);
return policies;
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred when retrieving related to given device " + String msg = "Error occurred when retrieving related to given device " +
pipDevice.getDeviceIdentifier().getId() + " " + pipDevice.getDeviceIdentifier().getType() + "."; pipDevice.getDeviceIdentifier().getId() + " " + pipDevice.getDeviceIdentifier().getType() + ".";

@ -45,7 +45,6 @@ public interface FeatureManager {
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagementException; List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagementException;
List<Feature> getAllFeatures() throws FeatureManagementException;
List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException; List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException;

@ -274,16 +274,6 @@ public class FeatureManagerImpl implements FeatureManager {
return features; return features;
} }
@Override
public List<Feature> getAllFeatures() throws FeatureManagementException {
try {
return featureDAO.getAllFeatures();
} catch (FeatureManagerDAOException e) {
String msg = "Error occurred while getting the features.";
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
}
@Override @Override
public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException { public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException {

@ -39,7 +39,7 @@ public class PolicyManagerImpl implements PolicyManager {
private ProfileDAO profileDAO; private ProfileDAO profileDAO;
private FeatureDAO featureDAO; private FeatureDAO featureDAO;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
// private DeviceTypeDAO deviceTypeDAO; // private DeviceTypeDAO deviceTypeDAO;
private ProfileManager profileManager; private ProfileManager profileManager;
private static Log log = LogFactory.getLog(PolicyManagerImpl.class); private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
@ -83,6 +83,7 @@ public class PolicyManagerImpl implements PolicyManager {
Criterion criteriaObj = new Criterion(); Criterion criteriaObj = new Criterion();
criteriaObj.setName(criterion.getName()); criteriaObj.setName(criterion.getName());
policyDAO.addCriterion(criteriaObj); policyDAO.addCriterion(criteriaObj);
criterion.setCriteriaId(criteriaObj.getId());
} }
} }
@ -90,17 +91,17 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias()); policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
} }
if (policy.getEndDate() != null & policy.getStartDate() != null) { // if (policy.getEndDate() != null & policy.getStartDate() != null) {
policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy); // policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy);
} // }
//
if (policy.getStartTime() != 0 & policy.getEndTime() != 0) { // if (policy.getStartTime() != 0 & policy.getEndTime() != 0) {
policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy); // policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy);
} // }
//
if (policy.getLatitude() != null && policy.getLongitude() != null) { // if (policy.getLatitude() != null && policy.getLongitude() != null) {
policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy); // policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy);
} // }
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
@ -165,6 +166,7 @@ public class PolicyManagerImpl implements PolicyManager {
Criterion criteriaObj = new Criterion(); Criterion criteriaObj = new Criterion();
criteriaObj.setName(criterion.getName()); criteriaObj.setName(criterion.getName());
policyDAO.addCriterion(criteriaObj); policyDAO.addCriterion(criteriaObj);
criterion.setCriteriaId(criteriaObj.getId());
} }
} }
@ -172,17 +174,17 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias()); policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
} }
if (policy.getEndDate() != null & policy.getStartDate() != null) { // if (policy.getEndDate() != null & policy.getStartDate() != null) {
policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy); // policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy);
} // }
//
if (policy.getStartTime() != 0 & policy.getEndTime() != 0) { // if (policy.getStartTime() != 0 & policy.getEndTime() != 0) {
policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy); // policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy);
} // }
//
if (policy.getLatitude() != null && policy.getLongitude() != null) { // if (policy.getLatitude() != null && policy.getLongitude() != null) {
policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy); // policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy);
} // }
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
@ -362,9 +364,9 @@ public class PolicyManagerImpl implements PolicyManager {
policy = policyDAO.getPolicyByProfileID(profileId); policy = policyDAO.getPolicyByProfileID(profileId);
deviceList = getPolicyAppliedDevicesIds(policy.getId()); deviceList = getPolicyAppliedDevicesIds(policy.getId());
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId()); roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
policyDAO.getDatesOfPolicy(policy); // policyDAO.getDatesOfPolicy(policy);
policyDAO.getTimesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);
policyDAO.getLocationsOfPolicy(policy); // policyDAO.getLocationsOfPolicy(policy);
profile = profileDAO.getProfiles(profileId); profile = profileDAO.getProfiles(profileId);
@ -395,9 +397,9 @@ public class PolicyManagerImpl implements PolicyManager {
policy = policyDAO.getPolicy(policyId); policy = policyDAO.getPolicy(policyId);
deviceList = getPolicyAppliedDevicesIds(policyId); deviceList = getPolicyAppliedDevicesIds(policyId);
roleNames = policyDAO.getPolicyAppliedRoles(policyId); roleNames = policyDAO.getPolicyAppliedRoles(policyId);
policyDAO.getDatesOfPolicy(policy); // policyDAO.getDatesOfPolicy(policy);
policyDAO.getTimesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);
policyDAO.getLocationsOfPolicy(policy); // policyDAO.getLocationsOfPolicy(policy);
Profile profile = profileDAO.getProfiles(policy.getProfileId()); Profile profile = profileDAO.getProfiles(policy.getProfileId());
@ -424,7 +426,8 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
policyList = policyDAO.getAllPolicies(); policyList = policyDAO.getAllPolicies();
List<Profile> profileList = profileDAO.getAllProfiles(); // List<Profile> profileList = profileDAO.getAllProfiles();
List<Profile> profileList = profileManager.getAllProfiles();
for (Policy policy : policyList) { for (Policy policy : policyList) {
for (Profile profile : profileList) { for (Profile profile : profileList) {
@ -434,16 +437,17 @@ public class PolicyManagerImpl implements PolicyManager {
} }
policy.setDevices(getPolicyAppliedDevicesIds(policy.getId())); policy.setDevices(getPolicyAppliedDevicesIds(policy.getId()));
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId())); policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
policyDAO.getDatesOfPolicy(policy); policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
policyDAO.getTimesOfPolicy(policy); // policyDAO.getDatesOfPolicy(policy);
policyDAO.getLocationsOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);
// policyDAO.getLocationsOfPolicy(policy);
} }
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
String msg = "Error occurred while getting all the policies."; String msg = "Error occurred while getting all the policies.";
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) { } catch (ProfileManagementException e) {
String msg = "Error occurred while getting all the profiles."; String msg = "Error occurred while getting all the profiles.";
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
@ -459,7 +463,7 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
Device device = deviceDAO.getDevice(deviceIdentifier); Device device = deviceDAO.getDevice(deviceIdentifier);
policyIdList = policyDAO.getPolicyIdsOfDevice(device); policyIdList = policyDAO.getPolicyIdsOfDevice(device);
List<Policy> tempPolicyList = policyDAO.getAllPolicies(); List<Policy> tempPolicyList = this.getPolicies();
for (Policy policy : tempPolicyList) { for (Policy policy : tempPolicyList) {
for (Integer i : policyIdList) { for (Integer i : policyIdList) {
@ -492,7 +496,7 @@ public class PolicyManagerImpl implements PolicyManager {
// DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName); // DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName); List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
List<Policy> allPolicies = policyDAO.getAllPolicies(); List<Policy> allPolicies = this.getPolicies();
for (Profile profile : profileList) { for (Profile profile : profileList) {
@ -504,10 +508,10 @@ public class PolicyManagerImpl implements PolicyManager {
} }
} }
} catch (PolicyManagerDAOException e) { // } catch (PolicyManagerDAOException e) {
String msg = "Error occurred while getting all the policies."; // String msg = "Error occurred while getting all the policies.";
log.error(msg, e); // log.error(msg, e);
throw new PolicyManagementException(msg, e); // throw new PolicyManagementException(msg, e);
// } catch (ProfileManagerDAOException e) { // } catch (ProfileManagerDAOException e) {
// String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")"; // String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
// log.error(msg, e); // log.error(msg, e);
@ -532,7 +536,7 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
policyIdList = policyDAO.getPolicyOfRole(roleName); policyIdList = policyDAO.getPolicyOfRole(roleName);
List<Policy> tempPolicyList = policyDAO.getAllPolicies(); List<Policy> tempPolicyList = this.getPolicies();
for (Policy policy : tempPolicyList) { for (Policy policy : tempPolicyList) {
for (Integer i : policyIdList) { for (Integer i : policyIdList) {
@ -558,7 +562,7 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
policyIdList = policyDAO.getPolicyOfUser(username); policyIdList = policyDAO.getPolicyOfUser(username);
List<Policy> tempPolicyList = policyDAO.getAllPolicies(); List<Policy> tempPolicyList = this.getPolicies();
for (Policy policy : tempPolicyList) { for (Policy policy : tempPolicyList) {
for (Integer i : policyIdList) { for (Integer i : policyIdList) {

@ -19,5 +19,8 @@
package org.wso2.carbon.policy.mgt.core.util; package org.wso2.carbon.policy.mgt.core.util;
public final class PolicyManagementConstants { public final class PolicyManagementConstants {
public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml"; public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml";
public static final String ANY = "ANY";
} }

@ -32,13 +32,7 @@ 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.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.*;
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.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.core.common.DBTypes; import org.wso2.carbon.policy.mgt.core.common.DBTypes;
import org.wso2.carbon.policy.mgt.core.common.TestDBConfiguration; import org.wso2.carbon.policy.mgt.core.common.TestDBConfiguration;
import org.wso2.carbon.policy.mgt.core.common.TestDBConfigurations; import org.wso2.carbon.policy.mgt.core.common.TestDBConfigurations;
@ -62,6 +56,7 @@ import java.sql.Connection;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties;
public class PolicyDAOTestCase { public class PolicyDAOTestCase {
@ -250,6 +245,15 @@ public class PolicyDAOTestCase {
policyManager.addPolicy(policy); policyManager.addPolicy(policy);
} }
@Test(dependsOnMethods = ("addPolicyToDevice"))
public void addThirdPolicy() throws PolicyManagementException {
PolicyManager policyManager = new PolicyManagerImpl();
policy = PolicyCreator.createPolicy4(profile);
policyManager.addPolicy(policy);
}
@Test(dependsOnMethods = ("addNewPolicy")) @Test(dependsOnMethods = ("addNewPolicy"))
public void getPolicies() throws PolicyManagementException { public void getPolicies() throws PolicyManagementException {
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl(); PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
@ -302,5 +306,66 @@ public class PolicyDAOTestCase {
} }
} }
@Test(dependsOnMethods = ("getRoleRelatedPolicy"))
public void addSecondPolicy() throws PolicyManagementException {
PolicyManager policyManager = new PolicyManagerImpl();
policy = PolicyCreator.createPolicy3(profile);
policyManager.addPolicy(policy);
}
@Test(dependsOnMethods = ("getDeviceTypeRelatedPolicy"))
public void getRoleRelatedPolicySecondTime() throws PolicyManagementException {
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
List<Policy> policyList = policyAdministratorPoint.getPoliciesOfRole("Role_01");
log.debug("----------Roles related policy second time ---------");
for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
for (ProfileFeature profileFeature : profileFeatures) {
log.debug("Feature Content" + profileFeature.getId() + " - " + profileFeature.getContent());
}
}
}
@Test(dependsOnMethods = ("getRoleRelatedPolicySecondTime"))
public void getRoleRelatedPolicyThirdTime() throws PolicyManagementException {
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
List<Policy> policyList = policyAdministratorPoint.getPoliciesOfRole("Role_02");
log.debug("----------Roles related policy third time ---------");
for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
// for (ProfileFeature profileFeature : profileFeatures) {
// log.debug("Feature Content" + profileFeature.getId() + " - " + profileFeature.getContent());
// }
List<PolicyCriterion> criteria = policy.getPolicyCriterias();
for (PolicyCriterion criterion : criteria) {
log.debug("Criterias " + criterion.getName() + " -- " + criterion.getCriteriaId() + " -- "
+ criterion.getId());
Properties prop = criterion.getProperties();
for (String key : prop.stringPropertyNames()) {
log.debug("Property Names : " + key + " -- " + prop.getProperty(key));
}
}
}
}
} }

@ -19,10 +19,12 @@
package org.wso2.carbon.policy.mgt.core.util; 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.PolicyCriterion;
import org.wso2.carbon.policy.mgt.common.Profile; import org.wso2.carbon.policy.mgt.common.Profile;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties;
public class PolicyCreator { public class PolicyCreator {
@ -35,6 +37,7 @@ public class PolicyCreator {
List<String> users = new ArrayList<String>(); List<String> users = new ArrayList<String>();
users.add("Dilshan"); users.add("Dilshan");
policy.setUsers(users); policy.setUsers(users);
policy.setCompliance("ENFORCE");
return policy; return policy;
} }
@ -43,11 +46,13 @@ public class PolicyCreator {
public static Policy createPolicy2(Profile profile) { public static Policy createPolicy2(Profile profile) {
Policy policy = new Policy(); Policy policy = new Policy();
policy.setPolicyName("New test Policy"); policy.setPolicyName("Test_Policy_02");
policy.setGeneric(true); policy.setGeneric(true);
policy.setProfile(profile); policy.setProfile(profile);
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType())); policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
policy.setCompliance("NOTIFY");
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");
@ -63,8 +68,128 @@ public class PolicyCreator {
policy.setUsers(users); policy.setUsers(users);
policy.setLatitude("6.927079");
policy.setLongitude("79.861243"); PolicyCriterion criterion = new PolicyCriterion();
Properties prop = new Properties();
prop.put("Start_time", "10.00 AM");
prop.put("End_time", "4.00 PM");
criterion.setProperties(prop);
criterion.setName("Time");
List<PolicyCriterion> criteria = new ArrayList<PolicyCriterion>();
criteria.add(criterion);
policy.setPolicyCriterias(criteria);
//
// policy.setLatitude("6.927079");
// policy.setLongitude("79.861243");
/* DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd ");
java.util.Date date = new java.util.Date();
policy.setStartDate(new java.sql.Timestamp(date.getDate()));*/
return policy;
}
public static Policy createPolicy3(Profile profile) {
Policy policy = new Policy();
policy.setPolicyName("Test_Policy_03");
policy.setGeneric(true);
policy.setProfile(profile);
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
List<String> roles = new ArrayList<String>();
roles.add("Role_01");
roles.add("Role_02");
policy.setRoles(roles);
policy.setCompliance("ENFORCE");
// List<String> users = new ArrayList<String>();
// users.add("Geeth");
// users.add("Manoj");
// users.add("Milan");
// users.add("Dulitha");
//
// policy.setUsers(users);
PolicyCriterion criterion = new PolicyCriterion();
Properties prop = new Properties();
prop.put("Start_time", "10.00 AM");
prop.put("End_time", "4.00 PM");
criterion.setProperties(prop);
criterion.setName("Location");
List<PolicyCriterion> criteria = new ArrayList<PolicyCriterion>();
criteria.add(criterion);
policy.setPolicyCriterias(criteria);
/* DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd ");
java.util.Date date = new java.util.Date();
policy.setStartDate(new java.sql.Timestamp(date.getDate()));*/
return policy;
}
public static Policy createPolicy4(Profile profile) {
Policy policy = new Policy();
policy.setPolicyName("Test_Policy_04");
policy.setGeneric(true);
policy.setProfile(profile);
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
policy.setCompliance("MONITOR");
List<String> roles = new ArrayList<String>();
roles.add("Role_04");
roles.add("Role_05");
roles.add("Role_02");
policy.setRoles(roles);
List<String> users = new ArrayList<String>();
users.add("Geeth");
users.add("Manoj");
users.add("Milan");
users.add("Dulitha");
policy.setUsers(users);
PolicyCriterion criterion = new PolicyCriterion();
Properties prop = new Properties();
prop.put("Start_time", "10.00 AM");
prop.put("End_time", "4.00 PM");
criterion.setProperties(prop);
criterion.setName("LOCATIONGGGGG");
List<PolicyCriterion> criteria = new ArrayList<PolicyCriterion>();
criteria.add(criterion);
policy.setPolicyCriterias(criteria);
// policy.setLatitude("6.927079");
// policy.setLongitude("79.861243");
/* DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd "); /* DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd ");
java.util.Date date = new java.util.Date(); java.util.Date date = new java.util.Date();

@ -23,25 +23,103 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class ProfileFeatureCreator { public class ProfileFeatureCreator {
public static List<ProfileFeature> getProfileFeature(List<Feature> features) { public static List<ProfileFeature> getProfileFeature(List<Feature> features) {
List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>(); List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>();
int i = 0;
for (Feature feature : features) { for (Feature feature : features) {
ProfileFeature profileFeature = new ProfileFeature(); ProfileFeature profileFeature = new ProfileFeature();
profileFeature.setContent(feature); if (i % 2 == 0) {
profileFeature.setContent( getJSON());
} else {
profileFeature.setContent(getJSON2());
}
profileFeature.setDeviceTypeId(1); profileFeature.setDeviceTypeId(1);
profileFeature.setFeatureCode(feature.getCode()); 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);
i++;
} }
return profileFeatureList; return profileFeatureList;
} }
private static String getJSON() {
return "[\n" +
"\t{\n" +
"\t\tcolor: \"red\",\n" +
"\t\tvalue: \"#f00\"\n" +
"\t},\n" +
"\t{\n" +
"\t\tcolor: \"green\",\n" +
"\t\tvalue: \"#0f0\"\n" +
"\t},\n" +
"\t{\n" +
"\t\tcolor: \"blue\",\n" +
"\t\tvalue: \"#00f\"\n" +
"\t},\n" +
"\t{\n" +
"\t\tcolor: \"cyan\",\n" +
"\t\tvalue: \"#0ff\"\n" +
"\t},\n" +
"\t{\n" +
"\t\tcolor: \"magenta\",\n" +
"\t\tvalue: \"#f0f\"\n" +
"\t},\n" +
"\t{\n" +
"\t\tcolor: \"yellow\",\n" +
"\t\tvalue: \"#ff0\"\n" +
"\t},\n" +
"\t{\n" +
"\t\tcolor: \"black\",\n" +
"\t\tvalue: \"#000\"\n" +
"\t}\n" +
"]";
}
private static String getJSON2() {
return "{\n" +
" \"odata.metadata\":\"http://services.odata.org/V3/OData/OData.svc/$metadata#Products\",\n" +
" \"value\":[\n" +
" {\n" +
" \"ID\":0,\n" +
" \"Name\":\"Bread\",\n" +
" \"Description\":\"Whole grain bread\",\n" +
" \"ReleaseDate\":\"1992-01-01T00:00:00\",\n" +
" \"DiscontinuedDate\":null,\n" +
" \"Rating\":4,\n" +
" \"Price\":\"2.5\"\n" +
" },\n" +
" {\n" +
" \"ID\":1,\n" +
" \"Name\":\"Milk\",\n" +
" \"Description\":\"Low fat milk\",\n" +
" \"ReleaseDate\":\"1995-10-01T00:00:00\",\n" +
" \"DiscontinuedDate\":null,\n" +
" \"Rating\":3,\n" +
" \"Price\":\"3.5\"\n" +
" },\n" +
" {\n" +
" \"ID\":2,\n" +
" \"Name\":\"Vint soda\",\n" +
" \"Description\":\"Americana Variety - Mix of 6 flavors\",\n" +
" \"ReleaseDate\":\"2000-10-01T00:00:00\",\n" +
" \"DiscontinuedDate\":null,\n" +
" \"Rating\":3,\n" +
" \"Price\":\"20.9\"\n" +
" },\n" +
" …\n" +
" ]\n" +
"}";
}
} }

@ -72,6 +72,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
NAME VARCHAR(45) NULL DEFAULT NULL , NAME VARCHAR(45) NULL DEFAULT NULL ,
TENANT_ID INT(11) NOT NULL , TENANT_ID INT(11) NOT NULL ,
PROFILE_ID INT(11) NOT NULL , PROFILE_ID INT(11) NOT NULL ,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL , PRIORITY INT NOT NULL ,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_PROFILE_DM_POLICY CONSTRAINT FK_DM_PROFILE_DM_POLICY
@ -172,56 +173,6 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
; ;
-- -----------------------------------------------------
-- Table DM_LOCATION
-- -----------------------------------------------------
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)
;
-- -----------------------------------------------------
-- Table DM_TIME
-- -----------------------------------------------------
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)
;
-- -----------------------------------------------------
-- Table DM_DATE
-- -----------------------------------------------------
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)
;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table .DM_USER_POLICY -- Table .DM_USER_POLICY
@ -263,3 +214,59 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
; ;
-- -----------------------------------------------------
-- Table DM_CRITERIA
-- -----------------------------------------------------
DROP TABLE IF EXISTS DM_CRITERIA ;
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
ID INT NOT NULL AUTO_INCREMENT,
TENANT_ID INT NOT NULL,
NAME VARCHAR(50) NULL,
PRIMARY KEY (ID)
);
-- -----------------------------------------------------
-- Table DM_POLICY_CRITERIA
-- -----------------------------------------------------
DROP TABLE IF EXISTS DM_POLICY_CRITERIA ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ID INT NOT NULL AUTO_INCREMENT,
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
FOREIGN KEY (CRITERIA_ID)
REFERENCES DM_CRITERIA (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_POLICY_POLICY_CRITERIA
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_POLICY_CRITERIA_PROPERTIES
-- -----------------------------------------------------
DROP TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT,
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL,
CONTENT BLOB NULL COMMENT 'This is used to ',
PRIMARY KEY (ID),
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
FOREIGN KEY (POLICY_CRITERION_ID)
REFERENCES DM_POLICY_CRITERIA (ID)
ON DELETE CASCADE
ON UPDATE NO ACTION
);

@ -1,8 +1,19 @@
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema WSO2CDM
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `WSO2CDM` ; -- -----------------------------------------------------
-- Schema WSO2CDM
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ; CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ;
USE `WSO2CDM` ; USE `WSO2CDM` ;
@ -11,36 +22,31 @@ USE `WSO2CDM` ;
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(300) NULL DEFAULT NULL , `NAME` VARCHAR(300) NULL DEFAULT NULL,
PRIMARY KEY (`ID`) ) PRIMARY KEY (`ID`))
ENGINE = InnoDB ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1; DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE` -- Table `WSO2CDM`.`DM_PROFILE`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`DESCRIPTION` TEXT NULL DEFAULT NULL , `PROFILE_NAME` VARCHAR(45) NOT NULL,
`NAME` VARCHAR(100) NULL DEFAULT NULL , `TENANT_ID` INT(11) NOT NULL,
`DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL , `DEVICE_TYPE_ID` INT(11) NOT NULL,
`DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL , `CREATED_TIME` DATETIME NOT NULL,
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL , `UPDATED_TIME` DATETIME NOT NULL,
`STATUS` VARCHAR(15) NULL DEFAULT NULL , PRIMARY KEY (`ID`),
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL , INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC),
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL , CONSTRAINT `DM_PROFILE_DEVICE_TYPE`
`OWNER` VARCHAR(45) NULL DEFAULT NULL , FOREIGN KEY (`DEVICE_TYPE_ID`)
`TENANT_ID` INT(11) NULL DEFAULT '0' , REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID`)
PRIMARY KEY (`ID`) ,
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) ,
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
FOREIGN KEY (`DEVICE_TYPE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
@ -48,43 +54,41 @@ DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_PROFILE` -- Table `WSO2CDM`.`DM_POLICY`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` (
`ID` INT NOT NULL AUTO_INCREMENT , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`PROFILE_NAME` VARCHAR(45) NOT NULL , `NAME` VARCHAR(45) NULL DEFAULT NULL,
`TENANT_ID` INT NOT NULL , `TENANT_ID` INT(11) NOT NULL,
`DEVICE_TYPE_ID` INT NOT NULL , `PROFILE_ID` INT(11) NOT NULL,
`CREATED_TIME` DATETIME NOT NULL , `COMPLIANCE` VARCHAR(100) NULL,
`UPDATED_TIME` DATETIME NOT NULL , `PRIORITY` INT(11) NOT NULL,
PRIMARY KEY (`ID`) , PRIMARY KEY (`ID`),
INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC),
CONSTRAINT `DM_PROFILE_DEVICE_TYPE` CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
FOREIGN KEY (`DEVICE_TYPE_ID` ) FOREIGN KEY (`PROFILE_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_POLICY` -- Table `WSO2CDM`.`DM_DATE`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_DATE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DATE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT , `START_DATE` DATE NOT NULL,
`NAME` VARCHAR(45) NULL DEFAULT NULL , `END_DATE` DATE NOT NULL,
`TENANT_ID` INT(11) NOT NULL , `POLICY_ID` INT(11) NOT NULL,
`PROFILE_ID` INT(11) NOT NULL , INDEX `DM_DATE_POLICY` (`POLICY_ID` ASC),
`PRIORITY` INT NOT NULL , CONSTRAINT `DM_DATE_POLICY`
PRIMARY KEY (`ID`) , FOREIGN KEY (`POLICY_ID`)
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) , REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
FOREIGN KEY (`PROFILE_ID` )
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
@ -92,25 +96,27 @@ DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE_POLICY` -- Table `WSO2CDM`.`DM_DEVICE`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`DEVICE_ID` INT(11) NOT NULL , `DESCRIPTION` TEXT NULL DEFAULT NULL,
`POLICY_ID` INT(11) NOT NULL , `NAME` VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (`ID`) , `DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL,
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) , `DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL,
INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC) , `OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL,
CONSTRAINT `FK_POLICY_DEVICE_POLICY` `STATUS` VARCHAR(15) NULL DEFAULT NULL,
FOREIGN KEY (`POLICY_ID` ) `DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL,
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) `DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL,
ON DELETE NO ACTION `OWNER` VARCHAR(45) NULL DEFAULT NULL,
ON UPDATE NO ACTION, `TENANT_ID` INT(11) NULL DEFAULT '0',
CONSTRAINT `FK_DEVICE_DEVICE_POLICY` PRIMARY KEY (`ID`),
FOREIGN KEY (`DEVICE_ID` ) INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC),
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` ) CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
FOREIGN KEY (`DEVICE_TYPE_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
@ -118,25 +124,25 @@ DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` -- Table `WSO2CDM`.`DM_DEVICE_POLICY`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` (
`ID` INT(11) NOT NULL , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`DEVICE_TYPE_ID` INT(11) NOT NULL , `DEVICE_ID` INT(11) NOT NULL,
`POLICY_ID` INT(11) NOT NULL , `POLICY_ID` INT(11) NOT NULL,
PRIMARY KEY (`ID`) , PRIMARY KEY (`ID`),
INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) , INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC),
INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC),
CONSTRAINT `FK_DEVICE_TYPE_POLICY` CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
FOREIGN KEY (`POLICY_ID` ) FOREIGN KEY (`DEVICE_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` CONSTRAINT `FK_POLICY_DEVICE_POLICY`
FOREIGN KEY (`DEVICE_TYPE_ID` ) FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
@ -144,49 +150,53 @@ DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_FEATURES` -- Table `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_FEATURES` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` (
`ID` INT(11) NOT NULL AUTO_INCREMENT , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(256) NOT NULL , `DEVICE_ID` INT(11) NOT NULL,
`CODE` VARCHAR(45) NULL DEFAULT NULL , `POLICY_ID` INT(11) NOT NULL,
`DEVICE_TYPE_ID` INT NOT NULL , `POLICY_CONTENT` BLOB NULL DEFAULT NULL,
`DESCRIPTION` TEXT NULL DEFAULT NULL , `APPLIED` TINYINT(1) NULL DEFAULT NULL,
`EVALUATION_RULE` VARCHAR(60) NOT NULL , `CREATED_TIME` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`ID`) , `UPDATED_TIME` TIMESTAMP NULL DEFAULT NULL,
INDEX `DM_FEATURES_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , `APPLIED_TIME` TIMESTAMP NULL DEFAULT NULL,
CONSTRAINT `DM_FEATURES_DEVICE_TYPE` PRIMARY KEY (`ID`),
FOREIGN KEY (`DEVICE_TYPE_ID` ) INDEX `FK_DM_POLICY_DEVCIE_APPLIED` (`DEVICE_ID` ASC),
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) INDEX `FK_DM_POLICY_DEVICE_APPLIED_POLICY` (`POLICY_ID` ASC),
CONSTRAINT `FK_DM_POLICY_DEVCIE_APPLIED`
FOREIGN KEY (`DEVICE_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DM_POLICY_DEVICE_APPLIED_POLICY`
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1; DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_PROFILE_FEATURES` -- Table `WSO2CDM`.`DM_PROFILE_FEATURES`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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,
INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) , PRIMARY KEY (`ID`),
INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) , INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC),
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
FOREIGN KEY (`FEATURE_ID` )
REFERENCES `WSO2CDM`.`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 `WSO2CDM`.`DM_PROFILE` (`ID` ) REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
@ -198,125 +208,101 @@ DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` (
`ID` INT(11) NOT NULL AUTO_INCREMENT , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`ROLE_NAME` VARCHAR(45) NOT NULL , `ROLE_NAME` VARCHAR(45) NOT NULL,
`POLICY_ID` INT(11) NOT NULL , `POLICY_ID` INT(11) NOT NULL,
PRIMARY KEY (`ID`) , PRIMARY KEY (`ID`),
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) , INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC),
CONSTRAINT `FK_ROLE_POLICY_POLICY` CONSTRAINT `FK_ROLE_POLICY_POLICY`
FOREIGN KEY (`POLICY_ID` ) FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1; DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_LOCATION`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_LOCATION` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` (
`LATITUDE` VARCHAR(45) NOT NULL ,
`LONGITUDE` VARCHAR(45) NOT NULL ,
`POLICY_ID` INT(11) NOT NULL ,
INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) ,
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_TIME` -- Table `WSO2CDM`.`DM_USER_POLICY`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_TIME` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_USER_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_USER_POLICY` (
`STARTING_TIME` DATETIME NOT NULL , `ID` INT(11) NOT NULL AUTO_INCREMENT,
`ENDING_TIME` DATETIME NOT NULL , `POLICY_ID` INT(11) NOT NULL,
`POLICY_ID` INT(11) NOT NULL , `USERNAME` VARCHAR(45) NOT NULL,
INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) , PRIMARY KEY (`ID`),
CONSTRAINT `FK_DM_POLICY_DM_TIME` INDEX `DM_POLICY_USER_POLICY` (`POLICY_ID` ASC),
FOREIGN KEY (`POLICY_ID` ) CONSTRAINT `DM_POLICY_USER_POLICY`
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DATE` -- Table `WSO2CDM`.`DM_CRITERIA`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DATE` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_CRITERIA` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DATE` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_CRITERIA` (
`START_DATE` DATE NOT NULL , `ID` INT NOT NULL AUTO_INCREMENT,
`END_DATE` DATE NOT NULL , `TENANT_ID` INT NOT NULL,
`POLICY_ID` INT NOT NULL , `NAME` VARCHAR(50) NULL,
INDEX `DM_DATE_POLICY` (`POLICY_ID` ASC) , PRIMARY KEY (`ID`))
CONSTRAINT `DM_DATE_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_USER_POLICY` -- Table `WSO2CDM`.`DM_POLICY_CRITERIA`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_USER_POLICY` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_USER_POLICY` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA` (
`ID` INT NOT NULL AUTO_INCREMENT , `ID` INT NOT NULL AUTO_INCREMENT,
`POLICY_ID` INT NOT NULL , `CRITERIA_ID` INT NOT NULL,
`USERNAME` VARCHAR(45) NOT NULL , `POLICY_ID` INT NOT NULL,
PRIMARY KEY (`ID`) , PRIMARY KEY (`ID`),
INDEX `DM_POLICY_USER_POLICY` (`POLICY_ID` ASC) , INDEX `FK_CRITERIA_POLICY_CRITERIA_idx` (`CRITERIA_ID` ASC),
CONSTRAINT `DM_POLICY_USER_POLICY` INDEX `FK_POLICY_POLICY_CRITERIA_idx` (`POLICY_ID` ASC),
FOREIGN KEY (`POLICY_ID` ) CONSTRAINT `FK_CRITERIA_POLICY_CRITERIA`
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) FOREIGN KEY (`CRITERIA_ID`)
REFERENCES `WSO2CDM`.`DM_CRITERIA` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_POLICY_POLICY_CRITERIA`
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` -- Table `WSO2CDM`.`DM_POLICY_CRITERIA_PROPERTIES`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ; DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA_PROPERTIES` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ( CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA_PROPERTIES` (
`ID` INT NOT NULL AUTO_INCREMENT , `ID` INT NOT NULL AUTO_INCREMENT,
`DEVICE_ID` INT NOT NULL , `POLICY_CRITERION_ID` INT NOT NULL,
`POLICY_ID` INT NOT NULL , `PROP_KEY` VARCHAR(45) NULL,
`POLICY_CONTENT` BLOB NULL , `PROP_VALUE` VARCHAR(100) NULL,
`APPLIED` TINYINT(1) NULL , `CONTENT` BLOB NULL COMMENT 'This is used to ',
`CREATED_TIME` TIMESTAMP NULL , PRIMARY KEY (`ID`),
`UPDATED_TIME` TIMESTAMP NULL , INDEX `FK_POLICY_CRITERIA_PROPERTIES_idx` (`POLICY_CRITERION_ID` ASC),
`APPLIED_TIME` TIMESTAMP NULL , CONSTRAINT `FK_POLICY_CRITERIA_PROPERTIES`
PRIMARY KEY (`ID`) , FOREIGN KEY (`POLICY_CRITERION_ID`)
INDEX `FK_DM_POLICY_DEVCIE_APPLIED` (`DEVICE_ID` ASC) , REFERENCES `WSO2CDM`.`DM_POLICY_CRITERIA` (`ID`)
INDEX `FK_DM_POLICY_DEVICE_APPLIED_POLICY` (`POLICY_ID` ASC) , ON DELETE CASCADE
CONSTRAINT `FK_DM_POLICY_DEVCIE_APPLIED`
FOREIGN KEY (`DEVICE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DM_POLICY_DEVICE_APPLIED_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE; SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

@ -1081,7 +1081,7 @@
<repository> <repository>
<id>wso2-staging</id> <id>wso2-staging</id>
<name>WSO2 Staging Repository</name> <name>WSO2 Staging Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/orgwso2carbonapimgt-004/</url> <url>http://maven.wso2.org/nexus/content/repositories/orgwso2carbonapimgt-009/</url>
<releases> <releases>
<enabled>true</enabled> <enabled>true</enabled>
<updatePolicy>daily</updatePolicy> <updatePolicy>daily</updatePolicy>

Loading…
Cancel
Save