use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomAttributeDTO in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionThrottlePolicyToDTO.
/**
* Converts a single Subscription Policy model into REST API DTO
*
* @param subscriptionPolicy Subscription Policy model object
* @return Converted Subscription policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException
* @throws ParseException
*/
public static SubscriptionThrottlePolicyDTO fromSubscriptionThrottlePolicyToDTO(SubscriptionPolicy subscriptionPolicy) throws UnsupportedThrottleLimitTypeException, ParseException {
SubscriptionThrottlePolicyDTO policyDTO = new SubscriptionThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(subscriptionPolicy, policyDTO);
policyDTO.setBillingPlan(subscriptionPolicy.getBillingPlan());
policyDTO.setRateLimitCount(subscriptionPolicy.getRateLimitCount());
policyDTO.setRateLimitTimeUnit(subscriptionPolicy.getRateLimitTimeUnit());
policyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
policyDTO.setGraphQLMaxComplexity(subscriptionPolicy.getGraphQLMaxComplexity());
policyDTO.setGraphQLMaxDepth(subscriptionPolicy.getGraphQLMaxDepth());
policyDTO.setSubscriberCount(subscriptionPolicy.getSubscriberCount());
byte[] customAttributes = subscriptionPolicy.getCustomAttributes();
if (customAttributes != null) {
List<CustomAttributeDTO> customAttributeDTOs = new ArrayList<>();
JSONParser parser = new JSONParser();
JSONArray attributeArray = (JSONArray) parser.parse(new String(subscriptionPolicy.getCustomAttributes()));
for (Object attributeObj : attributeArray) {
JSONObject attribute = (JSONObject) attributeObj;
CustomAttributeDTO customAttributeDTO = CommonThrottleMappingUtil.getCustomAttribute(attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_NAME).toString(), attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_VALUE).toString());
customAttributeDTOs.add(customAttributeDTO);
}
policyDTO.setCustomAttributes(customAttributeDTOs);
}
if (subscriptionPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(subscriptionPolicy.getDefaultQuotaPolicy()));
}
policyDTO.setType(SUBSCRIPTION_THROTTLE_POLICY_TYPE);
if (APIConstants.COMMERCIAL_TIER_PLAN.equals(subscriptionPolicy.getBillingPlan())) {
MonetizationInfoDTO monetizationInfoDTO = new MonetizationInfoDTO();
if (APIConstants.Monetization.FIXED_RATE.equalsIgnoreCase(subscriptionPolicy.getMonetizationPlan())) {
monetizationInfoDTO.setMonetizationPlan(MonetizationInfoDTO.MonetizationPlanEnum.FIXEDRATE);
} else {
monetizationInfoDTO.setMonetizationPlan(MonetizationInfoDTO.MonetizationPlanEnum.DYNAMICRATE);
}
monetizationInfoDTO.setProperties(subscriptionPolicy.getMonetizationPlanProperties());
policyDTO.setMonetization(monetizationInfoDTO);
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomAttributeDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method getCustomAttribute.
/**
* Create a custom attribute using the given name and value
*
* @param name Name of the attribute
* @param value Value of the attribute
* @return Custom Attribute object containing the given name and value
*/
public static CustomAttributeDTO getCustomAttribute(String name, String value) {
CustomAttributeDTO customAttributeDTO = new CustomAttributeDTO();
customAttributeDTO.setName(name);
customAttributeDTO.setValue(value);
return customAttributeDTO;
}
Aggregations