Change Next operations method to accept parameter device id

4.x.x
manoj 10 years ago
parent 86813aac52
commit bf62561b00

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -195,19 +196,32 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
if (log.isDebugEnabled()) { 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; Operation operation = null;
Device device;
try { 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 org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
.getNextOperation(deviceId); .getNextOperation(device.getId());
if (dtoOperation != null) { if (dtoOperation != null) {
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} }
return operation; return operation;
} 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) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving next pending operation", e); throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
} }

@ -42,6 +42,6 @@ public interface OperationDAO {
List<? extends Operation> getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException; List<? extends Operation> getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException;
Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException; Operation getNextOperation(int deviceId) throws OperationManagementDAOException;
} }

@ -462,7 +462,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = 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 " + "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"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
stmt.setString(1, deviceId.getType()); stmt.setString(1, Operation.Status.PENDING.toString());
stmt.setString(2, deviceId.getId()); stmt.setInt(2, deviceId);
stmt.setString(3, Operation.Status.PENDING.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
Operation operation = null; Operation operation = null;

@ -59,7 +59,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
return operationId; return operationId;
} }
@Override
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;

Loading…
Cancel
Save