From 7aa37ff4d5a118e3f9ade737405002828b0697ad Mon Sep 17 00:00:00 2001 From: mharindu Date: Wed, 1 Jun 2016 00:31:48 +0530 Subject: [PATCH] Fixed issues in RoleManagementService --- .../jaxrs/service/impl/PolicyManagementServiceImpl.java | 4 ++-- .../mgt/jaxrs/service/impl/RoleManagementServiceImpl.java | 4 ++++ .../util/{PolicyFilteringUtil.java => FilteringUtil.java} | 7 +++---- 3 files changed, 9 insertions(+), 6 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/{PolicyFilteringUtil.java => FilteringUtil.java} (81%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 32760e1189..f543b7b295 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index c0c90e38b5..58e08c1d8f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/PolicyFilteringUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/FilteringUtil.java similarity index 81% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/PolicyFilteringUtil.java rename to components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/FilteringUtil.java index d57266145b..3cc650029c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/PolicyFilteringUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/FilteringUtil.java @@ -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 getPolicies(List sourceList, int offset, int limit) { + public static List getFilteredList(List sourceList, int offset, int limit) { if(sourceList == null || sourceList.size() < offset){ return Collections.emptyList(); }