From 5b2e0c898908d8a2034924efcf49cafe2eda85fb Mon Sep 17 00:00:00 2001 From: milanperera Date: Fri, 24 Jul 2015 12:32:26 +0530 Subject: [PATCH] Merged --- .../mgt/core/dao/impl/EnrolmentDAOImpl.java | 8 +-- .../DeviceManagementProviderServiceImpl.java | 1 + .../mgt/core/dao/impl/PolicyDAOImpl.java | 56 ++++++++++--------- .../src/main/resources/dbscripts/cdm/h2.sql | 31 ++++++++++ 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrolmentDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrolmentDAOImpl.java index f6b22e07d62..b616202f828 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrolmentDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrolmentDAOImpl.java @@ -77,7 +77,7 @@ public class EnrolmentDAOImpl implements EnrolmentDAO { stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); - stmt.setTimestamp(4, new Timestamp(enrolmentInfo.getDateOfLastUpdate())); + stmt.setTimestamp(4, new Timestamp(new Date().getTime())); stmt.setInt(5, deviceId); stmt.setString(6, enrolmentInfo.getOwner()); stmt.setInt(7, tenantId); @@ -156,9 +156,9 @@ public class EnrolmentDAOImpl implements EnrolmentDAO { conn = this.getConnection(); String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); - stmt.setInt(2, deviceId); - stmt.setString(3, currentOwner); - stmt.setInt(4, tenantId); + stmt.setInt(1, deviceId); + stmt.setString(2, currentOwner); + stmt.setInt(3, tenantId); rs = stmt.executeQuery(); if (rs.next()) { status = EnrolmentInfo.Status.valueOf(rs.getString("STATUS")); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index a3c58daddf9..c2e352384e4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -138,6 +138,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo(); if (existingEnrolmentInfo != null && newEnrolmentInfo != null) { if (existingEnrolmentInfo.equals(newEnrolmentInfo)) { + device.getEnrolmentInfo().setDateOfEnrolment(existingEnrolmentInfo.getDateOfEnrolment()); this.modifyEnrollment(device); status = true; } else { 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 08232ea7edc..586c9b31c1d 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 @@ -416,7 +416,7 @@ public class PolicyDAOImpl implements PolicyDAO { } catch (SQLException e) { String msg = "Error occurred while inserting the criterion to policy (" + policy.getPolicyName() + ") " + - "to database."; + "to database."; log.error(msg, e); throw new PolicyManagerDAOException(msg, e); } finally { @@ -436,7 +436,7 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, " + - "CONTENT) VALUES (?, ?, ?, ?)"; + "CONTENT) VALUES (?, ?, ?, ?)"; stmt = conn.prepareStatement(query); for (PolicyCriterion criterion : policyCriteria) { @@ -477,9 +477,9 @@ public class PolicyDAOImpl implements PolicyDAO { 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 = ?"; + "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(); @@ -525,7 +525,7 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?" + - " WHERE ID = ?"; + " WHERE ID = ?"; stmt = conn.prepareStatement(query); stmt.setString(1, policy.getPolicyName()); stmt.setInt(2, policy.getTenantId()); @@ -758,7 +758,7 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED " + - "(DEVICE_ID, POLICY_ID, POLICY_CONTENT, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)"; + "(DEVICE_ID, POLICY_ID, POLICY_CONTENT, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(query); stmt.setInt(1, deviceId); stmt.setInt(2, policyId); @@ -814,7 +814,7 @@ public class PolicyDAOImpl implements PolicyDAO { try { conn = this.getConnection(); String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " + - "APPLIED = ? WHERE DEVICE_ID = ?"; + "APPLIED = ? WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, policyId); stmt.setObject(2, profileFeatures); @@ -1068,7 +1068,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)" + - " VALUES (?, ?, ?, ?, ?, ?)"; + " VALUES (?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, policy.getPolicyName()); @@ -1245,28 +1245,30 @@ public class PolicyDAOImpl implements PolicyDAO { stmt.setInt(1, deviceId); resultSet = stmt.executeQuery(); - ByteArrayInputStream bais = null; ObjectInputStream ois = null; byte[] contentBytes; - try { - contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT"); - bais = new ByteArrayInputStream(contentBytes); - ois = new ObjectInputStream(bais); - policy = (Policy) ois.readObject(); - } finally { - if (bais != null) { - try { - bais.close(); - } catch (IOException e) { - log.warn("Error occurred while closing ByteArrayOutputStream", e); + + while (resultSet.next()) { + try { + contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT"); + bais = new ByteArrayInputStream(contentBytes); + ois = new ObjectInputStream(bais); + policy = (Policy) ois.readObject(); + } 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); + if (ois != null) { + try { + ois.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ObjectOutputStream", e); + } } } } 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 d417bfe573b..cf8bf647d9b 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 @@ -322,6 +322,37 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + STATUS INT NULL, + LAST_SUCCESS_TIME TIMESTAMP NULL, + LAST_REQUESTED_TIME TIMESTAMP NULL, + LAST_FAILED_TIME TIMESTAMP NULL, + ATTEMPTS INT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( + ID INT NOT NULL AUTO_INCREMENT, + COMPLIANCE_STATUS_ID INT NOT NULL, + FEATURE_CODE INT NOT NULL, + STATUS INT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS + FOREIGN KEY (COMPLIANCE_STATUS_ID) + REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + -- POLICY RELATED TABLES FINISHED --