Search in sources :

Example 16 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.

the class CommentMappingUtil method fromCommentListToDTO.

/**
 * Wraps a List of Comments to a CommentListDTO
 *
 * @param commentList list of comments
 * @return CommentListDTO
 */
public static CommentListDTO fromCommentListToDTO(CommentList commentList, boolean includeCommenterInfo) {
    CommentListDTO commentListDTO = new CommentListDTO();
    List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
    commentListDTO.setCount(commentList.getCount());
    PaginationDTO paginationDTO = new PaginationDTO();
    paginationDTO.setLimit(commentList.getPagination().getLimit());
    paginationDTO.setOffset(commentList.getPagination().getOffset());
    paginationDTO.setTotal(commentList.getPagination().getTotal());
    paginationDTO.setNext(commentList.getPagination().getNext());
    paginationDTO.setPrevious(commentList.getPagination().getPrevious());
    commentListDTO.setPagination(paginationDTO);
    Map<String, Map<String, String>> userClaimsMap = new HashMap<>();
    for (Comment comment : commentList.getList()) {
        try {
            if (includeCommenterInfo) {
                userClaimsMap = retrieveUserClaims(comment.getUser(), userClaimsMap);
                listOfCommentDTOs.add(fromCommentToDTOWithUserInfo(comment, userClaimsMap));
            } else {
                listOfCommentDTOs.add(fromCommentToDTO(comment));
            }
        } catch (APIManagementException e) {
            log.error("Error while creating comments list", e);
        }
    }
    commentListDTO.setList(listOfCommentDTOs);
    return commentListDTO;
}
Also used : Comment(org.wso2.carbon.apimgt.api.model.Comment) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO) CommentDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.CommentDTO) CommentListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.CommentListDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with PaginationDTO

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

Example 18 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.

the class TagMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a TagListDTO object given pagination parameters and url parameters
 *
 * @param tagListDTO a TagListDTO object
 * @param limit       max number of objects returned
 * @param offset      starting index
 * @param size        max offset
 */
public static void setPaginationParams(TagListDTO tagListDTO, 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.getTagsPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getTagsPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
    }
    PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    tagListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 19 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a AdditionalSubscriptionInfoListDTO object given pagination parameters and url
 * parameters
 *
 * @param additionalSubscriptionInfoListDTO a AdditionalSubscriptionInfoListDTO object
 * @param apiId               uuid/id of API
 * @param groupId             group id of the applications to be returned
 * @param limit               max number of objects returned
 * @param offset              starting index
 * @param size                max offset
 */
public static void setPaginationParams(AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO, String apiId, String groupId, 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.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId, groupId);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
    }
    PaginationDTO pagination = new PaginationDTO();
    pagination.setOffset(offset);
    pagination.setLimit(limit);
    pagination.setNext(paginatedNext);
    pagination.setPrevious(paginatedPrevious);
    pagination.setTotal(size);
    additionalSubscriptionInfoListDTO.setPagination(pagination);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 20 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method getAPIClientCertificates.

@Override
public Response getAPIClientCertificates(String apiId, Integer limit, Integer offset, String alias, MessageContext messageContext) {
    limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
    offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
    List<ClientCertificateDTO> certificates = new ArrayList<>();
    String query = CertificateRestApiUtils.buildQueryString("alias", alias, "apiId", apiId);
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        int tenantId = APIUtil.getInternalOrganizationId(organization);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        int totalCount = apiProvider.getClientCertificateCount(tenantId);
        if (totalCount > 0) {
            APIIdentifier apiIdentifier = null;
            if (StringUtils.isNotEmpty(apiId)) {
                API api = apiProvider.getAPIbyUUID(apiId, organization);
                apiIdentifier = api.getId();
            }
            certificates = apiProvider.searchClientCertificates(tenantId, alias, apiIdentifier, organization);
        }
        ClientCertificatesDTO certificatesDTO = CertificateRestApiUtils.getPaginatedClientCertificates(certificates, limit, offset, query);
        PaginationDTO paginationDTO = new PaginationDTO();
        paginationDTO.setLimit(limit);
        paginationDTO.setOffset(offset);
        paginationDTO.setTotal(totalCount);
        certificatesDTO.setPagination(paginationDTO);
        return Response.status(Response.Status.OK).entity(certificatesDTO).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving the client certificates.", e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) ClientCertificatesDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

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