Search in sources :

Example 51 with Pagination

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

Example 52 with Pagination

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

Example 53 with Pagination

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

Example 54 with Pagination

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;
}
Also used : ClientCertMetadataDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertMetadataDTO) ArrayList(java.util.ArrayList) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) ClientCertificatesDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO)

Example 55 with Pagination

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;
}
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)

Aggregations

ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)19 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 JSONObject (org.json.simple.JSONObject)12 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)12 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)11 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)11 API (org.wso2.carbon.apimgt.api.model.API)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)8 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)8 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)8 TreeSet (java.util.TreeSet)7 Registry (org.wso2.carbon.registry.core.Registry)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 APINameComparator (org.wso2.carbon.apimgt.impl.utils.APINameComparator)6 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5