/** * @param applicationOperationDevice holds the information needs to retrieve device list. * @return List of devices * @throws MobileApplicationException */ public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice) throws MobileApplicationException { List<Device> devices; try { List<org.wso2.carbon.device.mgt.common.Device> deviceList = MDMServiceAPIUtils.getDeviceManagementService(applicationOperationDevice.getTenantId()) .getDevicesOfUser(applicationOperationDevice.getCurrentUser().getUsername()); devices = new ArrayList<>(deviceList.size()); if (log.isDebugEnabled()) { log.debug("device list got from mdm " + deviceList.toString()); } for (org.wso2.carbon.device.mgt.common.Device commonDevice : deviceList) { if (MDMAppConstants.ACTIVE.equals( commonDevice.getEnrolmentInfo().getStatus().toString().toLowerCase())) { Device device = new Device(); org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier(); deviceIdentifier.setId(commonDevice.getDeviceIdentifier()); deviceIdentifier.setType(commonDevice.getType()); device.setDeviceIdentifier(deviceIdentifier); device.setName(commonDevice.getName()); device.setModel(commonDevice.getName()); device.setType(MDMAppConstants.MOBILE_DEVICE); String imgUrl; if (MDMAppConstants.ANDROID.equalsIgnoreCase(commonDevice.getType())) { imgUrl = String.format( applicationOperationDevice.getConfigParams().get(MDMAppConstants.IMAGE_URL), MDMAppConstants.NEXUS); } else if (MDMAppConstants.IOS.equalsIgnoreCase(commonDevice.getType())) { imgUrl = String.format( applicationOperationDevice.getConfigParams().get(MDMAppConstants.IMAGE_URL), MDMAppConstants.IPHONE); } else { imgUrl = String.format( applicationOperationDevice.getConfigParams().get(MDMAppConstants.IMAGE_URL), MDMAppConstants.NONE); } device.setImage(imgUrl); device.setPlatform(commonDevice.getType()); devices.add(device); } } } catch (DeviceManagementException e) { logError("Error While retrieving Device List.", e); throw new MobileApplicationException(e.getMessage()); } return devices; }