Search in sources :

Example 26 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.

the class CommonMappingUtil method getPaginationDTO.

/**
 * Retreives a pagination DTO object given
 *
 * @param limit limit value
 * @param offset offset value (starting position)
 * @param total total number of resources available
 * @param next link to the next page
 * @param previous link to the previous page
 * @return a pagination DTO object given above properties
 */
public static PaginationDTO getPaginationDTO(int limit, int offset, int total, String next, String previous) {
    PaginationDTO paginationDTO = new PaginationDTO();
    paginationDTO.setLimit(limit);
    paginationDTO.setOffset(offset);
    paginationDTO.setTotal(total);
    paginationDTO.setNext(next);
    paginationDTO.setPrevious(previous);
    return paginationDTO;
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 27 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.

the class SearchResultMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a SearchResultListDTO object given pagination parameters and url parameters
 *
 * @param resultListDTO a SearchResultListDTO object
 * @param query      search condition
 * @param limit      max number of objects returned
 * @param offset     starting index
 * @param size       max offset
 */
public static void setPaginationParams(SearchResultListDTO resultListDTO, String query, 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.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 = new PaginationDTO();
    paginationDTO.setOffset(offset);
    paginationDTO.setLimit(limit);
    paginationDTO.setTotal(size);
    paginationDTO.setNext(paginatedNext);
    paginationDTO.setPrevious(paginatedPrevious);
    resultListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 28 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a SubscriptionListDTO object given pagination parameters and url parameters
 *
 * @param subscriptionListDTO a SubscriptionListDTO 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(SubscriptionListDTO subscriptionListDTO, 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);
    subscriptionListDTO.setPagination(pagination);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 29 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImpl method applicationsGet.

/**
 * Retrieves all the applications that the user has access to
 *
 * @param groupId     group Id
 * @param query       search condition
 * @param limit       max number of objects returns
 * @param offset      starting index
 * @param ifNoneMatch If-None-Match header value
 * @return Response object containing resulted applications
 */
@Override
public Response applicationsGet(String groupId, String query, String sortBy, String sortOrder, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) {
    limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
    offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
    sortOrder = sortOrder != null ? sortOrder : RestApiConstants.DEFAULT_SORT_ORDER;
    sortBy = sortBy != null ? ApplicationMappingUtil.getApplicationSortByField(sortBy) : APIConstants.APPLICATION_NAME;
    query = query == null ? "" : query;
    ApplicationListDTO applicationListDTO = new ApplicationListDTO();
    String username = RestApiCommonUtil.getLoggedInUsername();
    // todo: Do a second level filtering for the incoming group ID.
    // todo: eg: use case is when there are lots of applications which is accessible to his group "g1", he wants to see
    // todo: what are the applications shared to group "g2" among them.
    groupId = RestApiUtil.getLoggedInUserGroupId();
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
        Subscriber subscriber = new Subscriber(username);
        Application[] applications;
        applications = apiConsumer.getApplicationsWithPagination(new Subscriber(username), groupId, offset, limit, query, sortBy, sortOrder, organization);
        ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
        int applicationCount = apiMgtDAO.getAllApplicationCount(subscriber, groupId, query);
        applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(applications);
        ApplicationMappingUtil.setPaginationParamsWithSortParams(applicationListDTO, groupId, limit, offset, applicationCount, sortOrder, sortBy.toLowerCase());
        return Response.ok().entity(applicationListDTO).build();
    } catch (APIManagementException e) {
        if (RestApiUtil.rootCauseMessageMatches(e, "start index seems to be greater than the limit count")) {
            // this is not an error of the user as he does not know the total number of applications available.
            // Thus sends an empty response
            applicationListDTO.setCount(0);
            applicationListDTO.setPagination(new PaginationDTO());
            return Response.ok().entity(applicationListDTO).build();
        } else {
            String errorMessage = "Error while retrieving Applications";
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) ExportedApplication(org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedApplication) Application(org.wso2.carbon.apimgt.api.model.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO)

Example 30 with PaginationDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.

the class ServiceEntryMappingUtil method getPaginationDTO.

private static PaginationDTO getPaginationDTO(int limit, int offset, int total, String next, String previous) {
    PaginationDTO paginationDTO = new PaginationDTO();
    paginationDTO.setLimit(limit);
    paginationDTO.setOffset(offset);
    paginationDTO.setTotal(total);
    paginationDTO.setNext(next);
    paginationDTO.setPrevious(previous);
    return paginationDTO;
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.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