From bf62561b00108d2c83798c3befb248a4926713ed Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 13 May 2015 23:34:03 +0530 Subject: [PATCH] Change Next operations method to accept parameter device id --- .../operation/mgt/OperationManagerImpl.java | 22 +++++++++++++++---- .../core/operation/mgt/dao/OperationDAO.java | 2 +- .../mgt/dao/impl/OperationDAOImpl.java | 8 +++---- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 1 - 4 files changed, 23 insertions(+), 10 deletions(-) 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 5000bd56a6..6e66527c58 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 @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -195,20 +196,33 @@ public class OperationManagerImpl implements OperationManager { } @Override - public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { + public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { if (log.isDebugEnabled()) { - log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); + log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType() + "]"); } Operation operation = null; + Device device; try { + device = deviceManagementService.getCoreDevice(deviceIdentifier); + + if (device == null) { + throw new OperationManagementException("Device not found for given device " + + "Identifier:" + deviceIdentifier.getId() + " and given type" + deviceIdentifier.getType()); + } org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO - .getNextOperation(deviceId); + .getNextOperation(device.getId()); if (dtoOperation != null) { operation = OperationDAOUtil.convertOperation(dtoOperation); } return operation; - } catch (OperationManagementDAOException e) { + } catch (DeviceManagementException deviceMgtException) { + String errorMsg = "Error occurred while retrieving the device " + + "for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" + + deviceIdentifier.getId(); + log.error(errorMsg, deviceMgtException); + throw new OperationManagementException(errorMsg, deviceMgtException); + } catch (OperationManagementDAOException e) { throw new OperationManagementException("Error occurred while retrieving next pending operation", 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/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 bd7699e670..07572f98c7 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,6 +42,6 @@ public interface OperationDAO { List getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException; - Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException; + Operation getNextOperation(int deviceId) 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 9b996e1069..fdf39f8ddf 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 @@ -462,7 +462,7 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { + public Operation getNextOperation(int deviceId) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; @@ -483,9 +483,9 @@ public class OperationDAOImpl implements OperationDAO { "o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); - stmt.setString(1, deviceId.getType()); - stmt.setString(2, deviceId.getId()); - stmt.setString(3, Operation.Status.PENDING.toString()); + stmt.setString(1, Operation.Status.PENDING.toString()); + stmt.setInt(2, deviceId); + rs = stmt.executeQuery(); Operation operation = null; 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 f59fe6452d..f23e77eafa 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 @@ -59,7 +59,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { return operationId; } - @Override public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { PreparedStatement stmt = null;