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 408ab11abf..d84236c352 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 2a5b175755..a01fada772 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/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index c61b9802a2..859f29bd1c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -88,7 +88,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { return policyManager.getPolicies(); } - @Override public Policy getPolicy(int policyId) throws PolicyManagementException { + @Override + public Policy getPolicy(int policyId) throws PolicyManagementException { return policyManager.getPolicy(policyId); } @@ -184,34 +185,17 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public Feature addFeature(Feature feature) throws FeatureManagementException { - try { - return featureManager.addFeature(feature); - } catch (FeatureManagementException e) { - String msg = "Error occurred while persisting the feature."; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } + return featureManager.addFeature(feature); } @Override public Feature updateFeature(Feature feature) throws FeatureManagementException { - try { - return featureManager.updateFeature(feature); - } catch (FeatureManagementException e) { - String msg = "Error occurred while persisting the feature."; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } + return featureManager.updateFeature(feature); + } @Override public boolean deleteFeature(int featureId) throws FeatureManagementException { - try { - return featureManager.deleteFeature(featureId); - } catch (FeatureManagementException e) { - String msg = "Error occurred while deleting the feature."; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } + return featureManager.deleteFeature(featureId); } } 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 d275eb3c9a..18e832f8be 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 b6a44bc277..720e24a950 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) {