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
revert-dabc3590
Madawa Soysa 6 years ago
parent 972a859113
commit ec9451d444

@ -243,28 +243,30 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
/** /**
* @param applicationOperationDevice holds the information needs to retrieve device list. * @param applicationOperationDevice holds the information needs to retrieve device list.
* @return List of devices * @return List of devices
* @throws MobileApplicationException * @throws MobileApplicationException If unexpected error occur in getting devices or if app platform is not supported.
*/ */
public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice) public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice)
throws MobileApplicationException { throws MobileApplicationException {
List<Device> devices; List<Device> devices;
List<org.wso2.carbon.device.mgt.common.Device> deviceList = null; List<org.wso2.carbon.device.mgt.common.Device> deviceList;
try { try {
DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils
.getDeviceManagementService(applicationOperationDevice.getTenantId()); .getDeviceManagementService(applicationOperationDevice.getTenantId());
final String username = applicationOperationDevice.getCurrentUser().getUsername(); final String username = applicationOperationDevice.getCurrentUser().getUsername();
if (MDMAppConstants.WEBAPP.equals final String platform = applicationOperationDevice.getPlatform();
(applicationOperationDevice.getPlatform())) { switch (platform) {
deviceList = deviceManagementService. case MDMAppConstants.WEBAPP:
getDevicesOfUser(username); deviceList = deviceManagementService.getDevicesOfUser(username);
} else { break;
deviceList = deviceManagementService. case MDMAppConstants.ANDROID:
getDevicesOfUser(username, deviceList = deviceManagementService.getDevicesOfUser(username, MDMAppConstants.ANDROID);
MDMAppConstants.ANDROID); break;
deviceList.addAll(deviceManagementService. case MDMAppConstants.IOS:
getDevicesOfUser(username, deviceList = deviceManagementService.getDevicesOfUser(username, MDMAppConstants.IOS);
MDMAppConstants.IOS)); break;
default:
throw new MobileApplicationException("App platform:" + platform + "is not supported.");
} }
devices = new ArrayList<>(deviceList.size()); devices = new ArrayList<>(deviceList.size());
if(log.isDebugEnabled()){ if(log.isDebugEnabled()){

Loading…
Cancel
Save