From ec9451d4444fc3dfe22bdb1a6805f4a5098767e2 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Sun, 24 Feb 2019 16:22:00 +1100 Subject: [PATCH] Retrieve devices that only matches the app platform In the current implementation, all active devices are retreived to the app detail page regardless of the app type/platform this lets users select devices which are incompatible with the app. This fix resolves this issue by only fetching the devices which are compatible with the app type. Resolves product-iots#54 --- .../ApplicationOperationsImpl.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java index 7e2aeb6cc9..619328b138 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java @@ -243,28 +243,30 @@ public class ApplicationOperationsImpl implements ApplicationOperations { /** * @param applicationOperationDevice holds the information needs to retrieve device list. * @return List of devices - * @throws MobileApplicationException + * @throws MobileApplicationException If unexpected error occur in getting devices or if app platform is not supported. */ public List getDevices(ApplicationOperationDevice applicationOperationDevice) throws MobileApplicationException { List devices; - List deviceList = null; + List deviceList; try { DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils .getDeviceManagementService(applicationOperationDevice.getTenantId()); final String username = applicationOperationDevice.getCurrentUser().getUsername(); - if (MDMAppConstants.WEBAPP.equals - (applicationOperationDevice.getPlatform())) { - deviceList = deviceManagementService. - getDevicesOfUser(username); - } else { - deviceList = deviceManagementService. - getDevicesOfUser(username, - MDMAppConstants.ANDROID); - deviceList.addAll(deviceManagementService. - getDevicesOfUser(username, - MDMAppConstants.IOS)); + final String platform = applicationOperationDevice.getPlatform(); + switch (platform) { + case MDMAppConstants.WEBAPP: + deviceList = deviceManagementService.getDevicesOfUser(username); + break; + case MDMAppConstants.ANDROID: + deviceList = deviceManagementService.getDevicesOfUser(username, MDMAppConstants.ANDROID); + break; + case MDMAppConstants.IOS: + deviceList = deviceManagementService.getDevicesOfUser(username, MDMAppConstants.IOS); + break; + default: + throw new MobileApplicationException("App platform:" + platform + "is not supported."); } devices = new ArrayList<>(deviceList.size()); if(log.isDebugEnabled()){