|
|
@ -25,21 +25,19 @@ 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;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This class implements all the functionalities exposed as part of the OperationManager. Any transaction initiated
|
|
|
|
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
|
|
|
|
* upon persisting information related to operation state, etc has to be managed, demarcated and terminated via the
|
|
|
|
* upon persisting information related to operation state, etc has to be managed, demarcated and terminated via the
|
|
|
|
* methods available in OperationManagementDAOFactory.
|
|
|
|
* methods available in OperationManagementDAOFactory.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -51,21 +49,21 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
private OperationDAO configOperationDAO;
|
|
|
|
private OperationDAO configOperationDAO;
|
|
|
|
private OperationDAO profileOperationDAO;
|
|
|
|
private OperationDAO profileOperationDAO;
|
|
|
|
private OperationMappingDAO operationMappingDAO;
|
|
|
|
private OperationMappingDAO operationMappingDAO;
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
|
|
|
|
private OperationDAO operationDAO;
|
|
|
|
private OperationDAO operationDAO;
|
|
|
|
|
|
|
|
private DeviceManagementService deviceManagementService;
|
|
|
|
|
|
|
|
|
|
|
|
public OperationManagerImpl() {
|
|
|
|
public OperationManagerImpl() {
|
|
|
|
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
|
|
|
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
|
|
|
configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO();
|
|
|
|
configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO();
|
|
|
|
profileOperationDAO = OperationManagementDAOFactory.getProfileOperationDAO();
|
|
|
|
profileOperationDAO = OperationManagementDAOFactory.getProfileOperationDAO();
|
|
|
|
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
|
|
|
|
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
|
|
|
|
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
|
|
|
|
operationDAO = OperationManagementDAOFactory.getOperationDAO();
|
|
|
|
operationDAO = OperationManagementDAOFactory.getOperationDAO();
|
|
|
|
|
|
|
|
deviceManagementService = new DeviceManagementServiceImpl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addOperation(Operation operation,
|
|
|
|
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
|
|
|
|
List<DeviceIdentifier> devices) throws OperationManagementException {
|
|
|
|
OperationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("operation:[" + operation.toString() + "]");
|
|
|
|
log.debug("operation:[" + operation.toString() + "]");
|
|
|
@ -76,15 +74,22 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil
|
|
|
|
OperationDAOUtil.convertOperation(operation);
|
|
|
|
.convertOperation(operation);
|
|
|
|
|
|
|
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
|
|
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device;
|
|
|
|
|
|
|
|
|
|
|
|
for (DeviceIdentifier deviceIdentifier : devices) {
|
|
|
|
for (DeviceIdentifier deviceIdentifier : devices) {
|
|
|
|
Device device = deviceDAO.getDevice(deviceIdentifier);
|
|
|
|
device = deviceManagementService.getCoreDevice(deviceIdentifier);
|
|
|
|
|
|
|
|
if (device == null) {
|
|
|
|
|
|
|
|
String errorMsg = "The operation not added for device.The device not found for " +
|
|
|
|
|
|
|
|
"device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
|
|
|
|
log.info(errorMsg);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
operationMappingDAO.addOperationMapping(operationId, device.getId());
|
|
|
|
operationMappingDAO.addOperationMapping(operationId, device.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
@ -95,29 +100,38 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
log.warn("Error occurred while roll-backing the transaction", e1);
|
|
|
|
log.warn("Error occurred while roll-backing the transaction", e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
log.error("Error occurred while adding operation device mapping: ", e);
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
} catch (OperationManagementDAOException e1) {
|
|
|
|
} catch (OperationManagementDAOException e1) {
|
|
|
|
log.warn("Error occurred while roll-backing the transaction", e1);
|
|
|
|
log.warn("Error occurred while roll-backing the transaction", e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
String errorMsg = "Error occurred fetching devices ";
|
|
|
|
|
|
|
|
log.error(deviceMgtEx.getErrorMessage(), deviceMgtEx);
|
|
|
|
|
|
|
|
throw new OperationManagementException(errorMsg, deviceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
|
|
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
|
|
|
|
|
|
|
throws OperationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
Device device;
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = deviceDAO.getDevice(deviceId);
|
|
|
|
device = deviceManagementService.getCoreDevice(deviceIdentifier);
|
|
|
|
} catch (DeviceManagementDAOException deviceDAOException) {
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId();
|
|
|
|
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" +
|
|
|
|
log.error(errorMsg, deviceDAOException);
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
throw new OperationManagementException(errorMsg, deviceDAOException);
|
|
|
|
log.error(errorMsg, deviceMgtEx);
|
|
|
|
|
|
|
|
throw new OperationManagementException(errorMsg, deviceMgtEx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device == null) {
|
|
|
|
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
|
|
|
|
"Identifier:" + deviceIdentifier.getId() + " and given type" + deviceIdentifier.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = operationDAO
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = operationDAO
|
|
|
|
.getOperationsForDevice(device.getId());
|
|
|
|
.getOperationsForDevice(device.getId());
|
|
|
@ -129,40 +143,52 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
return operations;
|
|
|
|
return operations;
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() + "'", e);
|
|
|
|
"operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId()
|
|
|
|
|
|
|
|
+ "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId)
|
|
|
|
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
|
|
|
throws OperationManagementException {
|
|
|
|
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()
|
|
|
|
|
|
|
|
+ "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device;
|
|
|
|
|
|
|
|
List<Operation> operations;
|
|
|
|
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Device device;
|
|
|
|
|
|
|
|
device = deviceDAO.getDevice(deviceId);
|
|
|
|
device = deviceManagementService.getCoreDevice(deviceIdentifier);
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
|
|
if (device == null) {
|
|
|
|
operationDAO.getOperationsByDeviceAndStatus(device.getId(), org.wso2.carbon.device.mgt.core.dto
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
.operation.mgt.Operation.Status.PENDING);
|
|
|
|
"Identifier:" + deviceIdentifier.getId() + " and given type" + deviceIdentifier.getType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operations = new ArrayList<Operation>();
|
|
|
|
|
|
|
|
dtoOperationList = operationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING);
|
|
|
|
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
operations.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operations;
|
|
|
|
return operations;
|
|
|
|
} catch (DeviceManagementDAOException deviceDAOException) {
|
|
|
|
} catch (DeviceManagementException deviceMgtException) {
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId();
|
|
|
|
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
|
|
|
|
log.error(errorMsg, deviceDAOException);
|
|
|
|
+ deviceIdentifier.getId();
|
|
|
|
throw new OperationManagementException(errorMsg, deviceDAOException);
|
|
|
|
log.error(errorMsg, deviceMgtException);
|
|
|
|
|
|
|
|
throw new OperationManagementException(errorMsg, deviceMgtException);
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
"pending operations assigned for '" + deviceId.getType() + "' device '" +
|
|
|
|
"pending operations assigned for '" + deviceIdentifier.getType() + "' device '" +
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
deviceIdentifier.getId() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -172,10 +198,10 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
|
|
|
log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Operation operation = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
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(deviceId);
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
if (dtoOperation != null) {
|
|
|
|
if (dtoOperation != null) {
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -194,8 +220,8 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation =
|
|
|
|
(operationId);
|
|
|
|
operationDAO.getOperation(operationId);
|
|
|
|
|
|
|
|
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
throw new OperationManagementException("Operation not found for operation id:" + operationId);
|
|
|
|
throw new OperationManagementException("Operation not found for operation id:" + operationId);
|
|
|
@ -203,7 +229,7 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf
|
|
|
|
dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf
|
|
|
|
(operationStatus.toString()));
|
|
|
|
(operationStatus.toString()));
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
operationDAO.updateOperation(dtoOperation);
|
|
|
|
lookupOperationDAO(dtoOperation).updateOperation(dtoOperation);
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
} catch (OperationManagementDAOException ex) {
|
|
|
|
} catch (OperationManagementDAOException ex) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -228,21 +254,14 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
throw new OperationManagementException("Operation not found for operation id:" + operationId);
|
|
|
|
throw new OperationManagementException("Operation not found for operation id:" + operationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
|
|
|
lookupOperationDAO(operation).deleteOperation(operationId);
|
|
|
|
commandOperationDAO.deleteOperation(operationId);
|
|
|
|
|
|
|
|
} else if (operation.getType().equals(
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
|
|
|
|
|
|
|
configOperationDAO.deleteOperation(operationId);
|
|
|
|
|
|
|
|
} else if (operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
|
|
|
|
|
|
|
.PROFILE)) {
|
|
|
|
|
|
|
|
profileOperationDAO.deleteOperation(operationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (OperationManagementDAOException ex) {
|
|
|
|
} catch (OperationManagementDAOException ex) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
} catch (OperationManagementDAOException e1) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
log.warn("Error occurred while roll-backing the delete operation transaction", e1);
|
|
|
|
log.warn("Error occurred while roll-backing the delete operation transaction", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.error("Error occurred while deleting the operation: " + operationId, ex);
|
|
|
|
log.error("Error occurred while deleting the operation: " + operationId, ex);
|
|
|
|
throw new OperationManagementException("Error occurred while delete operation", ex);
|
|
|
|
throw new OperationManagementException("Error occurred while delete operation", ex);
|
|
|
@ -253,35 +272,36 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int operationId)
|
|
|
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int operationId)
|
|
|
|
throws OperationManagementException {
|
|
|
|
throws OperationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device;
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Device Type:" + deviceIdentifier.getType() + " Id:" + deviceIdentifier.getId());
|
|
|
|
log.debug(
|
|
|
|
|
|
|
|
"Operation Id:" + operationId + " Device Type:" + deviceIdentifier.getType() + " Device Identifier:"
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
deviceIdentifier.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = deviceDAO.getDevice(deviceIdentifier);
|
|
|
|
device = deviceManagementService.getCoreDevice(deviceIdentifier);
|
|
|
|
if (device == null) {
|
|
|
|
if (device == null) {
|
|
|
|
throw new OperationManagementException(
|
|
|
|
throw new OperationManagementException("Device not found for given device identifier:" +
|
|
|
|
"Device not found for given device identifier:" + deviceIdentifier.getId
|
|
|
|
deviceIdentifier.getId() + " type:" + deviceIdentifier.getType());
|
|
|
|
() + " 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
|
|
|
|
.getOperationByDeviceAndId(device.getId(), operationId);
|
|
|
|
.getOperationByDeviceAndId(device.getId(), operationId);
|
|
|
|
|
|
|
|
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
throw new OperationManagementException(
|
|
|
|
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
|
|
|
"Operation not found for operation Id:" + operationId + " device" +
|
|
|
|
" device" + " Id:" + device.getId());
|
|
|
|
" Id:" + device.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
} catch (DeviceManagementDAOException deviceDAOException) {
|
|
|
|
} catch (DeviceManagementException deviceMgtException) {
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
|
|
|
|
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
|
|
|
|
+ deviceIdentifier.getId();
|
|
|
|
+ deviceIdentifier.getId();
|
|
|
|
log.error(errorMsg, deviceDAOException);
|
|
|
|
log.error(errorMsg, deviceMgtException);
|
|
|
|
throw new OperationManagementException(errorMsg, deviceDAOException);
|
|
|
|
throw new OperationManagementException(errorMsg, deviceMgtException);
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
"operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId()
|
|
|
|
"operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId()
|
|
|
@ -296,27 +316,28 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
Device device = deviceDAO.getDevice(identifier);
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device = deviceManagementService.getCoreDevice(identifier);
|
|
|
|
|
|
|
|
|
|
|
|
if (device == null) {
|
|
|
|
if (device == null) {
|
|
|
|
throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " +
|
|
|
|
throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " +
|
|
|
|
"type:" + identifier.getType());
|
|
|
|
"type:" + identifier.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = operationDAO
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
|
|
.getOperationsByDeviceAndStatus(device.getId(),
|
|
|
|
operationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
|
|
.valueOf(status.toString()));
|
|
|
|
.valueOf(status.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
operations.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operations;
|
|
|
|
return operations;
|
|
|
|
} catch (DeviceManagementDAOException deviceDAOException) {
|
|
|
|
} catch (DeviceManagementException deviceMgtException) {
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
String errorMsg = "Error occurred while retrieving the device " +
|
|
|
|
"for device Identifier type -'" + identifier.getType() + "' and device Id '" + identifier.getId();
|
|
|
|
"for device Identifier type -'" + identifier.getType() + "' and device Id '" + identifier.getId();
|
|
|
|
log.error(errorMsg, deviceDAOException);
|
|
|
|
log.error(errorMsg, deviceMgtException);
|
|
|
|
throw new OperationManagementException(errorMsg, deviceDAOException);
|
|
|
|
throw new OperationManagementException(errorMsg, deviceMgtException);
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
"operations assigned for '" + identifier.getType() + "' device '" +
|
|
|
|
"operations assigned for '" + identifier.getType() + "' device '" +
|
|
|
@ -350,8 +371,8 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
|
|
operationDAO
|
|
|
|
operationDAO.getOperationsForStatus(
|
|
|
|
.getOperationsForStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
|
|
.valueOf(status.toString()));
|
|
|
|
.valueOf(status.toString()));
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
@ -378,17 +399,16 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private OperationDAO lookupOperationDAO(Operation.Type type) {
|
|
|
|
private OperationDAO lookupOperationDAO(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation) {
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case CONFIG:
|
|
|
|
if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) {
|
|
|
|
return configOperationDAO;
|
|
|
|
|
|
|
|
case PROFILE:
|
|
|
|
|
|
|
|
return profileOperationDAO;
|
|
|
|
|
|
|
|
case COMMAND:
|
|
|
|
|
|
|
|
return commandOperationDAO;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return commandOperationDAO;
|
|
|
|
return commandOperationDAO;
|
|
|
|
|
|
|
|
} else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation) {
|
|
|
|
|
|
|
|
return profileOperationDAO;
|
|
|
|
|
|
|
|
} else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation) {
|
|
|
|
|
|
|
|
return configOperationDAO;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return operationDAO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|