use of org.wso2.carbon.apimgt.api.model.Pagination 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.api.model.Pagination 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.api.model.Pagination 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.api.model.Pagination in project carbon-apimgt by wso2.
the class CertificateRestApiUtils method getPaginatedClientCertificates.
/**
* To get the paginated list of client certificates.
*
* @param clientCertificateDTOList Client certificate list.
* @param limit Limit
* @param offset Offset
* @param query query
* @return paginated list of client certificates.
*/
public static ClientCertificatesDTO getPaginatedClientCertificates(List<ClientCertificateDTO> clientCertificateDTOList, int limit, int offset, String query) {
if (log.isDebugEnabled()) {
log.debug(String.format("Filter the client certificates based on the pagination parameters, limit = %d and" + "offset = %d", limit, offset));
}
int certCount = clientCertificateDTOList.size();
List<ClientCertMetadataDTO> clientCertificateList = new ArrayList<>();
ClientCertificatesDTO certificatesDTO = new ClientCertificatesDTO();
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++) {
ClientCertMetadataDTO clientCertMetadataDTO = new ClientCertMetadataDTO();
ClientCertificateDTO clientCertificateDTO = clientCertificateDTOList.get(i);
clientCertMetadataDTO.setAlias(clientCertificateDTO.getAlias());
clientCertMetadataDTO.setApiId(clientCertificateDTO.getApiIdentifier().toString());
clientCertMetadataDTO.setTier(clientCertificateDTO.getTierName());
clientCertificateList.add(clientCertMetadataDTO);
}
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, certCount);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = getCertificatesPaginatedURL(RestApiConstants.CLIENT_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.CLIENT_CERTS_GET_PAGINATED_URL, paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
}
certificatesDTO.setCount(clientCertificateList.size());
certificatesDTO.setCertificates(clientCertificateList);
return certificatesDTO;
}
use of org.wso2.carbon.apimgt.api.model.Pagination 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;
}
Aggregations