Fix config fetching and device type filtering for tenants

feature/appm-store/pbac
Charitha Goonetilleke 5 years ago
parent 2c7463a072
commit 2e811aa12b

@ -1410,29 +1410,26 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes(); publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes();
Map<DeviceTypeServiceIdentifier, DeviceManagementService> registeredTypes = Map<DeviceTypeServiceIdentifier, DeviceManagementService> registeredTypes =
pluginRepository.getAllDeviceManagementServices(tenantId); pluginRepository.getAllDeviceManagementServices(tenantId);
Set<String> deviceTypeSetForTenant = new HashSet<>(); // Get the device from the public space, however if there is another device with same name then give
// priority to that
if (registeredTypes != null) { if (deviceTypesProvidedByTenant != null) {
if (deviceTypesProvidedByTenant != null) { for (DeviceType deviceType : deviceTypesProvidedByTenant) {
for (DeviceType deviceType : deviceTypesProvidedByTenant) { deviceTypesResponse.add(deviceType.getName());
DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType.getName(), tenantId); }
if (registeredTypes.get(providerKey) != null || deviceType.getDeviceTypeMetaDefinition() != null) { }
deviceTypesResponse.add(deviceType.getName()); if (publicSharedDeviceTypesInDB != null) {
deviceTypeSetForTenant.add(deviceType.getName()); 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 (registeredTypes != null) {
if (publicSharedDeviceTypesInDB != null) { for (DeviceTypeServiceIdentifier deviceType: registeredTypes.keySet()) {
for (String deviceType : publicSharedDeviceTypesInDB) { if (!deviceTypesResponse.contains(deviceType.getDeviceType())) {
DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType); deviceTypesResponse.add(deviceType.getDeviceType());
if (registeredTypes.get(providerKey) != null && !deviceTypeSetForTenant.contains(deviceType)) {
deviceTypesResponse.add(deviceType);
}
} }
} }
} }
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String msg = "Error occurred while obtaining the device types."; String msg = "Error occurred while obtaining the device types.";
@ -3489,12 +3486,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
try { try {
Device device = this.getDevice(new DeviceIdentifier(deviceProperties.getDeviceIdentifier(),
deviceProperties.getDeviceTypeName()), false);
String owner = device.getEnrolmentInfo().getOwner();
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ctx.setTenantId(Integer.parseInt(deviceProperties.getTenantId()), true); 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()); PlatformConfiguration configuration = this.getConfiguration(device.getType());
List<ConfigurationEntry> configurationEntries = new ArrayList<>(); List<ConfigurationEntry> configurationEntries = new ArrayList<>();
if (configuration != null) { if (configuration != null) {

Loading…
Cancel
Save