From 5a4e4ec4a03aeb16741d8026e35e8117682978ff Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 28 Apr 2015 14:42:59 +0530 Subject: [PATCH 1/2] Operations Refractor --- .../operation/mgt/OperationManager.java | 2 +- .../DeviceManagementServiceProviderImpl.java | 37 +++- .../operation/mgt/OperationManagerImpl.java | 188 ++++++++++-------- .../mgt/dao/impl/OperationDAOImpl.java | 7 +- .../core/service/DeviceManagementService.java | 13 +- .../service/DeviceManagementServiceImpl.java | 7 +- .../core/DeviceOperationManagementTests.java | 2 + .../mgt/core/dao/impl/ProfileDAOImpl.java | 4 +- 8 files changed, 157 insertions(+), 103 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index a7680c42d91..e7b0e4f8c3f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -37,7 +37,7 @@ public interface OperationManager { * operation */ public boolean addOperation(Operation operation, List devices) throws - OperationManagementException; + OperationManagementException, DeviceManagementException; /** * Method to retrieve the list of all operations to a device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 5968b153653..395c45c2d14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -67,6 +67,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ this.licenseManager = new LicenseManagerImpl(); } + public DeviceManagementServiceProviderImpl(){ + this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); + this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + this.operationManager = new OperationManagerImpl(); + this.licenseManager = new LicenseManagerImpl(); + } + @Override public String getProviderType() { return null; @@ -84,6 +91,24 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ 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 public boolean enrollDevice(Device device) throws DeviceManagementException { DeviceManager dms = @@ -336,8 +361,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManager dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + + DeviceManager dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); Device convertedDevice = null; try { DeviceType deviceType = @@ -375,10 +400,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ return dms.setOwnership(deviceId, ownershipType); } - public OperationManager getOperationManager(String type) throws DeviceManagementException { - return operationManager; - } - @Override public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { return licenseManager.getLicense(deviceType, languageCode); @@ -402,8 +423,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { + public boolean addOperation(Operation operation, List devices) throws + OperationManagementException, DeviceManagementException { return operationManager.addOperation(operation, devices); } 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 10f8a5e6fe8..241b73858b6 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 @@ -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.OperationManagementException; 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.OperationManagementDAOException; 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.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.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 * methods available in OperationManagementDAOFactory. */ @@ -51,21 +49,21 @@ public class OperationManagerImpl implements OperationManager { private OperationDAO configOperationDAO; private OperationDAO profileOperationDAO; private OperationMappingDAO operationMappingDAO; - private DeviceDAO deviceDAO; private OperationDAO operationDAO; + private DeviceManagementService deviceManagementService; public OperationManagerImpl() { commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO(); profileOperationDAO = OperationManagementDAOFactory.getProfileOperationDAO(); operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO(); - deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); operationDAO = OperationManagementDAOFactory.getOperationDAO(); + deviceManagementService = new DeviceManagementServiceImpl(); } @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { + public boolean addOperation(Operation operation, List devices) throws + OperationManagementException { if (log.isDebugEnabled()) { log.debug("operation:[" + operation.toString() + "]"); @@ -76,14 +74,21 @@ public class OperationManagerImpl implements OperationManager { } try { OperationManagementDAOFactory.beginTransaction(); - - org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil - .convertOperation(operation); + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = + OperationDAOUtil.convertOperation(operation); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); + org.wso2.carbon.device.mgt.common.Device device; for (DeviceIdentifier deviceIdentifier : devices) { - Device device = deviceDAO.getDevice(deviceIdentifier); - operationMappingDAO.addOperationMapping(operationId, device.getId()); + 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()); + } } OperationManagementDAOFactory.commitTransaction(); return true; @@ -95,29 +100,38 @@ public class OperationManagerImpl implements OperationManager { log.warn("Error occurred while roll-backing the transaction", e1); } throw new OperationManagementException("Error occurred while adding operation", e); - } catch (DeviceManagementDAOException e) { - log.error("Error occurred while adding operation device mapping: ", e); + } catch (DeviceManagementException deviceMgtEx) { try { OperationManagementDAOFactory.rollbackTransaction(); } catch (OperationManagementDAOException 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 - public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + public List getOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + try { List operations = new ArrayList(); - Device device; + org.wso2.carbon.device.mgt.common.Device device; + try { - device = deviceDAO.getDevice(deviceId); - } catch (DeviceManagementDAOException deviceDAOException) { + device = deviceManagementService.getCoreDevice(deviceIdentifier); + } catch (DeviceManagementException deviceMgtEx) { String errorMsg = "Error occurred while retrieving the device " + - "for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(); - log.error(errorMsg, deviceDAOException); - throw new OperationManagementException(errorMsg, deviceDAOException); + "for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" + + deviceIdentifier.getId(); + 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 operationList = operationDAO .getOperationsForDevice(device.getId()); @@ -129,40 +143,52 @@ public class OperationManagerImpl implements OperationManager { return operations; } catch (OperationManagementDAOException e) { 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 - public List getPendingOperations(DeviceIdentifier deviceId) + public List getPendingOperations(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() + + "]"); } + org.wso2.carbon.device.mgt.common.Device device; + List operations; + List dtoOperationList; + try { - Device device; - device = deviceDAO.getDevice(deviceId); - List operations = new ArrayList(); - List dtoOperationList = - operationDAO.getOperationsByDeviceAndStatus(device.getId(), org.wso2.carbon.device.mgt.core.dto - .operation.mgt.Operation.Status.PENDING); + + device = deviceManagementService.getCoreDevice(deviceIdentifier); + + if (device == null) { + throw new OperationManagementException("Device not found for given device " + + "Identifier:" + deviceIdentifier.getId() + " and given type" + deviceIdentifier.getType()); + } + operations = new ArrayList(); + dtoOperationList = operationDAO.getOperationsByDeviceAndStatus(device.getId(), + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING); + Operation operation; for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) { operation = OperationDAOUtil.convertOperation(dtoOperation); operations.add(operation); } return operations; - } catch (DeviceManagementDAOException deviceDAOException) { + } catch (DeviceManagementException deviceMgtException) { String errorMsg = "Error occurred while retrieving the device " + - "for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(); - log.error(errorMsg, deviceDAOException); - throw new OperationManagementException(errorMsg, deviceDAOException); + "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 the list of " + - "pending operations assigned for '" + deviceId.getType() + "' device '" + - deviceId.getId() + "'", e); + "pending operations assigned for '" + deviceIdentifier.getType() + "' device '" + + deviceIdentifier.getId() + "'", e); } } @@ -172,10 +198,10 @@ public class OperationManagerImpl implements OperationManager { if (log.isDebugEnabled()) { log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); } + Operation operation = null; try { org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO .getNextOperation(deviceId); - Operation operation = null; if (dtoOperation != null) { operation = OperationDAOUtil.convertOperation(dtoOperation); } @@ -194,8 +220,8 @@ public class OperationManagerImpl implements OperationManager { } try { - org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation - (operationId); + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = + operationDAO.getOperation(operationId); if (dtoOperation == null) { 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 (operationStatus.toString())); OperationManagementDAOFactory.beginTransaction(); - operationDAO.updateOperation(dtoOperation); + lookupOperationDAO(dtoOperation).updateOperation(dtoOperation); OperationManagementDAOFactory.commitTransaction(); } catch (OperationManagementDAOException ex) { try { @@ -228,21 +254,14 @@ public class OperationManagerImpl implements OperationManager { 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)) { - 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); - } + lookupOperationDAO(operation).deleteOperation(operationId); OperationManagementDAOFactory.commitTransaction(); + } catch (OperationManagementDAOException ex) { try { OperationManagementDAOFactory.rollbackTransaction(); - } catch (OperationManagementDAOException e1) { - log.warn("Error occurred while roll-backing the delete operation transaction", e1); + } catch (OperationManagementDAOException e) { + log.warn("Error occurred while roll-backing the delete operation transaction", e); } log.error("Error occurred while deleting the operation: " + operationId, 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) throws OperationManagementException { - Device device; + org.wso2.carbon.device.mgt.common.Device device; Operation operation; 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 { - device = deviceDAO.getDevice(deviceIdentifier); + device = deviceManagementService.getCoreDevice(deviceIdentifier); if (device == null) { - throw new OperationManagementException( - "Device not found for given device identifier:" + deviceIdentifier.getId - () + " type:" + deviceIdentifier.getType()); + throw new OperationManagementException("Device not found for given device identifier:" + + deviceIdentifier.getId() + " type:" + deviceIdentifier.getType()); } org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO .getOperationByDeviceAndId(device.getId(), operationId); if (dtoOperation == null) { - throw new OperationManagementException( - "Operation not found for operation Id:" + operationId + " device" + - " Id:" + device.getId()); + throw new OperationManagementException("Operation not found for operation Id:" + operationId + + " device" + " Id:" + device.getId()); } operation = OperationDAOUtil.convertOperation(dtoOperation); - } catch (DeviceManagementDAOException deviceDAOException) { + } 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, deviceDAOException); - throw new OperationManagementException(errorMsg, deviceDAOException); + log.error(errorMsg, deviceMgtException); + throw new OperationManagementException(errorMsg, deviceMgtException); } catch (OperationManagementDAOException e) { throw new OperationManagementException("Error occurred while retrieving the list of " + "operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId() @@ -296,27 +316,28 @@ public class OperationManagerImpl implements OperationManager { try { List operations = new ArrayList(); - Device device = deviceDAO.getDevice(identifier); + org.wso2.carbon.device.mgt.common.Device device = deviceManagementService.getCoreDevice(identifier); if (device == null) { throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " + "type:" + identifier.getType()); } - List dtoOperationList = operationDAO - .getOperationsByDeviceAndStatus(device.getId(), + List dtoOperationList = + operationDAO.getOperationsByDeviceAndStatus(device.getId(), org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status .valueOf(status.toString())); + Operation operation; for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) { operation = OperationDAOUtil.convertOperation(dtoOperation); operations.add(operation); } return operations; - } catch (DeviceManagementDAOException deviceDAOException) { + } catch (DeviceManagementException deviceMgtException) { String errorMsg = "Error occurred while retrieving the device " + "for device Identifier type -'" + identifier.getType() + "' and device Id '" + identifier.getId(); - log.error(errorMsg, deviceDAOException); - throw new OperationManagementException(errorMsg, deviceDAOException); + log.error(errorMsg, deviceMgtException); + throw new OperationManagementException(errorMsg, deviceMgtException); } catch (OperationManagementDAOException e) { throw new OperationManagementException("Error occurred while retrieving the list of " + "operations assigned for '" + identifier.getType() + "' device '" + @@ -350,8 +371,8 @@ public class OperationManagerImpl implements OperationManager { try { List operations = new ArrayList(); List dtoOperationList = - operationDAO - .getOperationsForStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status + operationDAO.getOperationsForStatus( + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status .valueOf(status.toString())); Operation operation; 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) { - switch (type) { - case CONFIG: - return configOperationDAO; - case PROFILE: - return profileOperationDAO; - case COMMAND: - return commandOperationDAO; - default: + private OperationDAO lookupOperationDAO(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation) { + + if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) { 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; } } - } 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 6f2f6f95b91..c19f157ef82 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 @@ -66,6 +66,7 @@ public class OperationDAOImpl implements OperationDAO { throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); } finally { OperationManagementDAOUtil.cleanupResources(stmt, rs); + OperationManagementDAOFactory.closeConnection(); } } @@ -398,7 +399,7 @@ public class OperationDAOImpl implements OperationDAO { ResultSet rs = null; Operation operation; - ByteArrayInputStream bais; + ByteArrayInputStream byteArrayInputStream; ObjectInputStream ois; List operationList = new ArrayList(); @@ -419,8 +420,8 @@ public class OperationDAOImpl implements OperationDAO { if (rs.getBytes("OPERATION_DETAILS") != null) { byte[] operationDetails; operationDetails = rs.getBytes("OPERATION_DETAILS"); - bais = new ByteArrayInputStream(operationDetails); - ois = new ObjectInputStream(bais); + byteArrayInputStream = new ByteArrayInputStream(operationDetails); + ois = new ObjectInputStream(byteArrayInputStream); operation = (ProfileOperation) ois.readObject(); } else { operation = new Operation(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 1f302ba9dca..812e165c19e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -17,10 +17,7 @@ */ package org.wso2.carbon.device.mgt.core.service; -import org.wso2.carbon.device.mgt.common.Device; -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.*; 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.operation.mgt.OperationManager; @@ -44,4 +41,12 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager, FeatureManager getFeatureManager(String type) throws DeviceManagementException; + /** + * This method returns core device details. + * @param deviceId + * @return + * @throws DeviceManagementException + */ + Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index 1a2fefc443c..09b13bf95b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -86,6 +86,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatureManager(type); } + @Override + public Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getCoreDevice(deviceId); + } + @Override public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { @@ -116,7 +121,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @Override public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { + List devices) throws OperationManagementException, DeviceManagementException { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java index a51ff423837..2772ac8ee9e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java @@ -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.OperationManagementException; 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.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; @@ -58,6 +59,7 @@ public class DeviceOperationManagementTests extends DeviceManagementBaseTest { private void initOperationManager() { this.operationManager = new OperationManagerImpl(); + DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(new DeviceManagementServiceProviderImpl()); } @Test diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java index 36ac7a4b734..e0ae50f2035 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java @@ -54,7 +54,7 @@ public class ProfileDAOImpl implements ProfileDAO { try { conn = this.getConnection(); 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.setInt(2, tenantId); @@ -108,7 +108,7 @@ public class ProfileDAOImpl implements ProfileDAO { conn = this.getConnection(); String query = "UPDATE DM_PROFILE SET PROFILE_NAME = ? ,TENANT_ID = ?, DEVICE_TYPE_ID = ? , UPDATED_TIME = ? " + "WHERE ID = ?"; - stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, profile.getProfileName()); stmt.setInt(2, tenantId); From 2d5f8fe9378f44f38a32e01f949cc88efe2e0c6c Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 28 Apr 2015 17:57:06 +0530 Subject: [PATCH 2/2] Refractor Operations Mgt --- .../device/mgt/common/operation/mgt/OperationManager.java | 3 +-- .../device/mgt/core/DeviceManagementServiceProviderImpl.java | 2 +- .../device/mgt/core/service/DeviceManagementServiceImpl.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index e7b0e4f8c3f..1a8991ba858 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -36,8 +36,7 @@ public interface OperationManager { * @throws OperationManagementException If some unusual behaviour is observed while adding the * operation */ - public boolean addOperation(Operation operation, List devices) throws - OperationManagementException, DeviceManagementException; + public boolean addOperation(Operation operation, List devices) throws OperationManagementException; /** * Method to retrieve the list of all operations to a device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 395c45c2d14..e294a7bcf5c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -424,7 +424,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ @Override public boolean addOperation(Operation operation, List devices) throws - OperationManagementException, DeviceManagementException { + OperationManagementException { return operationManager.addOperation(operation, devices); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index 09b13bf95b3..bb662a14c52 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -120,8 +120,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException, DeviceManagementException { + public boolean addOperation(Operation operation, List devices) + throws OperationManagementException { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices); }