use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method updateSubscriptionPolicy.
public static SubscriptionPolicy updateSubscriptionPolicy(SubscriptionPolicy subscriptionPolicy) {
subscriptionPolicy.setDisplayName(UPDATED_SAMPLE_SUBSCRIPTION_POLICY);
subscriptionPolicy.setDescription(UPDATED_SAMPLE_SUBSCRIPTION_POLICY_DESCRIPTION);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
defaultQuotaPolicy.setLimit(bandwidthLimit);
subscriptionPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
return subscriptionPolicy;
}
use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createApplicationPolicyWithRequestLimit.
public static ApplicationPolicy createApplicationPolicyWithRequestLimit(String name) {
ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
applicationPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("requestCount");
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
quotaPolicy.setLimit(requestCountLimit);
applicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
applicationPolicy.setDisplayName("displayName");
return applicationPolicy;
}
use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createApplicationPolicyWithBndwidthLimit.
public static ApplicationPolicy createApplicationPolicyWithBndwidthLimit(String name) {
ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
applicationPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("bandwidth");
BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
quotaPolicy.setLimit(bandwidthLimit);
applicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
applicationPolicy.setDisplayName("displayName");
return applicationPolicy;
}
use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createSubscriptionPolicyWithBndwidthLimit.
public static SubscriptionPolicy createSubscriptionPolicyWithBndwidthLimit(String name) {
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(name);
subscriptionPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("bandwidth");
BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
quotaPolicy.setLimit(bandwidthLimit);
subscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
return subscriptionPolicy;
}
use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy 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 - If error occurs
*/
public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) throws UnsupportedThrottleLimitTypeException {
Limit limit = quotaPolicy.getLimit();
String throttleLimitType = quotaPolicy.getType();
if (PolicyConstants.REQUEST_COUNT_TYPE.equals(throttleLimitType)) {
if (limit instanceof RequestCountLimit) {
RequestCountLimit requestCountLimit = (RequestCountLimit) limit;
return fromRequestCountLimitToDTO(requestCountLimit);
} else {
String msg = "Throttle limit type " + throttleLimitType + " is not of type RequestCountLimit";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
} else if (PolicyConstants.BANDWIDTH_TYPE.equals(throttleLimitType)) {
if (limit instanceof BandwidthLimit) {
BandwidthLimit bandwidthLimit = (BandwidthLimit) limit;
return fromBandwidthLimitToDTO(bandwidthLimit);
} else {
String msg = "Throttle limit type " + throttleLimitType + " is not of type BandwidthLimit";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
} else {
String msg = "Throttle limit type " + throttleLimitType + " is not supported";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
}
Aggregations