added role query param to getdevices restapis

revert-70aa11f8
lakshani 8 years ago
parent c17bead1fc
commit 26f2e2d2ae

@ -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,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<>();

Loading…
Cancel
Save