From 4faa740c9d288894a758b5e4c58c18a2b170ab19 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Tue, 10 Nov 2015 17:36:30 +0530 Subject: [PATCH] Fixing JIRA EMM-947 - only the registered device types are returned to UI --- .../DeviceManagementPluginRepository.java | 4 ++ .../DeviceManagementProviderServiceImpl.java | 45 ++++++++++++------- 2 files changed, 34 insertions(+), 15 deletions(-) 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 8eed2efc67..3caaf9585a 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 { @@ -635,21 +636,35 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return device; } - @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 List getAvailableDeviceTypes() throws DeviceManagementException { + List deviceTypesInDatabase; + List deviceTypesResponse = new ArrayList<>(); + try { + DeviceManagementDAOFactory.openConnection(); + 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 types.", e); + } catch (SQLException e) { + throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + return deviceTypesResponse; + } @Override public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {