Search in sources :

Example 1 with ThrottlingPolicyListDTO

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

the class ThrottlingPoliciesApiServiceImpl method getAllThrottlingPolicies.

/**
 * Retrieves all the Tiers
 *
 * @param policyLevel tier level (api/application or resource)
 * @param limit       max number of objects returns
 * @param offset      starting index
 * @param ifNoneMatch If-None-Match header value
 * @return Response object containing resulted tiers
 */
@Override
public Response getAllThrottlingPolicies(String policyLevel, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) {
    // pre-processing
    // setting default limit and offset if they are null
    limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
    offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
    List<Tier> tierList = getThrottlingPolicyList(policyLevel, false);
    ThrottlingPolicyListDTO policyListDTO = ThrottlingPolicyMappingUtil.fromTierListToDTO(tierList, policyLevel, limit, offset);
    // todo: set total counts properly
    ThrottlingPolicyMappingUtil.setPaginationParams(policyListDTO, policyLevel, limit, offset, tierList.size());
    return Response.ok().entity(policyListDTO).build();
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) ThrottlingPolicyListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyListDTO)

Example 2 with ThrottlingPolicyListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyListDTO 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 3 with ThrottlingPolicyListDTO

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

the class ThrottlingPolicyMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a TierListDTO object given pagination parameters and url parameters
 *
 * @param tierListDTO a TierListDTO object
 * @param limit       max number of objects returned
 * @param offset      starting index
 * @param size        max offset
 */
public static void setPaginationParams(ThrottlingPolicyListDTO tierListDTO, 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);
    tierListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 4 with ThrottlingPolicyListDTO

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

the class ThrottlingPolicyMappingUtil method fromTierListToDTO.

/**
 * Converts a List object of Tiers into a DTO.
 *
 * @param tiers  a list of Tier objects
 * @param limit  max number of objects returned
 * @param offset starting index
 * @return ThrottlingPolicyListDTO object containing ThrottlingPolicyDTOs
 */
public static ThrottlingPolicyListDTO fromTierListToDTO(List<Tier> tiers, String tierLevel, int limit, int offset) {
    ThrottlingPolicyListDTO throttlingPolicyListDTO = new ThrottlingPolicyListDTO();
    List<ThrottlingPolicyDTO> throttlingPolicyListDTOList = throttlingPolicyListDTO.getList();
    if (throttlingPolicyListDTOList == null) {
        throttlingPolicyListDTOList = new ArrayList<>();
        throttlingPolicyListDTO.setList(throttlingPolicyListDTOList);
    }
    // identifying the proper start and end indexes
    int size = tiers.size();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = Math.min(offset + limit - 1, size - 1);
    for (int i = start; i <= end; i++) {
        Tier tier = tiers.get(i);
        throttlingPolicyListDTOList.add(fromTierToDTO(tier, tierLevel));
    }
    throttlingPolicyListDTO.setCount(throttlingPolicyListDTOList.size());
    return throttlingPolicyListDTO;
}
Also used : ThrottlingPolicyListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyListDTO) Tier(org.wso2.carbon.apimgt.api.model.Tier) ThrottlingPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyDTO)

Example 5 with ThrottlingPolicyListDTO

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

the class ThrottlingPolicyMappingUtil method fromTierListToDTO.

/**
 * Converts a List object of Tiers into a DTO
 *
 * @param throttlingPolicyList a list of Tier objects
 * @param policyLevel          the policy level(eg: application or subscription)
 * @param limit                max number of objects returned
 * @param offset               starting index
 * @return TierListDTO object containing TierDTOs
 */
public static ThrottlingPolicyListDTO fromTierListToDTO(List<Tier> throttlingPolicyList, String policyLevel, int limit, int offset) {
    ThrottlingPolicyListDTO throttlingPolicyListDTO = new ThrottlingPolicyListDTO();
    List<ThrottlingPolicyDTO> throttlingPolicyDTOs = throttlingPolicyListDTO.getList();
    if (throttlingPolicyDTOs == null) {
        throttlingPolicyDTOs = new ArrayList<>();
        throttlingPolicyListDTO.setList(throttlingPolicyDTOs);
    }
    // identifying the proper start and end indexes
    int size = throttlingPolicyList.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++) {
        Tier tier = throttlingPolicyList.get(i);
        throttlingPolicyDTOs.add(fromTierToDTO(tier, policyLevel));
    }
    throttlingPolicyListDTO.setCount(throttlingPolicyDTOs.size());
    return throttlingPolicyListDTO;
}
Also used : ThrottlingPolicyListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyListDTO) Tier(org.wso2.carbon.apimgt.api.model.Tier) ThrottlingPolicyDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyDTO)

Aggregations

Tier (org.wso2.carbon.apimgt.api.model.Tier)3 ThrottlingPolicyListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyListDTO)2 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)1 ThrottlingPolicyDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyDTO)1 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)1 ThrottlingPolicyDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyDTO)1 ThrottlingPolicyListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyListDTO)1