use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class DocumentationMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a DocumentListDTO object given pagination parameters and url parameters.
*
* @param documentListDTO a DocumentListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(DocumentListDTO documentListDTO, 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.getDocumentationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getDocumentationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
documentListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class DocumentationMappingUtil method setProductDocListPaginationParams.
/**
* Sets pagination urls for a DocumentListDTO object (associated to an api product) given pagination parameters
* and url parameters.
*
* @param documentListDTO a DocumentListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setProductDocListPaginationParams(DocumentListDTO documentListDTO, String productId, 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.getProductDocumentPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), productId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getProductDocumentPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), productId);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
documentListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class SharedScopeMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a shared ScopeListDTO object given pagination parameters and url parameters.
*
* @param sharedScopeListDTO a ScopeListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(ScopeListDTO sharedScopeListDTO, 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.getScopesPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getScopesPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
sharedScopeListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class CertificateRestApiUtils method getPaginatedCertificates.
/**
* Get the paginated list of certificates based on the limit and offset values provided.
*
* @param certificateMetadataList : The list of certificate metadata.
* @param limit : The number of items per page.
* @param offset : Page number
* @param query : The query parameters.
* @return : CertificatesDTO Object with the parameters set.
*/
public static CertificatesDTO getPaginatedCertificates(List<CertificateMetadataDTO> certificateMetadataList, int limit, int offset, String query) {
if (log.isDebugEnabled()) {
log.debug(String.format("Filter the certificates based on the pagination parameters, limit = %d and " + "offset = %d", limit, offset));
}
int certCount = certificateMetadataList.size();
List<CertMetadataDTO> certificateList = new ArrayList<>();
CertificatesDTO certificatesDTO = new CertificatesDTO();
certificatesDTO.setCount(certCount > limit ? limit : certCount);
// If the provided offset value exceeds the offset, reset the offset to default.
if (offset > certCount) {
offset = RestApiConstants.PAGINATION_OFFSET_DEFAULT;
}
// Select only the set of Certificates which matches the given limit and offset values.
int start = offset;
int end = certCount > start + limit ? start + limit : certCount;
for (int i = start; i < end; i++) {
CertMetadataDTO certMetadataDTO = new CertMetadataDTO();
CertificateMetadataDTO certificateMetadataDTO = certificateMetadataList.get(i);
certMetadataDTO.setAlias(certificateMetadataDTO.getAlias());
certMetadataDTO.setEndpoint(certificateMetadataDTO.getEndpoint());
certificateList.add(certMetadataDTO);
}
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, certCount);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = getCertificatesPaginatedURL(RestApiConstants.CERTS_GET_PAGINATED_URL, paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = getCertificatesPaginatedURL(RestApiConstants.CERTS_GET_PAGINATED_URL, paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
}
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setNext(paginatedNext);
paginationDTO.setPrevious(paginatedPrevious);
paginationDTO.setLimit(limit);
paginationDTO.setOffset(offset);
paginationDTO.setTotal(certCount);
certificatesDTO.setCount(certificateList.size());
certificatesDTO.setCertificates(certificateList);
certificatesDTO.setPagination(paginationDTO);
return certificatesDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a APIListDTO object given pagination parameters and url parameters
*
* @param apiListDTO APIListDTO object to which pagination urls need to be set
* @param query query parameter
* @param offset starting index
* @param limit max number of returned objects
* @param size max offset
*/
public static void setPaginationParams(APIListDTO apiListDTO, String query, int offset, int limit, int size) {
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 = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
apiListDTO.setPagination(paginationDTO);
}
Aggregations