mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #576 from lakshani/rest-connector-3.1.0
Added role query param to getdevices restapis
This commit is contained in:
commit
56e4dfd743
@ -205,6 +205,13 @@ public interface DeviceManagementService {
|
||||
required = false)
|
||||
@QueryParam("user")
|
||||
String user,
|
||||
@ApiParam(
|
||||
name = "role",
|
||||
value = "A role of device owners. Ex : store-admin",
|
||||
required = false)
|
||||
@QueryParam("role")
|
||||
@Size(max = 45)
|
||||
String role,
|
||||
@ApiParam(
|
||||
name = "ownership",
|
||||
allowableValues = "BYOD, COPE",
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
@ -84,6 +85,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@QueryParam("name") String name,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("user") String user,
|
||||
@QueryParam("role") String role,
|
||||
@QueryParam("ownership") String ownership,
|
||||
@QueryParam("status") String status,
|
||||
@QueryParam("groupId") int groupId,
|
||||
@ -92,6 +94,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
try {
|
||||
if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(role)) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Request contains both name and role " +
|
||||
"parameters. Only one is allowed " +
|
||||
"at once.").build()).build();
|
||||
}
|
||||
// RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status);
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
@ -126,6 +134,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
if (groupId != 0 ) {
|
||||
request.setGroupId(groupId);
|
||||
}
|
||||
if (role != null && !role.isEmpty()) {
|
||||
request.setOwnerRole(role);
|
||||
}
|
||||
|
||||
// this is the user who initiates the request
|
||||
String authorizedUser = MultitenantUtils.getTenantAwareUsername(CarbonContext.getThreadLocalCarbonContext().getUsername());
|
||||
|
||||
@ -65,9 +65,10 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
|
||||
|
||||
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
||||
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
||||
if (Platform.ANDROID.toString().equals(deviceIdentifier.getType())) {
|
||||
String deviceType = deviceIdentifier.getType().toUpperCase();
|
||||
if (Platform.ANDROID.toString().equals(deviceType)) {
|
||||
operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp);
|
||||
} else if (Platform.IOS.toString().equals(deviceIdentifier.getType())) {
|
||||
} else if (Platform.IOS.toString().equals(deviceType)) {
|
||||
operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
|
||||
}
|
||||
}
|
||||
@ -114,9 +115,10 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
|
||||
|
||||
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
||||
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
||||
if (Platform.ANDROID.toString().equals(deviceIdentifier.getType())) {
|
||||
String deviceType = deviceIdentifier.getType().toUpperCase();
|
||||
if (Platform.ANDROID.toString().equals(deviceType)) {
|
||||
operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp);
|
||||
} else if (deviceIdentifier.getType().equals(Platform.IOS.toString())) {
|
||||
} else if (deviceType.equals(Platform.IOS.toString())) {
|
||||
operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ public class PaginationRequest {
|
||||
private String deviceType;
|
||||
private String deviceName;
|
||||
private String ownership;
|
||||
private String ownerRole;
|
||||
private Date since;
|
||||
|
||||
public PaginationRequest(int start, int rowCount) {
|
||||
@ -112,4 +113,11 @@ public class PaginationRequest {
|
||||
this.since = since;
|
||||
}
|
||||
|
||||
public String getOwnerRole() {
|
||||
return ownerRole;
|
||||
}
|
||||
|
||||
public void setOwnerRole(String ownerRole) {
|
||||
this.ownerRole = ownerRole;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,12 +608,17 @@ 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);
|
||||
@ -625,6 +631,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 {
|
||||
@ -637,7 +658,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
device.setDeviceInfo(info);
|
||||
} catch (DeviceDetailsMgtDAOException e) {
|
||||
log.error("Error occurred while retrieving advance info of '" + device.getType() +
|
||||
"' that carries the id '" + device.getDeviceIdentifier() + "'");
|
||||
"' that carries the id '" + device.getDeviceIdentifier() + "'");
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while opening a connection to the data source", e);
|
||||
} finally {
|
||||
@ -651,7 +672,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
device.setApplications(applications);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
|
||||
"which carries the id '" + device.getId() + "'", e);
|
||||
"which carries the id '" + device.getId() + "'", e);
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while opening a connection to the data source", e);
|
||||
} finally {
|
||||
@ -662,7 +683,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
if (deviceManager == null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
|
||||
"Therefore, not attempting method 'isEnrolled'");
|
||||
"Therefore, not attempting method 'isEnrolled'");
|
||||
}
|
||||
devices.add(device);
|
||||
continue;
|
||||
@ -675,12 +696,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<>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user