From 016414c076675f480e3a2e47451d76d4ed1b6b04 Mon Sep 17 00:00:00 2001 From: Ace Date: Mon, 13 Jun 2016 15:43:21 +0530 Subject: [PATCH] Bug fixes for role search --- .../service/impl/RoleManagementServiceImpl.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 620808a8f33..599d4345beb 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 @@ -61,13 +61,13 @@ public class RoleManagementServiceImpl implements RoleManagementService { List filteredRoles; RoleList targetRoles = new RoleList(); try { - filteredRoles = getRolesFromUserStore(); + filteredRoles = getRolesFromUserStore(filter); if (filteredRoles == null || filteredRoles.size() == 0) { throw new NotFoundException( new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No roles found.").build()); } targetRoles.setCount(filteredRoles.size()); - filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(), offset, limit); + filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter), offset, limit); if (filteredRoles.size() == 0) { throw new NotFoundException( new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No roles found").build()); @@ -322,9 +322,10 @@ public class RoleManagementServiceImpl implements RoleManagementService { "successfully been updated with the user list").build(); } - private List getRolesFromUserStore() throws UserStoreException { + private List getRolesFromUserStore(String filter) throws UserStoreException { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); String[] roles; + boolean filterRolesByName = ((filter == null) || filter.isEmpty() ? false : true); if (log.isDebugEnabled()) { log.debug("Getting the list of user roles"); } @@ -333,7 +334,13 @@ public class RoleManagementServiceImpl implements RoleManagementService { List filteredRoles = new ArrayList<>(); for (String role : roles) { if (!(role.startsWith("Internal/") || role.startsWith("Authentication/") || role.startsWith("Application/"))) { - filteredRoles.add(role); + if(!filterRolesByName) { + filteredRoles.add(role); + } else{ + if(role.contains(filter)){ + filteredRoles.add(role); + } + } } } return filteredRoles;