Operations Refractor

revert-70aa11f8
manoj 10 years ago
parent 4f4240f176
commit 5a4e4ec4a0

@ -37,7 +37,7 @@ public interface OperationManager {
* operation * operation
*/ */
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
OperationManagementException; OperationManagementException, DeviceManagementException;
/** /**
* Method to retrieve the list of all operations to a device. * Method to retrieve the list of all operations to a device.

@ -67,6 +67,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
this.licenseManager = new LicenseManagerImpl(); this.licenseManager = new LicenseManagerImpl();
} }
public DeviceManagementServiceProviderImpl(){
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.operationManager = new OperationManagerImpl();
this.licenseManager = new LicenseManagerImpl();
}
@Override @Override
public String getProviderType() { public String getProviderType() {
return null; return null;
@ -84,6 +91,24 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
return dms.getFeatureManager(); return dms.getFeatureManager();
} }
@Override
public Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device convertedDevice = null;
try {
DeviceType deviceType = this.getDeviceTypeDAO().getDeviceType(deviceId.getType());
org.wso2.carbon.device.mgt.core.dto.Device device = this.getDeviceDAO().getDevice(deviceId);
if (device != null) {
convertedDevice = DeviceManagementDAOUtil.convertDevice(device,
this.getDeviceTypeDAO().getDeviceType(deviceType.getId()));
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "' and type:"+deviceId.getType(), e);
}
return convertedDevice;
}
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
@ -336,8 +361,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override @Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); DeviceManager dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
Device convertedDevice = null; Device convertedDevice = null;
try { try {
DeviceType deviceType = DeviceType deviceType =
@ -375,10 +400,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
return dms.setOwnership(deviceId, ownershipType); return dms.setOwnership(deviceId, ownershipType);
} }
public OperationManager getOperationManager(String type) throws DeviceManagementException {
return operationManager;
}
@Override @Override
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
return licenseManager.getLicense(deviceType, languageCode); return licenseManager.getLicense(deviceType, languageCode);
@ -402,8 +423,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
} }
@Override @Override
public boolean addOperation(Operation operation, public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
List<DeviceIdentifier> devices) throws OperationManagementException { OperationManagementException, DeviceManagementException {
return operationManager.addOperation(operation, devices); return operationManager.addOperation(operation, devices);
} }

@ -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,14 +74,21 @@ 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);
operationMappingDAO.addOperationMapping(operationId, device.getId()); 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());
}
} }
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
return true; return true;
@ -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;
} }
} }
} }

@ -66,6 +66,7 @@ public class OperationDAOImpl implements OperationDAO {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
} }
@ -398,7 +399,7 @@ public class OperationDAOImpl implements OperationDAO {
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
ByteArrayInputStream bais; ByteArrayInputStream byteArrayInputStream;
ObjectInputStream ois; ObjectInputStream ois;
List<Operation> operationList = new ArrayList<Operation>(); List<Operation> operationList = new ArrayList<Operation>();
@ -419,8 +420,8 @@ public class OperationDAOImpl implements OperationDAO {
if (rs.getBytes("OPERATION_DETAILS") != null) { if (rs.getBytes("OPERATION_DETAILS") != null) {
byte[] operationDetails; byte[] operationDetails;
operationDetails = rs.getBytes("OPERATION_DETAILS"); operationDetails = rs.getBytes("OPERATION_DETAILS");
bais = new ByteArrayInputStream(operationDetails); byteArrayInputStream = new ByteArrayInputStream(operationDetails);
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(byteArrayInputStream);
operation = (ProfileOperation) ois.readObject(); operation = (ProfileOperation) ois.readObject();
} else { } else {
operation = new Operation(); operation = new Operation();

@ -17,10 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.core.service; package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
@ -44,4 +41,12 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
FeatureManager getFeatureManager(String type) throws DeviceManagementException; FeatureManager getFeatureManager(String type) throws DeviceManagementException;
/**
* This method returns core device details.
* @param deviceId
* @return
* @throws DeviceManagementException
*/
Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
} }

@ -86,6 +86,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatureManager(type); return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatureManager(type);
} }
@Override
public Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getCoreDevice(deviceId);
}
@Override @Override
public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId)
throws DeviceManagementException { throws DeviceManagementException {
@ -116,7 +121,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@Override @Override
public boolean addOperation(Operation operation, public boolean addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException { List<DeviceIdentifier> devices) throws OperationManagementException, DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices); return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices);
} }

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
@ -58,6 +59,7 @@ public class DeviceOperationManagementTests extends DeviceManagementBaseTest {
private void initOperationManager() { private void initOperationManager() {
this.operationManager = new OperationManagerImpl(); this.operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(new DeviceManagementServiceProviderImpl());
} }
@Test @Test

@ -54,7 +54,7 @@ public class ProfileDAOImpl implements ProfileDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_PROFILE (PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?)"; String query = "INSERT INTO DM_PROFILE (PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, profile.getProfileName()); stmt.setString(1, profile.getProfileName());
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -108,7 +108,7 @@ public class ProfileDAOImpl implements ProfileDAO {
conn = this.getConnection(); conn = this.getConnection();
String query = "UPDATE DM_PROFILE SET PROFILE_NAME = ? ,TENANT_ID = ?, DEVICE_TYPE_ID = ? , UPDATED_TIME = ? " + String query = "UPDATE DM_PROFILE SET PROFILE_NAME = ? ,TENANT_ID = ?, DEVICE_TYPE_ID = ? , UPDATED_TIME = ? " +
"WHERE ID = ?"; "WHERE ID = ?";
stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, profile.getProfileName()); stmt.setString(1, profile.getProfileName());
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);

Loading…
Cancel
Save