use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException 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.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyDTOToPolicy.
/**
* Converts a single Advanced Policy DTO into a model object
*
* @param dto Advanced policy DTO object
* @return Converted Advanced policy model object
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static APIPolicy fromAdvancedPolicyDTOToPolicy(AdvancedThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
// update mandatory fields such as tenantDomain etc.
dto = CommonThrottleMappingUtil.updateDefaultMandatoryFieldsOfThrottleDTO(dto);
APIPolicy apiPolicy = new APIPolicy(dto.getPolicyName());
apiPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, apiPolicy);
List<Pipeline> pipelines = CommonThrottleMappingUtil.fromConditionalGroupDTOListToPipelineList(dto.getConditionalGroups());
apiPolicy.setPipelines(pipelines);
if (dto.getDefaultLimit() != null) {
apiPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
}
return apiPolicy;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAPIPolicyArrayToListDTO.
/**
* Converts an array of Advanced Policy objects into a List DTO
*
* @param apiPolicies Array of Advanced Policies
* @return A List DTO of converted Advanced Policies
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static AdvancedThrottlePolicyListDTO fromAPIPolicyArrayToListDTO(APIPolicy[] apiPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyListDTO listDTO = new AdvancedThrottlePolicyListDTO();
List<AdvancedThrottlePolicyInfoDTO> advancedPolicyDTOs = new ArrayList<>();
if (apiPolicies != null) {
for (APIPolicy apiPolicy : apiPolicies) {
advancedPolicyDTOs.add(fromAdvancedPolicyToInfoDTO(apiPolicy));
}
}
listDTO.setList(advancedPolicyDTOs);
listDTO.setCount(advancedPolicyDTOs.size());
return listDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyToDTO.
/**
* Converts a single Advanced Policy model into REST API DTO
*
* @param apiPolicy Advanced Policy model object
* @return Converted Advanced policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static AdvancedThrottlePolicyDTO fromAdvancedPolicyToDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyDTO policyDTO = new AdvancedThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
List<ConditionalGroupDTO> groupDTOs = CommonThrottleMappingUtil.fromPipelineListToConditionalGroupDTOList(apiPolicy.getPipelines());
policyDTO.setConditionalGroups(groupDTOs);
policyDTO.setType(ADVANCED_THROTTLING_POLICY_TYPE);
if (apiPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class GlobalThrottlePolicyMappingUtil method fromGlobalThrottlePolicyDTOToModel.
/**
* Converts a single Global policy DTO object into model object
*
* @param dto Global policy DTO object
* @return Model object derived from DTO
* @throws UnsupportedThrottleLimitTypeException
*/
public static GlobalPolicy fromGlobalThrottlePolicyDTOToModel(CustomRuleDTO dto) throws UnsupportedThrottleLimitTypeException {
// update mandatory fields such as tenantDomain etc.
dto = CommonThrottleMappingUtil.updateDefaultMandatoryFieldsOfThrottleDTO(dto);
GlobalPolicy globalPolicy = new GlobalPolicy(dto.getPolicyName());
globalPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, globalPolicy);
globalPolicy.setKeyTemplate(dto.getKeyTemplate());
globalPolicy.setSiddhiQuery(dto.getSiddhiQuery());
return globalPolicy;
}
Aggregations