From 39b85a3b448ca76d0aec3aebfac781a8b7656311 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 29 May 2015 21:58:15 +0530 Subject: [PATCH] update operation status --- .../operation/mgt/OperationManager.java | 3 ++- .../DeviceManagementServiceProviderImpl.java | 5 ++-- .../operation/mgt/OperationManagerImpl.java | 6 +++-- .../core/operation/mgt/dao/OperationDAO.java | 3 +++ .../mgt/dao/impl/OperationDAOImpl.java | 26 ++++++++++++++++++- .../service/DeviceManagementServiceImpl.java | 5 ++-- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index aded7d9ace..ff6119aaae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -59,7 +59,8 @@ public interface OperationManager { public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException; - public void updateOperation(int operationId, Operation.Status operationStatus) throws OperationManagementException; + public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) throws + OperationManagementException; public void deleteOperation(int operationId) throws OperationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 5ad3489644..02941bdbe0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -465,9 +465,10 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } @Override - public void updateOperation(int operationId, Operation.Status operationStatus) + public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) throws OperationManagementException { - DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(operationId, operationStatus); + DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(deviceId,operationId, + operationStatus); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 1678e7b477..a95c427b2a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -263,7 +263,7 @@ public class OperationManagerImpl implements OperationManager { } @Override - public void updateOperation(int operationId, Operation.Status operationStatus) + public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) throws OperationManagementException { if (log.isDebugEnabled()) { @@ -280,7 +280,9 @@ public class OperationManagerImpl implements OperationManager { dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf (operationStatus.toString())); OperationManagementDAOFactory.beginTransaction(); - lookupOperationDAO(dtoOperation).updateOperation(dtoOperation); + operationDAO.updateOperation(dtoOperation); + operationDAO.updateOperationStatus(deviceId,operationId, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(operationStatus.toString())); OperationManagementDAOFactory.commitTransaction(); } catch (OperationManagementDAOException ex) { try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 8aa4f08c9f..91fb369f19 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -42,4 +42,7 @@ public interface OperationDAO { Operation getNextOperation(int deviceId) throws OperationManagementDAOException; + void updateOperationStatus(int deviceId, int operationId,Operation.Status status) throws + OperationManagementDAOException; + } 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 5eb710eb35..a761dc4448 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 @@ -76,10 +76,34 @@ public class OperationDAOImpl implements OperationDAO { stmt.executeUpdate(); } catch (SQLException e) { - throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); + throw new OperationManagementDAOException("Error occurred while update operation metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt); + } + } + + public void updateOperationStatus(int deviceId, int operationId,Operation.Status status) + throws OperationManagementDAOException{ + + PreparedStatement stmt = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + stmt = connection.prepareStatement("UPDATE DM_DEVICE_OPERATION_MAPPING O SET O.STATUS=? " + + "WHERE O.DEVICE_ID=? and O.OPERATION_ID=?"); + + stmt.setString(1, status.toString()); + stmt.setInt(2, deviceId); + stmt.setInt(3, operationId); + stmt.executeUpdate(); + + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while update device mapping operation status " + + "metadata", + e); } finally { OperationManagementDAOUtil.cleanupResources(stmt); } + } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index 03e50611cb..d681233abb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -149,8 +149,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } @Override - public void updateOperation(int operationId, Operation.Status operationStatus) throws OperationManagementException { - DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateOperation(operationId, + public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) throws + OperationManagementException { + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateOperation(deviceId, operationId, operationStatus); }