use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CustomPolicyMappingUtil method fromCustomPolicyToDTO.
/**
* Converts a single Custom Policy model object into DTO object.
*
* @param globalPolicy Custom Policy model object
* @return DTO object derived from the Policy model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static CustomRuleDTO fromCustomPolicyToDTO(CustomPolicy globalPolicy) throws UnsupportedThrottleLimitTypeException {
CustomRuleDTO policyDTO = new CustomRuleDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(globalPolicy, policyDTO);
policyDTO.setKeyTemplate(globalPolicy.getKeyTemplate());
policyDTO.setSiddhiQuery(globalPolicy.getSiddhiQuery());
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CustomPolicyMappingUtil method fromCustomPolicyArrayToListDTO.
/**
* Converts an array of Custom Policy model objects into REST API DTO objects.
*
* @param customPolicies An array of custom policy model objects
* @return A List DTO of Custom Policy DTOs derived from the array of model objects
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static CustomRuleListDTO fromCustomPolicyArrayToListDTO(List<CustomPolicy> customPolicies) throws UnsupportedThrottleLimitTypeException {
CustomRuleListDTO listDTO = new CustomRuleListDTO();
List<CustomRuleDTO> customPolicyDTOList = new ArrayList<>();
if (customPolicies != null) {
for (CustomPolicy policy : customPolicies) {
CustomRuleDTO dto = fromCustomPolicyToDTO(policy);
customPolicyDTOList.add(dto);
}
}
listDTO.setCount(customPolicyDTOList.size());
listDTO.setList(customPolicyDTOList);
return listDTO;
}
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 policy Subscription Policy model object
* @return Converted Subscription policy REST API DTO object
* @throws SubscriptionThrottlePolicyException - If error occurs
*/
public static SubscriptionThrottlePolicyDTO fromSubscriptionThrottlePolicyToDTO(SubscriptionPolicy policy) throws SubscriptionThrottlePolicyException {
try {
SubscriptionThrottlePolicyDTO policyDTO = new SubscriptionThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(policy, policyDTO);
SubscriptionPolicy subscriptionPolicy = policy;
policyDTO.setBillingPlan(subscriptionPolicy.getBillingPlan());
policyDTO.setRateLimitCount(subscriptionPolicy.getRateLimitCount());
policyDTO.setRateLimitTimeUnit(subscriptionPolicy.getRateLimitTimeUnit());
policyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
byte[] customAttributes = subscriptionPolicy.getCustomAttributes();
if (customAttributes != null && customAttributes.length > 0) {
List<CustomAttributeDTO> customAttributeDTOs = new ArrayList<>();
JSONParser parser = new JSONParser();
JSONArray attributeArray = (JSONArray) parser.parse(new String(customAttributes, StandardCharsets.UTF_8));
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 (policy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(policy.getDefaultQuotaPolicy()));
}
return policyDTO;
} catch (ParseException | UnsupportedThrottleLimitTypeException e) {
throw new SubscriptionThrottlePolicyException(e.getMessage(), e);
}
}
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 policies Array of Advanced Policies
* @return A List DTO of converted Advanced Policies
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static AdvancedThrottlePolicyListDTO fromAPIPolicyArrayToListDTO(List<APIPolicy> policies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyListDTO listDTO = new AdvancedThrottlePolicyListDTO();
List<AdvancedThrottlePolicyDTO> advancedPolicyDTOs = new ArrayList<>();
if (policies != null) {
for (APIPolicy policy : policies) {
advancedPolicyDTOs.add(fromAdvancedPolicyToDTO(policy));
}
}
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 fromAdvancedPolicyToInfoDTO.
/**
* 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 - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static AdvancedThrottlePolicyDTO fromAdvancedPolicyToInfoDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyDTO policyDTO = new AdvancedThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
if (apiPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
Aggregations