Search in sources :

Example 6 with MonetizationInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.MonetizationInfoDTO 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

HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 JSONObject (org.json.simple.JSONObject)3 JsonObject (com.google.gson.JsonObject)2 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 MonetizationException (org.wso2.carbon.apimgt.api.MonetizationException)2 API (org.wso2.carbon.apimgt.api.model.API)2 Monetization (org.wso2.carbon.apimgt.api.model.Monetization)2 Scope (org.wso2.carbon.apimgt.api.model.Scope)2 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)2 Tier (org.wso2.carbon.apimgt.api.model.Tier)2 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)2 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)2 APIMonetizationInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMonetizationInfoDTO)2 APIAdditionalPropertiesDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIAdditionalPropertiesDTO)2 APIBusinessInformationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO)2 APIDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIDTO)2 APIMonetizationAttributesDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIMonetizationAttributesDTO)2