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<String> users;
/* Compliance data*/
private String Compliance;
/*Dynamic policy attributes*/
/* This is related criteria based policy */
@ -54,17 +58,17 @@ public class Policy implements Comparable<Policy>, Serializable {
/*These are related to time based policies*/
private int startTime; // Start time to apply the policy.
private int endTime; // After this time policy will not be applied
private Date startDate; // Start date to apply the policy
private Date endDate; // After this date policy will not be applied.
// private int startTime; // Start time to apply the policy.
// private int endTime; // After this time policy will not be applied
// private Date startDate; // Start date to apply the policy
// private Date endDate; // After this date policy will not be applied.
/*These are related to location based policies*/
private String latitude; // Latitude
private String longitude; // Longitude
// private String latitude; // Latitude
// private String longitude; // Longitude
//
private int tenantId;
private int profileId;
@ -171,58 +175,66 @@ public class Policy implements Comparable<Policy>, Serializable {
this.policyCriterias = policyCriterias;
}
public int getStartTime() {
return startTime;
}
public void setStartTime(int startTime) {
this.startTime = startTime;
}
@XmlElement
public int getEndTime() {
return endTime;
}
public void setEndTime(int endTime) {
this.endTime = endTime;
}
@XmlElement
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@XmlElement
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@XmlElement
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
@XmlElement
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getCompliance() {
return Compliance;
}
public void setCompliance(String compliance) {
Compliance = compliance;
}
// public int getStartTime() {
// return startTime;
// }
//
// public void setStartTime(int startTime) {
// this.startTime = startTime;
// }
//
// @XmlElement
// public int getEndTime() {
// return endTime;
// }
//
// public void setEndTime(int endTime) {
// this.endTime = endTime;
// }
//
// @XmlElement
// public Date getStartDate() {
// return startDate;
// }
//
// public void setStartDate(Date startDate) {
// this.startDate = startDate;
// }
//
// @XmlElement
// public Date getEndDate() {
// return endDate;
// }
//
// public void setEndDate(Date endDate) {
// this.endDate = endDate;
// }
//
// @XmlElement
// public String getLatitude() {
// return latitude;
// }
//
// public void setLatitude(String latitude) {
// this.latitude = latitude;
// }
//
// @XmlElement
// public String getLongitude() {
// return longitude;
// }
//
// public void setLongitude(String longitude) {
// this.longitude = longitude;
// }
@XmlElement
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
FeatureManagerDAOException;
List<Feature> getAllFeatures() throws FeatureManagerDAOException;
List<ProfileFeature> getAllProfileFeatures() 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 addDatesToPolicy(Date startDate, Date endDate, 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 addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException;
//
// Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException;
//
// Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws PolicyManagerDAOException;
Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException;
@ -86,11 +86,11 @@ public interface PolicyDAO {
List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException;
PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException;
PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException;
PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException;
// PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException;
//
// PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException;
//
// PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException;
void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
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.util.PolicyManagementDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@ -181,7 +181,11 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt.setInt(1, profileId);
stmt.setString(2, feature.getFeatureCode());
stmt.setInt(3, feature.getDeviceTypeId());
if (conn.getMetaData().getDriverName().contains("H2")) {
stmt.setObject(4, feature.getContent(), Types.JAVA_OBJECT);
} else {
stmt.setObject(4, feature.getContent());
}
stmt.addBatch();
//Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
}
@ -217,7 +221,11 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
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.setString(3, feature.getFeatureCode());
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
public List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException {
@ -322,8 +294,34 @@ public class FeatureDAOImpl implements FeatureDAO {
profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
profileFeature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
profileFeature.setId(resultSet.getInt("ID"));
profileFeature.setContent(resultSet.getObject("CONTENT"));
// profileFeature.setContent(resultSet.getObject("CONTENT"));
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);
}
@ -331,6 +329,14 @@ public class FeatureDAOImpl implements FeatureDAO {
String msg = "Unable to get the list of the features from database.";
log.error(msg);
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 {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
@ -395,17 +401,35 @@ public class FeatureDAOImpl implements FeatureDAO {
while (resultSet.next()) {
ProfileFeature profileFeature = new ProfileFeature();
// Feature feature = new Feature();
// feature.setId(resultSet.getInt("FEATURE_ID"));
// feature.setCode(resultSet.getString("CODE"));
// feature.setName(resultSet.getString("NAME"));
// feature.setRuleValue(resultSet.getString("RULE"));
// profileFeature.setFeature(feature);
profileFeature.setId(resultSet.getInt("ID"));
profileFeature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
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);
}
@ -413,6 +437,14 @@ public class FeatureDAOImpl implements FeatureDAO {
String msg = "Unable to get the list of the features from database.";
log.error(msg);
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 {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();

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

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

@ -274,16 +274,6 @@ public class FeatureManagerImpl implements FeatureManager {
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
public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException {

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

@ -19,5 +19,8 @@
package org.wso2.carbon.policy.mgt.core.util;
public final class PolicyManagementConstants {
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.dto.Device;
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.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.common.*;
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.TestDBConfigurations;
@ -62,6 +56,7 @@ import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class PolicyDAOTestCase {
@ -250,6 +245,15 @@ public class PolicyDAOTestCase {
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"))
public void getPolicies() throws PolicyManagementException {
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;
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 java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class PolicyCreator {
@ -35,6 +37,7 @@ public class PolicyCreator {
List<String> users = new ArrayList<String>();
users.add("Dilshan");
policy.setUsers(users);
policy.setCompliance("ENFORCE");
return policy;
}
@ -43,11 +46,13 @@ public class PolicyCreator {
public static Policy createPolicy2(Profile profile) {
Policy policy = new Policy();
policy.setPolicyName("New test Policy");
policy.setPolicyName("Test_Policy_02");
policy.setGeneric(true);
policy.setProfile(profile);
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
policy.setCompliance("NOTIFY");
List<String> roles = new ArrayList<String>();
roles.add("Role_01");
roles.add("Role_02");
@ -63,8 +68,128 @@ public class PolicyCreator {
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 ");
java.util.Date date = new java.util.Date();

@ -23,16 +23,22 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ProfileFeatureCreator {
public static List<ProfileFeature> getProfileFeature(List<Feature> features) {
List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>();
int i = 0;
for (Feature feature : features) {
ProfileFeature profileFeature = new ProfileFeature();
profileFeature.setContent(feature);
if (i % 2 == 0) {
profileFeature.setContent( getJSON());
} else {
profileFeature.setContent(getJSON2());
}
profileFeature.setDeviceTypeId(1);
profileFeature.setFeatureCode(feature.getCode());
@ -41,7 +47,79 @@ public class ProfileFeatureCreator {
// profileFeature.setFeature(feature);
profileFeatureList.add(profileFeature);
i++;
}
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 ,
TENANT_ID INT(11) NOT NULL ,
PROFILE_ID INT(11) NOT NULL ,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL ,
PRIMARY KEY (ID) ,
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
@ -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_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';
DROP SCHEMA IF EXISTS `WSO2CDM` ;
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema WSO2CDM
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema WSO2CDM
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ;
USE `WSO2CDM` ;
@ -12,37 +23,9 @@ USE `WSO2CDM` ;
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
`DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL ,
`DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL ,
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
`TENANT_ID` INT(11) NULL DEFAULT '0' ,
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 UPDATE NO ACTION)
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(300) NULL DEFAULT NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
@ -53,20 +36,21 @@ DEFAULT CHARACTER SET = latin1;
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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`) ,
INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`PROFILE_NAME` VARCHAR(45) NOT NULL,
`TENANT_ID` INT(11) NOT NULL,
`DEVICE_TYPE_ID` INT(11) NOT NULL,
`CREATED_TIME` DATETIME NOT NULL,
`UPDATED_TIME` DATETIME NOT NULL,
PRIMARY KEY (`ID`),
INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC),
CONSTRAINT `DM_PROFILE_DEVICE_TYPE`
FOREIGN KEY (`DEVICE_TYPE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
FOREIGN KEY (`DEVICE_TYPE_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
@ -75,16 +59,17 @@ ENGINE = InnoDB;
DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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`) ,
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) ,
`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,
`COMPLIANCE` VARCHAR(100) NULL,
`PRIORITY` INT(11) NOT NULL,
PRIMARY KEY (`ID`),
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC),
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
FOREIGN KEY (`PROFILE_ID` )
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
FOREIGN KEY (`PROFILE_ID`)
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
@ -92,25 +77,46 @@ DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE_POLICY`
-- Table `WSO2CDM`.`DM_DATE`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ;
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DATE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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`) ,
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) ,
INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC) ,
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DATE` (
`START_DATE` DATE NOT NULL,
`END_DATE` DATE NOT NULL,
`POLICY_ID` INT(11) NOT NULL,
INDEX `DM_DATE_POLICY` (`POLICY_ID` ASC),
CONSTRAINT `DM_DATE_POLICY`
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
FOREIGN KEY (`DEVICE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` )
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`DESCRIPTION` TEXT NULL DEFAULT NULL,
`NAME` VARCHAR(100) NULL DEFAULT NULL,
`DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL,
`DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL,
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL,
`STATUS` VARCHAR(15) NULL DEFAULT NULL,
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL,
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL,
`OWNER` VARCHAR(45) NULL DEFAULT NULL,
`TENANT_ID` INT(11) NULL DEFAULT '0',
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 UPDATE NO ACTION)
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` (
`ID` INT(11) NOT NULL ,
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
`POLICY_ID` INT(11) NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) ,
INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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`),
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC),
INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC),
CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
FOREIGN KEY (`DEVICE_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
FOREIGN KEY (`DEVICE_TYPE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
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` (
`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`) ,
INDEX `DM_FEATURES_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
CONSTRAINT `DM_FEATURES_DEVICE_TYPE`
FOREIGN KEY (`DEVICE_TYPE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`DEVICE_ID` INT(11) NOT NULL,
`POLICY_ID` INT(11) NOT NULL,
`POLICY_CONTENT` BLOB NULL DEFAULT NULL,
`APPLIED` TINYINT(1) NULL DEFAULT NULL,
`CREATED_TIME` TIMESTAMP NULL DEFAULT NULL,
`UPDATED_TIME` TIMESTAMP NULL DEFAULT NULL,
`APPLIED_TIME` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`ID`),
INDEX `FK_DM_POLICY_DEVCIE_APPLIED` (`DEVICE_ID` ASC),
INDEX `FK_DM_POLICY_DEVICE_APPLIED_POLICY` (`POLICY_ID` ASC),
CONSTRAINT `FK_DM_POLICY_DEVCIE_APPLIED`
FOREIGN KEY (`DEVICE_ID`)
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DM_POLICY_DEVICE_APPLIED_POLICY`
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_PROFILE_FEATURES`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`PROFILE_ID` INT(11) NOT NULL ,
`FEATURE_ID` INT(11) NOT NULL ,
`CONTENT` BLOB NULL DEFAULT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_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,
`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`),
INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC),
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
FOREIGN KEY (`PROFILE_ID` )
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
FOREIGN KEY (`PROFILE_ID`)
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
@ -199,124 +209,100 @@ DEFAULT CHARACTER SET = latin1;
DROP TABLE IF EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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`) ,
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) ,
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`ROLE_NAME` VARCHAR(45) NOT NULL,
`POLICY_ID` INT(11) NOT NULL,
PRIMARY KEY (`ID`),
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC),
CONSTRAINT `FK_ROLE_POLICY_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
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` (
`STARTING_TIME` DATETIME NOT NULL ,
`ENDING_TIME` DATETIME NOT NULL ,
`POLICY_ID` INT(11) NOT NULL ,
INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) ,
CONSTRAINT `FK_DM_POLICY_DM_TIME`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_USER_POLICY` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`POLICY_ID` INT(11) NOT NULL,
`USERNAME` VARCHAR(45) NOT NULL,
PRIMARY KEY (`ID`),
INDEX `DM_POLICY_USER_POLICY` (`POLICY_ID` ASC),
CONSTRAINT `DM_POLICY_USER_POLICY`
FOREIGN KEY (`POLICY_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID`)
ON DELETE 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` (
`START_DATE` DATE NOT NULL ,
`END_DATE` DATE NOT NULL ,
`POLICY_ID` INT NOT NULL ,
INDEX `DM_DATE_POLICY` (`POLICY_ID` ASC) ,
CONSTRAINT `DM_DATE_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_CRITERIA` (
`ID` INT NOT NULL AUTO_INCREMENT,
`TENANT_ID` INT NOT NULL,
`NAME` VARCHAR(50) NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_USER_POLICY`
-- Table `WSO2CDM`.`DM_POLICY_CRITERIA`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_USER_POLICY` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_USER_POLICY` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`POLICY_ID` INT NOT NULL ,
`USERNAME` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `DM_POLICY_USER_POLICY` (`POLICY_ID` ASC) ,
CONSTRAINT `DM_POLICY_USER_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA` (
`ID` INT NOT NULL AUTO_INCREMENT,
`CRITERIA_ID` INT NOT NULL,
`POLICY_ID` INT NOT NULL,
PRIMARY KEY (`ID`),
INDEX `FK_CRITERIA_POLICY_CRITERIA_idx` (`CRITERIA_ID` ASC),
INDEX `FK_POLICY_POLICY_CRITERIA_idx` (`POLICY_ID` ASC),
CONSTRAINT `FK_CRITERIA_POLICY_CRITERIA`
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 UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED`
-- Table `WSO2CDM`.`DM_POLICY_CRITERIA_PROPERTIES`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`DEVICE_ID` INT NOT NULL ,
`POLICY_ID` INT NOT NULL ,
`POLICY_CONTENT` BLOB NULL ,
`APPLIED` TINYINT(1) NULL ,
`CREATED_TIME` TIMESTAMP NULL ,
`UPDATED_TIME` TIMESTAMP NULL ,
`APPLIED_TIME` TIMESTAMP NULL ,
PRIMARY KEY (`ID`) ,
INDEX `FK_DM_POLICY_DEVCIE_APPLIED` (`DEVICE_ID` ASC) ,
INDEX `FK_DM_POLICY_DEVICE_APPLIED_POLICY` (`POLICY_ID` ASC) ,
CONSTRAINT `FK_DM_POLICY_DEVCIE_APPLIED`
FOREIGN KEY (`DEVICE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DM_POLICY_DEVICE_APPLIED_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
ON DELETE NO ACTION
DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY_CRITERIA_PROPERTIES` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`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`),
INDEX `FK_POLICY_CRITERIA_PROPERTIES_idx` (`POLICY_CRITERION_ID` ASC),
CONSTRAINT `FK_POLICY_CRITERIA_PROPERTIES`
FOREIGN KEY (`POLICY_CRITERION_ID`)
REFERENCES `WSO2CDM`.`DM_POLICY_CRITERIA` (`ID`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

@ -1081,7 +1081,7 @@
<repository>
<id>wso2-staging</id>
<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>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>

Loading…
Cancel
Save