use of org.wso2.carbon.apimgt.api.model.Pagination 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.api.model.Pagination 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.api.model.Pagination 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.api.model.Pagination in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method getPaginatedSubscriptions.
/**
* Get the subscriptions within the specified pagination range
*
* @param subscriptionListDTO list of all subscription DTOs
* @param limit max number of objects returned
* @param offset starting index
* @return SubscriptionListDTO object containing SubscriptionDTOs within the pagination range
*/
public static SubscriptionListDTO getPaginatedSubscriptions(SubscriptionListDTO subscriptionListDTO, Integer limit, Integer offset) {
SubscriptionListDTO paginatedSubscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = paginatedSubscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
paginatedSubscriptionListDTO.setList(subscriptionDTOs);
}
// identifying the proper start and end indexes
int size = subscriptionListDTO.getCount();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
List<SubscriptionDTO> subscriptions = subscriptionListDTO.getList();
for (int i = start; i <= end; i++) {
subscriptionDTOs.add(subscriptions.get(i));
}
paginatedSubscriptionListDTO.setCount(subscriptionDTOs.size());
return paginatedSubscriptionListDTO;
}
use of org.wso2.carbon.apimgt.api.model.Pagination 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);
}
Aggregations