diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java index e7205ca5fe..83900177b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java @@ -77,11 +77,10 @@ public class OperationManagementDAOFactory { public static Connection getConnection() throws OperationManagementDAOException { if (currentConnection.get() == null) { synchronized (LOCK) { - try { currentConnection.set(dataSource.getConnection()); } catch (SQLException e) { - throw new OperationManagementDAOException("Error occurred while retrieving datasource connection", + throw new OperationManagementDAOException("Error occurred while retrieving data source connection", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index 5e8527fe9f..cab41c2913 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -39,11 +39,13 @@ public class OperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement( - "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS) VALUES (?, ?, ?, ?)"); + "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS,OPERATIONCODE) " + + "VALUES (?, ?, ?, ?,?)"); stmt.setString(1, operation.getType().toString()); stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setTimestamp(3, null); stmt.setString(4, Operation.Status.PENDING.toString()); + stmt.setString(5, operation.getCode()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); @@ -117,11 +119,11 @@ public class OperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = - "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS FROM DM_OPERATION o " + + "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o " + "INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER " + "JOIN " + "DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND d" + - ".DEVICE_IDENTIFICATION = ?) d1 "+ + ".DEVICE_IDENTIFICATION = ?) d1 " + "INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois " + "ON o.ID = ois.OP_ID"; stmt = conn.prepareStatement(sql); @@ -133,6 +135,15 @@ public class OperationDAOImpl implements OperationDAO { while (rs.next()) { Operation operation = new Operation(); operation.setId(rs.getInt("ID")); + operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + if (rs.getTimestamp("CREATED_TIMESTAMP") == null){ + operation.setReceivedTimeStamp(""); + }else{ + operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + } + operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + operation.setCode(rs.getString("OPERATIONCODE")); } } catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while retrieving the operation list " + @@ -161,7 +172,8 @@ public class OperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement( - "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS FROM DM_OPERATION o " + + "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS,o.OPERATIONCODE " + + " FROM DM_OPERATION o " + "INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID " + "FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND " + "dm.NAME = ? AND d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN " + @@ -173,10 +185,18 @@ public class OperationDAOImpl implements OperationDAO { Operation operation = null; if (rs.next()) { + operation = new Operation(); operation.setType(this.getType(rs.getString("TYPE"))); operation.setStatus(this.getStatus(rs.getString("STATUS"))); operation.setId(rs.getInt("ID")); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null){ + operation.setReceivedTimeStamp(""); + }else{ + operation.setReceivedTimeStamp(rs.getString("RECEIVED_TIMESTAMP").toString()); + } + operation.setCode(rs.getString("OPERATIONCODE")); } return operation; } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index 90cf50f25e..4dc56db82f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -135,15 +135,16 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { int operationId = 0; String operationType = ""; - String createdTime; - String receivedTime; + String createdTime = ""; + String receivedTime = ""; String operationStatus = ""; + String operationCode = ""; try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement( "SELECT o.ID AS OPERATION_ID, o.CREATED_TIMESTAMP AS CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP AS " + - "RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD,o.TYPE AS TYPE,o.STATUS as STATUS " + + "RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD,o.TYPE AS TYPE,o.STATUS as STATUS,o.OPERATIONCODE " + "FROM DM_OPERATION o " + "INNER JOIN DM_PROFILE_OPERATION po ON o.ID = po.OPERATION_ID AND o.ID IN (" + "SELECT dom.OPERATION_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " + @@ -162,6 +163,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { payload = rs.getBytes("PAYLOAD"); operationType = rs.getString("TYPE"); operationStatus = rs.getString("STATUS"); + operationCode = rs.getString("OPERATIONCODE"); } bais = new ByteArrayInputStream(payload); ois = new ObjectInputStream(bais); @@ -170,6 +172,9 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { profileOperation.setId(operationId); profileOperation.setType(Operation.Type.valueOf(operationType)); profileOperation.setStatus(Operation.Status.valueOf(operationStatus)); + profileOperation.setCreatedTimeStamp(createdTime); + profileOperation.setReceivedTimeStamp(receivedTime); + profileOperation.setCode(operationCode); return profileOperation; } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java index 6b7fe6da81..a51ff42383 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java @@ -65,6 +65,7 @@ public class DeviceOperationManagementTests extends DeviceManagementBaseTest { CommandOperation op = new CommandOperation(); op.setEnabled(true); op.setType(Operation.Type.COMMAND); + op.setCode("OPCODE1"); List deviceIds = new ArrayList(); DeviceIdentifier deviceId = new DeviceIdentifier(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index b8b3376aff..e0fd152ac6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATED_TIMESTAMP TIMESTAMP NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL, STATUS VARCHAR(50) NULL, + OPERATIONCODE VARCHAR(25) NOT NULL, PRIMARY KEY (ID) ); 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 0e8cd993cb..a7e39bff60 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 @@ -28,6 +28,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( RECEIVED_TIMESTAMP TIMESTAMP NULL, STATUS VARCHAR(50) NULL, PAYLOAD CLOB NULL, + OPERATIONCODE VARCHAR(25) NOT NULL, PRIMARY KEY (ID) );