use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToLimit.
/**
* Converts a Throttle Limit DTO object into a Limit object
*
* @param dto Throttle Limit DTO object
* @return Limit object derived from DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static Limit fromDTOToLimit(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
if (PolicyConstants.BANDWIDTH_LIMIT_TYPE.equals(dto.getType())) {
// check if all required params are available
if (dto.getBandwidthLimit() == null || dto.getBandwidthLimit().getDataAmount() == null || dto.getBandwidthLimit().getDataUnit() == null) {
// can't continue, throw
String errorMsg = "One or more required params are missing for the ThrottleLimit type: " + dto.getType();
log.error(errorMsg);
throw new UnsupportedThrottleLimitTypeException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
return fromDTOToBandwidthLimit(dto);
} else if (PolicyConstants.REQUEST_COUNT_LIMIT_TYPE.equals(dto.getType())) {
// check if all required params are available
if (dto.getRequestCountLimit() == null || dto.getRequestCountLimit().getRequestCount() == null) {
// can't continue, throw
String errorMsg = "One or more required params are missing for the ThrottleLimit type: " + dto.getType();
log.error(errorMsg);
throw new UnsupportedThrottleLimitTypeException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
return fromDTOToRequestCountLimit(dto);
} else {
String msg = "Throttle limit type " + dto.getType() + " is not supported";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToQuotaPolicy.
/**
* Converts a Throttle Limit DTO object into a Quota Policy object
*
* @param dto Throttle limit DTO object
* @return Derived Quota policy object from DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static QuotaPolicy fromDTOToQuotaPolicy(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setLimit(fromDTOToLimit(dto));
quotaPolicy.setType(mapQuotaPolicyTypeFromDTOToModel(dto.getType()));
return quotaPolicy;
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromConditionalGroupDTOToPipeline.
/**
* Converts a single Conditional Group DTO into a Pipeline object
*
* @param dto Conditional Group DTO
* @return Derived Pipeline object from Conditional Group DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static Pipeline fromConditionalGroupDTOToPipeline(ConditionalGroupDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
Pipeline pipeline = new Pipeline();
pipeline.setDescription(dto.getDescription());
pipeline.setEnabled(true);
pipeline.setQuotaPolicy(fromDTOToQuotaPolicy(dto.getLimit()));
List<Condition> conditions = fromDTOListToConditionList(dto.getConditions());
pipeline.setConditions(conditions);
return pipeline;
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CustomPolicyMappingUtil method fromCustomPolicyDTOToModel.
/**
* Converts a single Custom Policy DTO object into model object.
*
* @param dto Custom Policy DTO object
* @return Model object derived from DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static CustomPolicy fromCustomPolicyDTOToModel(CustomRuleDTO dto) throws UnsupportedThrottleLimitTypeException {
CustomPolicy customPolicy = new CustomPolicy(dto.getPolicyName());
customPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, customPolicy);
customPolicy.setKeyTemplate(dto.getKeyTemplate());
customPolicy.setSiddhiQuery(dto.getSiddhiQuery());
return customPolicy;
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionThrottlePolicyDTOToModel.
/**
* Converts a single Subscription Policy DTO into a model object
*
* @param dto Subscription policy DTO object
* @return Converted Subscription policy model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
@SuppressWarnings("unchecked")
public static SubscriptionPolicy fromSubscriptionThrottlePolicyDTOToModel(SubscriptionThrottlePolicyDTO dto) throws APIManagementException {
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(dto.getPolicyName());
subscriptionPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, subscriptionPolicy);
subscriptionPolicy.setBillingPlan(dto.getBillingPlan());
subscriptionPolicy.setRateLimitTimeUnit(dto.getRateLimitTimeUnit());
subscriptionPolicy.setRateLimitCount(dto.getRateLimitCount());
subscriptionPolicy.setStopOnQuotaReach(dto.getStopOnQuotaReach());
List<CustomAttributeDTO> customAttributes = dto.getCustomAttributes();
if (customAttributes != null && customAttributes.size() > 0) {
JSONArray customAttrJsonArray = new JSONArray();
for (CustomAttributeDTO customAttributeDTO : customAttributes) {
JSONObject attrJsonObj = new JSONObject();
attrJsonObj.put(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_NAME, customAttributeDTO.getName());
attrJsonObj.put(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_VALUE, customAttributeDTO.getValue());
customAttrJsonArray.add(attrJsonObj);
}
try {
subscriptionPolicy.setCustomAttributes(customAttrJsonArray.toJSONString().getBytes(System.getProperty(ENCODING_SYSTEM_PROPERTY, ENCODING_UTF_8)));
} catch (UnsupportedEncodingException e) {
String errorMsg = "Error while setting custom attributes for Subscription Policy: " + dto.getPolicyName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
}
}
if (dto.getDefaultLimit() != null) {
subscriptionPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
}
return subscriptionPolicy;
}
Aggregations