Fixed issues in RoleManagementService

4.x.x
mharindu 9 years ago
parent 63ea40eb27
commit 7aa37ff4d5

@ -29,7 +29,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.PolicyManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.PolicyFilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
import org.wso2.carbon.policy.mgt.common.Policy;
@ -131,7 +131,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(PolicyFilteringUtil.getPolicies(policies, offset, limit))
return Response.status(Response.Status.OK).entity(FilteringUtil.getFilteredList(policies, offset, limit))
.build();
}

@ -25,6 +25,7 @@ import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper;
@ -60,6 +61,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
RoleList targetRoles;
try {
filteredRoles = getRolesFromUserStore();
if (offset != -1 && limit != -1) {
filteredRoles = FilteringUtil.getFilteredList(filteredRoles, offset, limit);
}
if (filteredRoles == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
}

@ -18,21 +18,20 @@
*/
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.Collections;
import java.util.List;
/**
* This is used instead of filtering from cache.
* Todo : need to implement proper pagination support on retrieving policies.
*/
public class PolicyFilteringUtil {
public class FilteringUtil {
/**
* This is used to filter from the cached policies.
*/
public static List<Policy> getPolicies(List<Policy> sourceList, int offset, int limit) {
public static <T> List<T> getFilteredList(List<T> sourceList, int offset, int limit) {
if(sourceList == null || sourceList.size() < offset){
return Collections.emptyList();
}
Loading…
Cancel
Save