Fixed RoleManagementService API issues

revert-70aa11f8
mharindu 9 years ago
parent 7aa37ff4d5
commit 81aa298740

@ -0,0 +1,55 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.List;
@ApiModel(value = "Policy List")
public class PolicyList extends BasePaginatedResult {
private List<Policy> policies;
@ApiModelProperty(value = "List of policies returned")
@JsonProperty("policies")
public List<Policy> getList() {
return policies;
}
public void setList(List<Policy> policies) {
this.policies = policies;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" roles: [").append(policies).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -43,7 +43,6 @@ public class RoleList extends BasePaginatedResult {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n"); sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n"); sb.append(" previous: ").append(getPrevious()).append(",\n");

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyList;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; 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.api.PolicyManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
@ -120,19 +121,27 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
List<Policy> policies; List<Policy> policies;
List<Policy> filteredPolicies;
PolicyList targetPolicies = new PolicyList();
try { try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicies(); policies = policyAdministratorPoint.getPolicies();
if (policies == null || policies.size() == 0) { if (policies == null || policies.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build(); return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
} }
targetPolicies.setCount(policies.size());
filteredPolicies = FilteringUtil.getFilteredList(policies, offset, limit);
if (filteredPolicies.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
}
targetPolicies.setList(filteredPolicies);
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while retrieving all available policies"; String msg = "ErrorResponse occurred while retrieving all available policies";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
return Response.status(Response.Status.OK).entity(FilteringUtil.getFilteredList(policies, offset, limit))
.build(); return Response.status(Response.Status.OK).entity(targetPolicies).build();
} }
@GET @GET

@ -58,17 +58,17 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) { @QueryParam("offset") int offset, @QueryParam("limit") int limit) {
List<String> filteredRoles; List<String> filteredRoles;
RoleList targetRoles; RoleList targetRoles = new RoleList();
try { try {
filteredRoles = getRolesFromUserStore(); filteredRoles = getRolesFromUserStore();
if (offset != -1 && limit != -1) { if (filteredRoles == null || filteredRoles.size() == 0) {
filteredRoles = FilteringUtil.getFilteredList(filteredRoles, offset, limit);
}
if (filteredRoles == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build(); return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
} }
targetRoles = new RoleList();
targetRoles.setCount(filteredRoles.size()); targetRoles.setCount(filteredRoles.size());
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(), offset, limit);
if (filteredRoles.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
}
targetRoles.setList(filteredRoles); targetRoles.setList(filteredRoles);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving roles from the underlying user stores"; String msg = "Error occurred while retrieving roles from the underlying user stores";
@ -219,8 +219,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Override @Override
public Response updateRole(@PathParam("roleName") String roleName, RoleWrapper roleWrapper) { public Response updateRole(@PathParam("roleName") String roleName, RoleWrapper roleWrapper) {
if (roleWrapper == null) { if (roleWrapper == null) {
log.error("Request body is incorrect or empty"); return Response.status(Response.Status.BAD_REQUEST).entity("Request body is incorrect or empty").build();
return Response.status(Response.Status.BAD_REQUEST).build();
} }
String newRoleName = roleWrapper.getRoleName(); String newRoleName = roleWrapper.getRoleName();
try { try {
@ -290,8 +289,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Override @Override
public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) { public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) {
if (users == null || users.size() == 0) { if (users == null || users.size() == 0) {
log.error("No users are found"); return Response.status(Response.Status.BAD_REQUEST).entity("No users are found in the request").build();
return Response.status(Response.Status.BAD_REQUEST).build();
} }
try { try {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();

Loading…
Cancel
Save