use of org.wso2.carbon.apimgt.rest.api.store.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;
}
Aggregations