From 14c6773b57a584439437429ad078ad3f950ac9db Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 29 May 2015 22:26:09 +0530 Subject: [PATCH] Fetch device according to the device identifier --- .../mgt/common/operation/mgt/OperationManager.java | 2 +- .../core/DeviceManagementServiceProviderImpl.java | 2 +- .../core/operation/mgt/OperationManagerImpl.java | 14 +++++++++++--- .../core/service/DeviceManagementServiceImpl.java | 2 +- 4 files changed, 14 insertions(+), 6 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 ff6119aaae4..03e5e520c7d 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,7 @@ public interface OperationManager { public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException; - public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) throws + public void updateOperation(DeviceIdentifier 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 02941bdbe08..595b25b3e22 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,7 +465,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } @Override - public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) + public void updateOperation(DeviceIdentifier deviceId, int operationId, Operation.Status operationStatus) throws OperationManagementException { DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(deviceId,operationId, operationStatus); 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 a95c427b2aa..0eda6992bef 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 deviceId, int operationId, Operation.Status operationStatus) + public void updateOperation(DeviceIdentifier deviceIdentifier, int operationId, Operation.Status operationStatus) throws OperationManagementException { if (log.isDebugEnabled()) { @@ -279,11 +279,19 @@ public class OperationManagerImpl implements OperationManager { } dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf (operationStatus.toString())); + Device device = deviceManagementService.getCoreDevice(deviceIdentifier); + OperationManagementDAOFactory.beginTransaction(); operationDAO.updateOperation(dtoOperation); - operationDAO.updateOperationStatus(deviceId,operationId, - org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(operationStatus.toString())); + operationDAO.updateOperationStatus(device.getId(), operationId, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status + .valueOf(operationStatus.toString())); OperationManagementDAOFactory.commitTransaction(); + }catch (DeviceManagementException ex){ + log.error("Error occurred while fetch the device for device identifier: " + deviceIdentifier.getId() + " " + + "type:" + deviceIdentifier.getType(), ex); + throw new OperationManagementException("Error occurred while update operation", ex); + } catch (OperationManagementDAOException ex) { try { OperationManagementDAOFactory.rollbackTransaction(); 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 d681233abbb..f79ebf09818 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,7 +149,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } @Override - public void updateOperation(int deviceId, int operationId, Operation.Status operationStatus) throws + public void updateOperation(DeviceIdentifier deviceId, int operationId, Operation.Status operationStatus) throws OperationManagementException { DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateOperation(deviceId, operationId, operationStatus);