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