Search in sources :

Example 6 with ThrottlingPolicyDTO

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

the class ThrottlingPolicyMappingUtil method fromTierToDTO.

/**
 * Converts a Tier object into TierDTO
 *
 * @param throttlingPolicy Tier object
 * @param tierLevel        tier level (api/application or resource)
 * @return TierDTO corresponds to Tier object
 */
public static ThrottlingPolicyDTO fromTierToDTO(Tier throttlingPolicy, String tierLevel) {
    ThrottlingPolicyDTO dto = new ThrottlingPolicyDTO();
    dto.setName(throttlingPolicy.getName());
    dto.setDescription(throttlingPolicy.getDescription());
    dto.setRequestCount(throttlingPolicy.getRequestCount());
    dto.setUnitTime(throttlingPolicy.getUnitTime());
    dto.setTimeUnit(throttlingPolicy.getTimeUnit());
    dto.setRateLimitCount(throttlingPolicy.getRateLimitCount());
    dto.setRateLimitTimeUnit(throttlingPolicy.getRateLimitTimeUnit());
    dto.setStopOnQuotaReach(throttlingPolicy.isStopOnQuotaReached());
    dto.setDataUnit(throttlingPolicy.getBandwidthDataUnit());
    dto.setPolicyLevel(ThrottlingPolicyDTO.PolicyLevelEnum.valueOf(tierLevel.toUpperCase()));
    dto = setTierPermissions(dto, throttlingPolicy);
    if (throttlingPolicy.getQuotaPolicyType() != null) {
        dto.setQuotaPolicyType(mapQuotaPolicyTypeFromModeltoDTO(throttlingPolicy.getQuotaPolicyType()));
    }
    if (throttlingPolicy.getTierPlan() != null) {
        dto.setTierPlan(ThrottlingPolicyDTO.TierPlanEnum.valueOf(throttlingPolicy.getTierPlan()));
    }
    if (throttlingPolicy.getTierAttributes() != null) {
        Map<String, String> additionalProperties = new HashMap<>();
        for (String key : throttlingPolicy.getTierAttributes().keySet()) {
            additionalProperties.put(key, throttlingPolicy.getTierAttributes().get(key).toString());
        }
        dto.setAttributes(additionalProperties);
    }
    MonetizationInfoDTO monetizationInfoDTO = new MonetizationInfoDTO();
    Map<String, String> monetizationAttributeMap = throttlingPolicy.getMonetizationAttributes();
    if (MapUtils.isNotEmpty(monetizationAttributeMap)) {
        monetizationInfoDTO.setBillingCycle(monetizationAttributeMap.get(APIConstants.Monetization.BILLING_CYCLE));
        monetizationInfoDTO.setCurrencyType(monetizationAttributeMap.get(APIConstants.Monetization.CURRENCY));
        if (StringUtils.isNotBlank(monetizationAttributeMap.get(APIConstants.Monetization.FIXED_PRICE))) {
            monetizationInfoDTO.setFixedPrice(monetizationAttributeMap.get(APIConstants.Monetization.FIXED_PRICE));
            monetizationInfoDTO.setBillingType(MonetizationInfoDTO.BillingTypeEnum.FIXEDPRICE);
        } else {
            monetizationInfoDTO.setPricePerRequest(monetizationAttributeMap.get(APIConstants.Monetization.PRICE_PER_REQUEST));
            monetizationInfoDTO.setBillingType(MonetizationInfoDTO.BillingTypeEnum.DYNAMICRATE);
        }
    }
    dto.setMonetizationAttributes(monetizationInfoDTO);
    return dto;
}
Also used : MonetizationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.MonetizationInfoDTO) HashMap(java.util.HashMap) ThrottlingPolicyDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyDTO)

Aggregations

Tier (org.wso2.carbon.apimgt.api.model.Tier)3 ThrottlingPolicyDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyDTO)3 HashMap (java.util.HashMap)2 ThrottlingPolicyDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyDTO)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 ThrottlingPolicyListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottlingPolicyListDTO)1 MonetizationInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.MonetizationInfoDTO)1 ThrottlingPolicyListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyListDTO)1 ThrottlingPolicyPermissionInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyPermissionInfoDTO)1