use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class CommonMappingUtil method getPaginationDTO.
/**
* Retreives a pagination DTO object given
*
* @param limit limit value
* @param offset offset value (starting position)
* @param total total number of resources available
* @param next link to the next page
* @param previous link to the previous page
* @return a pagination DTO object given above properties
*/
public static PaginationDTO getPaginationDTO(int limit, int offset, int total, String next, String previous) {
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(limit);
paginationDTO.setOffset(offset);
paginationDTO.setTotal(total);
paginationDTO.setNext(next);
paginationDTO.setPrevious(previous);
return paginationDTO;
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class SearchResultMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a SearchResultListDTO object given pagination parameters and url parameters.
*
* @param resultListDTO a SearchResultListDTO object
* @param query search condition
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(SearchResultListDTO resultListDTO, String query, 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.getAPIPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getAPIPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
}
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setNext(paginatedNext);
paginationDTO.setPrevious(paginatedPrevious);
paginationDTO.setOffset(offset);
paginationDTO.setLimit(limit);
paginationDTO.setTotal(size);
resultListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class ThrottlingPolicyMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a ThrottlingPolicyListDTO object given pagination parameters and url parameters.
*
* @param throttlingPolicyListDTO a ThrottlingPolicyListDTO object
* @param tierLevel tier level (api/application or resource)
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(ThrottlingPolicyListDTO throttlingPolicyListDTO, String tierLevel, int limit, int offset, int size) {
String paginatedPrevious = "";
String paginatedNext = "";
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getTiersPaginatedURL(tierLevel, paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getTiersPaginatedURL(tierLevel, paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
throttlingPolicyListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method setRatingPaginationParams.
/**
* Sets pagination urls for a RatingListDTO object given pagination parameters and url parameters
*
* @param ratingListDTO a RatingListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setRatingPaginationParams(RatingListDTO ratingListDTO, String apiId, 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.getRatingPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getRatingPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
ratingListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
@Override
public Response apisGet(Integer limit, Integer offset, String xWSO2Tenant, String query, String ifNoneMatch, MessageContext messageContext) {
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
query = query == null ? "" : query;
APIListDTO apiListDTO = new APIListDTO();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
// revert content search back to normal search by name to avoid doc result complexity and to comply with REST api practices
if (query.startsWith(APIConstants.CONTENT_SEARCH_TYPE_PREFIX + ":")) {
query = query.replace(APIConstants.CONTENT_SEARCH_TYPE_PREFIX + ":", APIConstants.NAME_TYPE_PREFIX + ":");
}
Map allMatchedApisMap = apiConsumer.searchPaginatedAPIs(query, organization, offset, limit, null, null);
// This is a SortedSet
Set<Object> sortedSet = (Set<Object>) allMatchedApisMap.get("apis");
ArrayList<Object> allMatchedApis = new ArrayList<>(sortedSet);
apiListDTO = APIMappingUtil.fromAPIListToDTO(allMatchedApis, organization);
// Add pagination section in the response
Object totalLength = allMatchedApisMap.get("length");
Integer totalAvailableAPis = 0;
if (totalLength != null) {
totalAvailableAPis = (Integer) totalLength;
}
APIMappingUtil.setPaginationParams(apiListDTO, query, offset, limit, totalAvailableAPis);
return Response.ok().entity(apiListDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.rootCauseMessageMatches(e, "start index seems to be greater than the limit count")) {
// this is not an error of the user as he does not know the total number of apis available. Thus sends
// an empty response
apiListDTO.setCount(0);
apiListDTO.setPagination(new PaginationDTO());
return Response.ok().entity(apiListDTO).build();
} else {
String errorMessage = "Error while retrieving APIs";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
Aggregations