Change Next operations method to accept parameter device id

revert-70aa11f8
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.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,19 +196,32 @@ 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 (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);
}

@ -42,6 +42,6 @@ public interface OperationDAO {
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
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;

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

Loading…
Cancel
Save