diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index ae94f52811..58263e2b25 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -65,6 +65,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis return providers.get(type); } + public Map getAllDeviceManagementServices() { + return providers; + } + @Override public void notifyObserver() { synchronized (providers) { 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 31d84beab5..51dbd8f7fe 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 @@ -47,6 +47,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener { @@ -667,55 +668,35 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status) throws DeviceManagementException { - Device device; + public List getAvailableDeviceTypes() throws DeviceManagementException { + List deviceTypesInDatabase; + List deviceTypesResponse = new ArrayList<>(); try { DeviceManagementDAOFactory.openConnection(); - device = deviceDAO.getDevice(deviceId, status, this.getTenantId()); + deviceTypesInDatabase = deviceDAO.getDeviceTypes(); + Map registeredTypes = pluginRepository.getAllDeviceManagementServices(); + DeviceType deviceType; + + if (registeredTypes != null && deviceTypesInDatabase != null) { + for (int x = 0; x < deviceTypesInDatabase.size(); x++) { + if (registeredTypes.get(deviceTypesInDatabase.get(x).getName()) != null) { + deviceType = new DeviceType(); + deviceType.setId(deviceTypesInDatabase.get(x).getId()); + deviceType.setName(deviceTypesInDatabase.get(x).getName()); + deviceTypesResponse.add(deviceType); + } + } + } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "'", e); + throw new DeviceManagementException("Error occurred while obtaining the device types.", 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; + return deviceTypesResponse; } - @Override - public List getAvailableDeviceTypes() throws DeviceManagementException { - List deviceTypes; - try { - DeviceManagementDAOFactory.openConnection(); - deviceTypes = deviceDAO.getDeviceTypes(); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device types.", e); - } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); - } finally { - DeviceManagementDAOFactory.closeConnection(); - } - return deviceTypes; - } - @Override public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); diff --git a/pom.xml b/pom.xml index 18edc0b79c..e52c77573e 100644 --- a/pom.xml +++ b/pom.xml @@ -501,6 +501,10 @@ org.wso2.carbon org.wso2.carbon.user.api + + xerces.wso2 + xercesImpl + @@ -597,6 +601,10 @@ commons-collections.wso2 commons-collections + + xerces.wso2 + xercesImpl + @@ -825,6 +833,10 @@ javax.servlet servlet-api + + xerces + xercesImpl + @@ -1427,7 +1439,7 @@ 6.1.1 - 4.4.1 + 4.4.2 1.5.4 1.3 @@ -1471,7 +1483,7 @@ 5.0.2 - 4.5.0-m1 + 4.5.0 4.4.8