From 5d107b0d56a768cfb241c8b51d9b658ae077e1af Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 10 Nov 2015 18:46:26 +0530 Subject: [PATCH] Merged changes --- .../DeviceManagementProviderServiceImpl.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 51dbd8f7fe..6a49235aef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -667,6 +667,40 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return device; } + @Override + public Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status) throws DeviceManagementException { + Device device; + try { + DeviceManagementDAOFactory.openConnection(); + device = deviceDAO.getDevice(deviceId, status, this.getTenantId()); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining the device for id " + + "'" + deviceId.getId() + "'", e); + } catch (SQLException e) { + throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + if (device != null) { + // The changes made here to prevent unit tests getting failed. They failed because when running the unit + // tests there is no osgi services. So getDeviceManager() returns a null. + DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); + if (deviceManager == null) { + if (log.isDebugEnabled()) { + log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " + + "Therefore, not attempting method 'getDevice'"); + } + return device; + } + Device pluginSpecificInfo = deviceManager.getDevice(deviceId); + if (pluginSpecificInfo != null) { + device.setFeatures(pluginSpecificInfo.getFeatures()); + device.setProperties(pluginSpecificInfo.getProperties()); + } + } + return device; + } + @Override public List getAvailableDeviceTypes() throws DeviceManagementException { List deviceTypesInDatabase;