From d52df2474e98a17704877451cc0c76aff45aaa24 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 15 Oct 2015 13:01:53 +0530 Subject: [PATCH] Fixing policy descriptions --- .../org/wso2/carbon/policy/mgt/common/Policy.java | 15 ++++++++++++--- .../policy/mgt/core/dao/impl/PolicyDAOImpl.java | 14 +++++++++----- .../policy/mgt/core/util/PolicyCreator.java | 6 +++++- .../src/test/resources/sql/CreateH2TestDB.sql | 1 + .../src/main/resources/dbscripts/cdm/h2.sql | 1 + 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index 6087207db1..4299549f96 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java @@ -44,10 +44,11 @@ public class Policy implements Comparable, Serializable { private List users; private boolean active; private boolean updated; + private String description; /* Compliance data*/ - private String Compliance; + private String compliance; /*Dynamic policy attributes*/ @@ -170,6 +171,14 @@ public class Policy implements Comparable, Serializable { this.updated = updated; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + @XmlElement public List getPolicyCriterias() { return policyCriterias; @@ -181,11 +190,11 @@ public class Policy implements Comparable, Serializable { @XmlElement public String getCompliance() { - return Compliance; + return compliance; } public void setCompliance(String compliance) { - Compliance = compliance; + this.compliance = compliance; } @XmlElement 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 b33b71289e..8513540ea4 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 @@ -629,15 +629,16 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "UPDATE DM_POLICY SET NAME = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?," + - " UPDATED = ? WHERE ID = ? AND TENANT_ID = ?"; + " UPDATED = ?, DESCRIPTION = ? WHERE ID = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(query); stmt.setString(1, policy.getPolicyName()); stmt.setInt(2, policy.getProfile().getProfileId()); stmt.setInt(3, policy.getPriorityId()); stmt.setString(4, policy.getCompliance()); stmt.setInt(5, 1); - stmt.setInt(6, policy.getId()); - stmt.setInt(7, tenantId); + stmt.setString(6, policy.getDescription()); + stmt.setInt(7, policy.getId()); + stmt.setInt(8, tenantId); stmt.executeUpdate(); } catch (SQLException e) { @@ -742,6 +743,7 @@ public class PolicyDAOImpl implements PolicyDAO { policy.setPriorityId(resultSet.getInt("PRIORITY")); policy.setProfileId(resultSet.getInt("PROFILE_ID")); policy.setCompliance(resultSet.getString("COMPLIANCE")); + policy.setDescription(resultSet.getString("DESCRIPTION")); } return policy; @@ -775,6 +777,7 @@ public class PolicyDAOImpl implements PolicyDAO { policy.setTenantId(resultSet.getInt("TENANT_ID")); policy.setPriorityId(resultSet.getInt("PRIORITY")); policy.setCompliance(resultSet.getString("COMPLIANCE")); + policy.setDescription(resultSet.getString("DESCRIPTION")); } return policy; } catch (SQLException e) { @@ -810,6 +813,7 @@ public class PolicyDAOImpl implements PolicyDAO { policy.setOwnershipType(resultSet.getString("OWNERSHIP_TYPE")); policy.setUpdated(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("UPDATED"))); policy.setActive(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("ACTIVE"))); + policy.setDescription(resultSet.getString("DESCRIPTION")); policies.add(policy); } return policies; @@ -1185,8 +1189,7 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE," + - " " + - "UPDATED, ACTIVE) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + "UPDATED, ACTIVE, DESCRIPTION) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, policy.getPolicyName()); @@ -1197,6 +1200,7 @@ public class PolicyDAOImpl implements PolicyDAO { stmt.setString(6, policy.getOwnershipType()); stmt.setInt(7, 0); stmt.setInt(8, 0); + stmt.setString(9, policy.getDescription()); int affectedRows = stmt.executeUpdate(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java index a7dbe5c4a6..2b86282aaf 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/PolicyCreator.java @@ -39,6 +39,7 @@ public class PolicyCreator { policy.setUsers(users); policy.setCompliance("NOTIFY"); policy.setOwnershipType("COPE"); + policy.setDescription("This is the first policy."); return policy; } @@ -87,6 +88,7 @@ public class PolicyCreator { policy.setOwnershipType("COPE"); policy.setPolicyCriterias(criteria); + policy.setDescription("This is the second policy."); return policy; @@ -126,7 +128,7 @@ public class PolicyCreator { criteria.add(criterion); policy.setPolicyCriterias(criteria); - + policy.setDescription("This is the third policy."); return policy; } @@ -175,6 +177,8 @@ public class PolicyCreator { policy.setPolicyCriterias(criteria); + policy.setDescription("This is the fourth policy."); + return policy; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index f221ba0e78..6af5c86031 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -139,6 +139,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( CREATE TABLE IF NOT EXISTS DM_POLICY ( ID INT(11) NOT NULL AUTO_INCREMENT , NAME VARCHAR(45) NULL DEFAULT NULL , + DESCRIPTION VARCHAR(1000) NULL, TENANT_ID INT(11) NOT NULL , PROFILE_ID INT(11) NOT NULL , OWNERSHIP_TYPE VARCHAR(45) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 4e337ef6a3..95a32302b1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -124,6 +124,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( CREATE TABLE IF NOT EXISTS DM_POLICY ( ID INT(11) NOT NULL AUTO_INCREMENT , NAME VARCHAR(45) DEFAULT NULL , + DESCRIPTION VARCHAR(1000) NULL, TENANT_ID INT(11) NOT NULL , PROFILE_ID INT(11) NOT NULL , OWNERSHIP_TYPE VARCHAR(45) NULL,