use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromPipelineToConditionalGroupDTO.
/**
* Converts a single Pipeline object into a Conditional Group DTO object
*
* @param pipeline Pipeline object
* @return Derived DTO object from Pipeline object
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static ConditionalGroupDTO fromPipelineToConditionalGroupDTO(Pipeline pipeline) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ConditionalGroupDTO groupDTO = new ConditionalGroupDTO();
groupDTO.setDescription(pipeline.getDescription());
groupDTO.setLimit(fromQuotaPolicyToDTO(pipeline.getQuotaPolicy()));
List<ThrottleConditionDTO> conditionDTOList = fromConditionListToDTOList(pipeline.getConditions());
groupDTO.setConditions(conditionDTOList);
return groupDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromQuotaPolicyToDTO.
/**
* Converts a Quota Policy object into a Throttle Limit DTO object
*
* @param quotaPolicy Quota Policy object
* @return Throttle Limit DTO object derived from the Quota Policy object
* @throws UnsupportedThrottleLimitTypeException
*/
public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) throws UnsupportedThrottleLimitTypeException {
ThrottleLimitDTO defaultLimitType = new ThrottleLimitDTO();
if (PolicyConstants.REQUEST_COUNT_TYPE.equals(quotaPolicy.getType())) {
RequestCountLimit requestCountLimit = (RequestCountLimit) quotaPolicy.getLimit();
defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT);
defaultLimitType.setRequestCount(fromRequestCountLimitToDTO(requestCountLimit));
} else if (PolicyConstants.BANDWIDTH_TYPE.equals(quotaPolicy.getType())) {
BandwidthLimit bandwidthLimit = (BandwidthLimit) quotaPolicy.getLimit();
defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.BANDWIDTHLIMIT);
defaultLimitType.setBandwidth(fromBandwidthLimitToDTO(bandwidthLimit));
} else if (PolicyConstants.EVENT_COUNT_TYPE.equals(quotaPolicy.getType())) {
EventCountLimit eventCountLimit = (EventCountLimit) quotaPolicy.getLimit();
defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT);
defaultLimitType.setEventCount(fromEventCountLimitToDTO(eventCountLimit));
} else {
String msg = "Throttle limit type " + quotaPolicy.getType() + " is not supported";
throw new UnsupportedThrottleLimitTypeException(msg);
}
return defaultLimitType;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.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
*/
public static QuotaPolicy fromDTOToQuotaPolicy(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
String errorMessage;
QuotaPolicy quotaPolicy = new QuotaPolicy();
ThrottleLimitDTO.TypeEnum limitType = dto.getType();
if (limitType != null) {
switch(dto.getType()) {
case REQUESTCOUNTLIMIT:
{
if (dto.getRequestCount() != null) {
quotaPolicy.setLimit(fromDTOToRequestCountLimit(dto.getRequestCount()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT) + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
break;
}
case BANDWIDTHLIMIT:
{
if (dto.getBandwidth() != null) {
quotaPolicy.setLimit(fromDTOToBandwidthLimit(dto.getBandwidth()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleLimitDTO.TypeEnum.BANDWIDTHLIMIT) + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
break;
}
case EVENTCOUNTLIMIT:
{
if (dto.getEventCount() != null) {
quotaPolicy.setLimit(fromDTOToEventCountLimit(dto.getEventCount()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT) + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
break;
}
}
quotaPolicy.setType(mapQuotaPolicyTypeFromDTOToModel(dto.getType()));
} else {
errorMessage = "defaultLimit 'type' property has not been specified\n" + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
return quotaPolicy;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.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
*/
@SuppressWarnings("unchecked")
public static SubscriptionPolicy fromSubscriptionThrottlePolicyDTOToModel(SubscriptionThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException {
// update mandatory fields such as tenantDomain etc.
dto = CommonThrottleMappingUtil.updateDefaultMandatoryFieldsOfThrottleDTO(dto);
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(dto.getPolicyName());
subscriptionPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, subscriptionPolicy);
subscriptionPolicy.setBillingPlan(dto.getBillingPlan());
subscriptionPolicy.setRateLimitTimeUnit(dto.getRateLimitTimeUnit());
subscriptionPolicy.setRateLimitCount(dto.getRateLimitCount());
subscriptionPolicy.setSubscriberCount(dto.getSubscriberCount());
subscriptionPolicy.setStopOnQuotaReach(dto.isStopOnQuotaReach());
if (dto.getGraphQLMaxComplexity() != null) {
subscriptionPolicy.setGraphQLMaxComplexity(dto.getGraphQLMaxComplexity());
}
if (dto.getGraphQLMaxDepth() != null) {
subscriptionPolicy.setGraphQLMaxDepth(dto.getGraphQLMaxDepth());
}
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);
}
subscriptionPolicy.setCustomAttributes(customAttrJsonArray.toJSONString().getBytes());
} else {
// if no custom attributes are set, assign an empty byte array
subscriptionPolicy.setCustomAttributes(new JSONArray().toJSONString().getBytes());
}
if (dto.getMonetization() != null && dto.getMonetization().getMonetizationPlan() != null && StringUtils.isNotBlank(dto.getMonetization().getMonetizationPlan().name())) {
String tierMonetizationPlan = dto.getMonetization().getMonetizationPlan().toString();
subscriptionPolicy.setMonetizationPlan(tierMonetizationPlan);
if (dto.getMonetization().getProperties() != null) {
Map<String, String> tierMonetizationProperties = new HashMap<>();
Map<String, String> props = dto.getMonetization().getProperties();
for (Map.Entry<String, String> entry : props.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
tierMonetizationProperties.put(key, value);
}
subscriptionPolicy.setMonetizationPlanProperties(tierMonetizationProperties);
}
}
if (dto.getDefaultLimit() != null) {
subscriptionPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
}
return subscriptionPolicy;
}
use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionPolicyArrayToListDTO.
/**
* Converts an array of Subscription Policy objects into a List DTO
*
* @param subscriptionPolicies Array of Subscription Policies
* @return A List DTO of converted Subscription Policies
* @throws UnsupportedThrottleLimitTypeException
* @throws ParseException
*/
public static SubscriptionThrottlePolicyListDTO fromSubscriptionPolicyArrayToListDTO(SubscriptionPolicy[] subscriptionPolicies) throws UnsupportedThrottleLimitTypeException, ParseException {
SubscriptionThrottlePolicyListDTO listDTO = new SubscriptionThrottlePolicyListDTO();
List<SubscriptionThrottlePolicyDTO> subscriptionPolicyDTOList = new ArrayList<>();
if (subscriptionPolicies != null) {
for (SubscriptionPolicy policy : subscriptionPolicies) {
SubscriptionThrottlePolicyDTO dto = fromSubscriptionThrottlePolicyToDTO(policy);
subscriptionPolicyDTOList.add(dto);
}
}
listDTO.setCount(subscriptionPolicyDTOList.size());
listDTO.setList(subscriptionPolicyDTOList);
return listDTO;
}
Aggregations