Search in sources :

Example 26 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method updateAPIPolicy.

/**
 * Updated the given API policy
 *
 * @param apiPolicy {@link APIPolicy} instance to be updated
 * @return updated {@link APIPolicy} instance
 */
public static APIPolicy updateAPIPolicy(APIPolicy apiPolicy) {
    apiPolicy.setDisplayName(UPDATED_SAMPLE_API_POLICY);
    apiPolicy.setDescription(UPDATED_SAMPLE_API_POLICY_DESCRIPTION);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
    defaultQuotaPolicy.setLimit(bandwidthLimit);
    apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    apiPolicy.setPipelines(createDefaultPipelines());
    apiPolicy.getPipelines().add(createNewIPRangePipeline());
    return apiPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 27 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultPolicy.

public static void createDefaultPolicy(PolicyDAO policyDAO) throws APIMgtDAOException {
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType(REQUEST_COUNT_TYPE);
    quotaPolicy.setLimit(new RequestCountLimit(SECONDS_TIMUNIT, 60, 1));
    unlimitedApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(unlimitedApiPolicy);
    goldApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(goldApiPolicy);
    silverApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(silverApiPolicy);
    bronzeApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(bronzeApiPolicy);
    unlimitedSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(unlimitedSubscriptionPolicy);
    goldSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(goldSubscriptionPolicy);
    silverSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(silverSubscriptionPolicy);
    bronzeSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(bronzeSubscriptionPolicy);
    fiftyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApplicationPolicy(fiftyPerMinApplicationPolicy);
    twentyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApplicationPolicy(twentyPerMinApplicationPolicy);
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 28 with QuotaPolicy

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

Example 29 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createAPIPolicyWithRequestLimit.

public static APIPolicy createAPIPolicyWithRequestLimit(String name) {
    APIPolicy apiPolicy = new APIPolicy(name);
    apiPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("requestCount");
    RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
    quotaPolicy.setLimit(requestCountLimit);
    apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    apiPolicy.setDisplayName("displayName");
    return apiPolicy;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy)

Example 30 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createAPIPolicyWithBndwidthLimit.

public static APIPolicy createAPIPolicyWithBndwidthLimit(String name) {
    APIPolicy apiPolicy = new APIPolicy(name);
    apiPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("bandwidth");
    BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
    quotaPolicy.setLimit(bandwidthLimit);
    apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    apiPolicy.setDisplayName("displayName");
    return apiPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Aggregations

QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)34 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)23 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)16 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)10 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)9 Test (org.testng.annotations.Test)6 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)6 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)4 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)4 ArrayList (java.util.ArrayList)3 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)3 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)3 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)3 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)3 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)1 Limit (org.wso2.carbon.apimgt.core.models.policy.Limit)1 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)1