|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.wso2.carbon.device.mgt.core.service;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
@ -607,16 +608,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PaginationResult getAllDevices(PaginationRequest request) throws DeviceManagementException {
|
|
|
|
|
List<Device> devicesForRoles = null;
|
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
|
List<Device> allDevices = new ArrayList<>();
|
|
|
|
|
int count = 0;
|
|
|
|
|
int tenantId = this.getTenantId();
|
|
|
|
|
request = DeviceManagerUtil.validateDeviceListPageSize(request);
|
|
|
|
|
if (!StringUtils.isEmpty(request.getOwnerRole())) {
|
|
|
|
|
devicesForRoles = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
|
|
|
|
.getAllDevicesOfRole(request.getOwnerRole());
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
allDevices = deviceDAO.getDevices(request, tenantId);
|
|
|
|
|
count = deviceDAO.getDeviceCount(request, tenantId);
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
|
|
|
|
|
"the current tenant", e);
|
|
|
|
@ -625,6 +632,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
devices = processDevices(devices, allDevices);
|
|
|
|
|
|
|
|
|
|
if (devicesForRoles != null) {
|
|
|
|
|
count += devicesForRoles.size();
|
|
|
|
|
devices = processDevices(devices, devicesForRoles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paginationResult.setData(devices);
|
|
|
|
|
paginationResult.setRecordsFiltered(count);
|
|
|
|
|
paginationResult.setRecordsTotal(count);
|
|
|
|
|
return paginationResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Device> processDevices(List<Device> devices, List<Device> allDevices) throws DeviceManagementException {
|
|
|
|
|
for (Device device : allDevices) {
|
|
|
|
|
DeviceInfo info = null;
|
|
|
|
|
try {
|
|
|
|
@ -675,12 +697,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
}
|
|
|
|
|
devices.add(device);
|
|
|
|
|
}
|
|
|
|
|
paginationResult.setData(devices);
|
|
|
|
|
paginationResult.setRecordsFiltered(count);
|
|
|
|
|
paginationResult.setRecordsTotal(count);
|
|
|
|
|
return paginationResult;
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Device> getAllDevices(String deviceType) throws DeviceManagementException {
|
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
|