From 2e811aa12b080a9b759794170ff8648a860d7607 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 18 Sep 2019 08:11:20 +0530 Subject: [PATCH] Fix config fetching and device type filtering for tenants --- .../DeviceManagementProviderServiceImpl.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) 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 dd552c6868..ea8d1712fb 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 @@ -1410,29 +1410,26 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes(); Map registeredTypes = pluginRepository.getAllDeviceManagementServices(tenantId); - Set deviceTypeSetForTenant = new HashSet<>(); - - if (registeredTypes != null) { - if (deviceTypesProvidedByTenant != null) { - for (DeviceType deviceType : deviceTypesProvidedByTenant) { - DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType.getName(), tenantId); - if (registeredTypes.get(providerKey) != null || deviceType.getDeviceTypeMetaDefinition() != null) { - deviceTypesResponse.add(deviceType.getName()); - deviceTypeSetForTenant.add(deviceType.getName()); - } + // Get the device from the public space, however if there is another device with same name then give + // priority to that + if (deviceTypesProvidedByTenant != null) { + for (DeviceType deviceType : deviceTypesProvidedByTenant) { + deviceTypesResponse.add(deviceType.getName()); + } + } + if (publicSharedDeviceTypesInDB != null) { + for (String deviceType: publicSharedDeviceTypesInDB) { + if (!deviceTypesResponse.contains(deviceType)) { + deviceTypesResponse.add(deviceType); } } - // Get the device from the public space, however if there is another device with same name then give - // priority to that - if (publicSharedDeviceTypesInDB != null) { - for (String deviceType : publicSharedDeviceTypesInDB) { - DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType); - if (registeredTypes.get(providerKey) != null && !deviceTypeSetForTenant.contains(deviceType)) { - deviceTypesResponse.add(deviceType); - } + } + if (registeredTypes != null) { + for (DeviceTypeServiceIdentifier deviceType: registeredTypes.keySet()) { + if (!deviceTypesResponse.contains(deviceType.getDeviceType())) { + deviceTypesResponse.add(deviceType.getDeviceType()); } } - } } catch (DeviceManagementDAOException e) { String msg = "Error occurred while obtaining the device types."; @@ -3489,12 +3486,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } try { - Device device = this.getDevice(new DeviceIdentifier(deviceProperties.getDeviceIdentifier(), - deviceProperties.getDeviceTypeName()), false); - String owner = device.getEnrolmentInfo().getOwner(); PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantId(Integer.parseInt(deviceProperties.getTenantId()), true); + Device device = this.getDevice(new DeviceIdentifier(deviceProperties.getDeviceIdentifier(), + deviceProperties.getDeviceTypeName()), false); + String owner = device.getEnrolmentInfo().getOwner(); PlatformConfiguration configuration = this.getConfiguration(device.getType()); List configurationEntries = new ArrayList<>(); if (configuration != null) {