Search in sources :

Example 91 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoListToDTO.

/**
 * Converts a List object of SubscribedAPIs into a DTO
 *
 * @param subscriptions a list of SubscribedAPI objects
 * @param limit         max number of objects returned
 * @param offset        starting index
 * @param organization  identifier of the organization
 * @return SubscriptionListDTO object containing SubscriptionDTOs
 * @throws APIManagementException if error occurred when creating AdditionalSubscriptionInfoListDTO
 */
public static AdditionalSubscriptionInfoListDTO fromAdditionalSubscriptionInfoListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset, String organization) throws APIManagementException {
    AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO = new AdditionalSubscriptionInfoListDTO();
    List<AdditionalSubscriptionInfoDTO> additionalSubscriptionInfoDTOs = additionalSubscriptionInfoListDTO.getList();
    if (additionalSubscriptionInfoDTOs == null) {
        additionalSubscriptionInfoDTOs = new ArrayList<>();
        additionalSubscriptionInfoListDTO.setList(additionalSubscriptionInfoDTOs);
    }
    // Identifying the proper start and end indexes
    int size = subscriptions.size();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
    for (int i = start; i <= end; i++) {
        try {
            SubscribedAPI subscription = subscriptions.get(i);
            additionalSubscriptionInfoDTOs.add(fromAdditionalSubscriptionInfoToDTO(subscription, organization));
        } catch (APIManagementException e) {
            log.error("Error while obtaining additional info of subscriptions", e);
        }
    }
    // Set count for list
    additionalSubscriptionInfoListDTO.setCount(additionalSubscriptionInfoDTOs.size());
    return additionalSubscriptionInfoListDTO;
}
Also used : AdditionalSubscriptionInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO) AdditionalSubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoListDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI)

Example 92 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit 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.publisher.v1.dto.PaginationDTO)

Example 93 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit 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.setNext(paginatedNext);
    paginationDTO.setPrevious(paginatedPrevious);
    paginationDTO.setOffset(offset);
    paginationDTO.setLimit(limit);
    paginationDTO.setTotal(size);
    resultListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 94 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class ThrottlingPolicyMappingUtil method setPaginationParams.

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

Example 95 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method getPaginatedSubscriptions.

/**
 * Get the subscriptions within the specified pagination range
 *
 * @param subscriptionListDTO list of all subscription DTOs
 * @param limit               max number of objects returned
 * @param offset              starting index
 * @return SubscriptionListDTO object containing SubscriptionDTOs within the pagination range
 */
public static SubscriptionListDTO getPaginatedSubscriptions(SubscriptionListDTO subscriptionListDTO, Integer limit, Integer offset) {
    SubscriptionListDTO paginatedSubscriptionListDTO = new SubscriptionListDTO();
    List<SubscriptionDTO> subscriptionDTOs = paginatedSubscriptionListDTO.getList();
    if (subscriptionDTOs == null) {
        subscriptionDTOs = new ArrayList<>();
        paginatedSubscriptionListDTO.setList(subscriptionDTOs);
    }
    // identifying the proper start and end indexes
    int size = subscriptionListDTO.getCount();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
    List<SubscriptionDTO> subscriptions = subscriptionListDTO.getList();
    for (int i = start; i <= end; i++) {
        subscriptionDTOs.add(subscriptions.get(i));
    }
    paginatedSubscriptionListDTO.setCount(subscriptionDTOs.size());
    return paginatedSubscriptionListDTO;
}
Also used : SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)49 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)41 Test (org.testng.annotations.Test)29 PreparedStatement (java.sql.PreparedStatement)22 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)21 API (org.wso2.carbon.apimgt.api.model.API)20 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 Map (java.util.Map)18 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 SQLException (java.sql.SQLException)16 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)16 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)15 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)15 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)14 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)13 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)13 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)13 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)12