Search in sources :

Example 1 with BandwidthLimit

use of org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createSubscriptionPolicyWithBandwithLimit.

public static SubscriptionPolicy createSubscriptionPolicyWithBandwithLimit() {
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy("SubPolicyBandwith");
    subscriptionPolicy.setUuid(UUID.randomUUID().toString());
    subscriptionPolicy.setDisplayName(SAMPLE_SUBSCRIPTION_POLICY);
    subscriptionPolicy.setDescription(SAMPLE_SUBSCRIPTION_POLICY_DESCRIPTION);
    subscriptionPolicy.setCustomAttributes(SAMPLE_CUSTOM_ATTRIBUTE.getBytes());
    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);
    subscriptionPolicy.setBillingPlan(BUSINESS_PLAN_FREE);
    subscriptionPolicy.setRateLimitCount(100);
    subscriptionPolicy.setRateLimitTimeUnit("s");
    subscriptionPolicy.setStopOnQuotaReach(true);
    return subscriptionPolicy;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 2 with BandwidthLimit

use of org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method updateApplicationPolicy.

public static ApplicationPolicy updateApplicationPolicy(ApplicationPolicy applicationPolicy) {
    applicationPolicy.setDisplayName(UPDATED_SAMPLE_APP_POLICY);
    applicationPolicy.setDescription(UPDATED_SAMPLE_APP_POLICY_DESCRIPTION);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 10, 1000, "KB");
    defaultQuotaPolicy.setLimit(bandwidthLimit);
    applicationPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    return applicationPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 3 with BandwidthLimit

use of org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit 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;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 4 with BandwidthLimit

use of org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromBandwidthLimitToDTO.

/**
 * Converts a Bandwidth Limit model object into a Bandwidth Limit DTO object
 *
 * @param bandwidthLimit Bandwidth Limit model object
 * @return Bandwidth Limit DTO object derived from model
 */
public static ThrottleLimitDTO fromBandwidthLimitToDTO(BandwidthLimit bandwidthLimit) {
    // done
    ThrottleLimitDTO dto = new ThrottleLimitDTO();
    dto = updateFieldsFromLimitToDTO(bandwidthLimit, dto);
    dto.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
    dto.setBandwidthLimit(new BandwidthLimitDTO());
    dto.getBandwidthLimit().setDataAmount(bandwidthLimit.getDataAmount());
    dto.getBandwidthLimit().setDataUnit(bandwidthLimit.getDataUnit());
    return dto;
}
Also used : ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO) BandwidthLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BandwidthLimitDTO)

Example 5 with BandwidthLimit

use of org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit 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;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Aggregations

BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)19 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)18 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)15 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)15 QuotaPolicy (org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy)13 EventCountLimit (org.wso2.carbon.apimgt.api.model.policy.EventCountLimit)10 ArrayList (java.util.ArrayList)7 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)7 PreparedStatement (java.sql.PreparedStatement)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)4 Test (org.testng.annotations.Test)3 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)3 Condition (org.wso2.carbon.apimgt.api.model.policy.Condition)3 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)3