diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 450fd923a3..83527c0c0a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -39,6 +39,8 @@ public class Operation { private int id; private String payLoad; private Status status; + private String receivedTimeStamp; + private String createdTimeStamp; @XmlElement public String getCode() { @@ -91,4 +93,20 @@ public class Operation { this.status = status; } + public String getReceivedTimeStamp() { + return receivedTimeStamp; + } + + public void setReceivedTimeStamp(String receivedTimeStamp) { + this.receivedTimeStamp = receivedTimeStamp; + } + + public String getCreatedTimeStamp() { + return createdTimeStamp; + } + + public void setCreatedTimeStamp(String createdTimeStamp) { + this.createdTimeStamp = createdTimeStamp; + } + } \ No newline at end of file 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/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 48febb5158..f6eabf6ded 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -19,13 +19,35 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; public class ConfigOperationDAOImpl extends OperationDAOImpl { @Override public int addOperation(Operation operation) throws OperationManagementDAOException { - return 0; - } + int operationId = super.addOperation(operation); + ConfigOperation commandOp = (ConfigOperation) operation; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID) VALUES(?)"); + stmt.setInt(1, operationId); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding command operation", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return operationId; + } } 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 05320aed1d..3870e1c4d9 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 @@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; - import java.sql.*; import java.util.ArrayList; import java.util.Date; @@ -33,6 +32,7 @@ import java.util.List; public class OperationDAOImpl implements OperationDAO { public int addOperation(Operation operation) throws OperationManagementDAOException { + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -60,7 +60,30 @@ public class OperationDAOImpl implements OperationDAO { @Override public int updateOperation(Operation operation) throws OperationManagementDAOException { - return 0; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + stmt = connection.prepareStatement( + "UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=?,O.STATUS=? WHERE O.ID=?"); + + stmt.setTimestamp(1, new Timestamp(new Date().getTime())); + stmt.setString(2, operation.getStatus().toString()); + stmt.setInt(3,operation.getId()); + stmt.executeUpdate(); + + rs = stmt.getGeneratedKeys(); + int id = -1; + if (rs.next()) { + id = rs.getInt(1); + } + return id; + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } } @Override