use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathListDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method setPaginationParamsForAPIResourcePathList.
/**
* Sets pagination urls for a ResourcePathListDTO object.
*
* @param resourcePathListDTO ResourcePathListDTO object to which pagination urls need to be set
* @param offset starting index
* @param limit max number of returned objects
* @param size max offset
*/
public static void setPaginationParamsForAPIResourcePathList(ResourcePathListDTO resourcePathListDTO, int offset, int limit, int size) {
// acquiring pagination parameters and setting pagination urls
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getResourcePathPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getResourcePathPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
resourcePathListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIResourcePaths.
@Override
public Response getAPIResourcePaths(String apiId, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
if (apiIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
List<ResourcePath> apiResourcePaths = apiProvider.getResourcePathsOfAPI(apiIdentifier);
ResourcePathListDTO dto = APIMappingUtil.fromResourcePathListToDTO(apiResourcePaths, limit, offset);
APIMappingUtil.setPaginationParamsForAPIResourcePathList(dto, offset, limit, apiResourcePaths.size());
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving resource paths of API : " + apiId, e, log);
} else {
String errorMessage = "Error while retrieving resource paths of API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathListDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromResourcePathListToDTO.
/**
* Converts a List object of API resource paths into a DTO.
*
* @param resourcePathList List of API resource paths
* @param limit maximum number of API resource paths to be returned
* @param offset starting index
* @return ResourcePathListDTO object containing ResourcePathDTOs
*/
public static ResourcePathListDTO fromResourcePathListToDTO(List<ResourcePath> resourcePathList, int limit, int offset) {
ResourcePathListDTO resourcePathListDTO = new ResourcePathListDTO();
List<ResourcePathDTO> resourcePathDTOs = new ArrayList<ResourcePathDTO>();
// identifying the proper start and end indexes
int size = resourcePathList.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
ResourcePath path = resourcePathList.get(i);
ResourcePathDTO dto = new ResourcePathDTO();
dto.setId(path.getId());
dto.setResourcePath(path.getResourcePath());
dto.setHttpVerb(path.getHttpVerb());
resourcePathDTOs.add(dto);
}
resourcePathListDTO.setCount(resourcePathDTOs.size());
resourcePathListDTO.setList(resourcePathDTOs);
return resourcePathListDTO;
}
Aggregations