diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index 408ab11abf8..d84236c3525 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -36,6 +36,8 @@ public interface PolicyDAO { Policy addPolicyToDevice(List devices, Policy policy) throws PolicyManagerDAOException; + boolean updatePolicyPriorities(List policies) throws PolicyManagerDAOException; + // Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException; // // Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException; @@ -88,6 +90,8 @@ public interface PolicyDAO { List getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException; + List getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException; + // PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException; // // PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index 2a5b1757550..a01fada7727 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -142,6 +142,36 @@ public class PolicyDAOImpl implements PolicyDAO { return policy; } + @Override + public boolean updatePolicyPriorities(List policies) throws PolicyManagerDAOException { + + /* Connection conn; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String query = "UPDATE DM_POLICY SET PRIORITY = ? 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.setString(5, policy.getCompliance()); + stmt.setInt(6, policy.getId()); + stmt.executeUpdate(); + + } catch (SQLException e) { + String msg = "Error occurred while updating policy (" + policy.getPolicyName() + ") in database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } + return policy;*/ + + + return false; + } + // @Override // public Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException { // @@ -752,6 +782,36 @@ public class PolicyDAOImpl implements PolicyDAO { } } + @Override + public List getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + List users = new ArrayList(); + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_USER_POLICY WHERE POLICY_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policyId); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + + users.add(resultSet.getString("USERNAME")); + } + return users; + + } catch (SQLException e) { + String msg = "Error occurred while getting the roles related to policies."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); + this.closeConnection(); + } + } + // public PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException { // diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index d275eb3c9ad..18e832f8be6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -468,6 +468,7 @@ public class PolicyManagerImpl implements PolicyManager { } policy.setDevices(getPolicyAppliedDevicesIds(policy.getId())); policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId())); + policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId())); policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId())); // policyDAO.getDatesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java index b6a44bc277c..720e24a9503 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java @@ -263,6 +263,17 @@ public class PolicyDAOTestCase { for (Policy policy : policyList) { log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); + log.debug("Policy Ownership type :" + policy.getOwnershipType()); + + List users = policy.getUsers(); + for (String user : users) { + log.debug("User of the policy : " + user); + } + + List roles = policy.getRoles(); + for (String role : roles) { + log.debug("User of the policy : " + role); + } } } @@ -276,6 +287,17 @@ public class PolicyDAOTestCase { for (Policy policy : policyList) { log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); + log.debug("Policy Ownership type :" + policy.getOwnershipType()); + + List users = policy.getUsers(); + for (String user : users) { + log.debug("User of the policy : " + user); + } + + List roles = policy.getRoles(); + for (String role : roles) { + log.debug("User of the policy : " + role); + } } } @@ -290,6 +312,17 @@ public class PolicyDAOTestCase { for (Policy policy : policyList) { log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); + log.debug("Policy Ownership type :" + policy.getOwnershipType()); + + List users = policy.getUsers(); + for (String user : users) { + log.debug("User of the policy : " + user); + } + + List roles = policy.getRoles(); + for (String role : roles) { + log.debug("User of the policy : " + role); + } } } @@ -303,6 +336,8 @@ public class PolicyDAOTestCase { for (Policy policy : policyList) { log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); + + log.debug("Policy Ownership type :" + policy.getOwnershipType()); } } @@ -324,6 +359,8 @@ public class PolicyDAOTestCase { for (Policy policy : policyList) { log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); + log.debug("Policy Ownership type :" + policy.getOwnershipType()); + List profileFeatures = policy.getProfile().getProfileFeaturesList(); for (ProfileFeature profileFeature : profileFeatures) {