|
|
@ -29,9 +29,8 @@ import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.sql.Date;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
@ -143,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 {
|
|
|
@ -230,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();
|
|
|
@ -303,6 +302,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
|
|
|
|
this.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -333,6 +333,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
|
|
|
|
this.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -391,17 +392,165 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Criterion> getAllPolicyCriteria() throws PolicyManagerDAOException {
|
|
|
|
public List<Criterion> getAllPolicyCriteria() throws PolicyManagerDAOException {
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
List<Criterion> criteria = new ArrayList<Criterion>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
Criterion criterion = new Criterion();
|
|
|
|
|
|
|
|
criterion.setId(resultSet.getInt("ID"));
|
|
|
|
|
|
|
|
criterion.setName(resultSet.getString("NAME"));
|
|
|
|
|
|
|
|
criteria.add(criterion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return criteria;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicyCriteria(Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public Policy addPolicyCriteria(Policy policy) throws PolicyManagerDAOException {
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet generatedKeys = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String query = "INSERT INTO DM_POLICY_CRITERIA (CRITERIA_ID, POLICY_ID) VALUES (?, ?)";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<PolicyCriterion> criteria = policy.getPolicyCriterias();
|
|
|
|
|
|
|
|
for (PolicyCriterion criterion : criteria) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setInt(1, criterion.getCriteriaId());
|
|
|
|
|
|
|
|
stmt.setInt(2, policy.getId());
|
|
|
|
|
|
|
|
stmt.addBatch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generatedKeys = stmt.getGeneratedKeys();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (generatedKeys.next()) {
|
|
|
|
|
|
|
|
policy.getPolicyCriterias().get(i).setId(generatedKeys.getInt(1));
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while inserting the criterion to policy (" + policy.getPolicyName() + ") " +
|
|
|
|
|
|
|
|
"to database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return policy;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<PolicyCriteria> getPolicyCriteria(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public boolean addPolicyCriteriaProperties(List<PolicyCriterion> policyCriteria) throws PolicyManagerDAOException {
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties prop = criterion.getProperties();
|
|
|
|
|
|
|
|
for (String name : prop.stringPropertyNames()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setInt(1, criterion.getId());
|
|
|
|
|
|
|
|
stmt.setString(2, name);
|
|
|
|
|
|
|
|
stmt.setString(3, prop.getProperty(name));
|
|
|
|
|
|
|
|
stmt.setObject(4, criterion.getObjectMap());
|
|
|
|
|
|
|
|
stmt.addBatch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt.executeBatch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while inserting the criterion properties to database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<PolicyCriterion> getPolicyCriteria(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
List<PolicyCriterion> criteria = new ArrayList<PolicyCriterion>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
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 = ?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int criteriaId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PolicyCriterion policyCriterion = null;
|
|
|
|
|
|
|
|
Properties prop = null;
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (criteriaId != resultSet.getInt("ID")) {
|
|
|
|
|
|
|
|
if (policyCriterion != null) {
|
|
|
|
|
|
|
|
policyCriterion.setProperties(prop);
|
|
|
|
|
|
|
|
criteria.add(policyCriterion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
policyCriterion = new PolicyCriterion();
|
|
|
|
|
|
|
|
prop = new Properties();
|
|
|
|
|
|
|
|
criteriaId = resultSet.getInt("ID");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policyCriterion.setId(resultSet.getInt("ID"));
|
|
|
|
|
|
|
|
policyCriterion.setCriteriaId(resultSet.getInt("CRITERIA_ID"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
prop.setProperty(resultSet.getString("PROP_KEY"), resultSet.getString("PROP_VALUE"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while reading the criteria related to policies from the database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return criteria;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -411,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) {
|
|
|
@ -450,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;
|
|
|
|
|
|
|
|
|
|
|
@ -483,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;
|
|
|
|
|
|
|
|
|
|
|
@ -517,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;
|
|
|
@ -599,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)
|
|
|
@ -972,6 +1115,13 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String deleteCriteria = "DELETE FROM DM_POLICY_CRITERIA WHERE POLICY_ID = ?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(deleteCriteria);
|
|
|
|
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Policy (" + policyId + ") related configs deleted from database.");
|
|
|
|
log.debug("Policy (" + policyId + ") related configs deleted from database.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1007,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();
|
|
|
|
|
|
|
|
|
|
|
|