Search in sources :

Example 21 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 22 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 23 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 24 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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;
}
Also used : CertificateMetadataDTO(org.wso2.carbon.apimgt.api.dto.CertificateMetadataDTO) ArrayList(java.util.ArrayList) PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO) ClientCertMetadataDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertMetadataDTO) CertMetadataDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertMetadataDTO) ClientCertificatesDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO) CertificatesDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificatesDTO)

Example 25 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Aggregations

PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)14 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)12 ArrayList (java.util.ArrayList)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)2 Comment (org.wso2.carbon.apimgt.api.model.Comment)2 PaginationDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.PaginationDTO)2 ClientCertificatesDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO)2 PaginationDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO)2 Set (java.util.Set)1 JSONObject (org.json.simple.JSONObject)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 CertificateMetadataDTO (org.wso2.carbon.apimgt.api.dto.CertificateMetadataDTO)1 ClientCertificateDTO (org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 Application (org.wso2.carbon.apimgt.api.model.Application)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1