Search in sources :

Example 71 with SubscriptionPolicy

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

the class SampleTestObjectCreator method createSubscriptionPolicyWithRequestLimit.

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

Example 72 with SubscriptionPolicy

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

the class TestUtil method createApi.

protected static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
    Set<String> transport = new HashSet<>();
    transport.add("http");
    Set<Policy> policies = new HashSet<>();
    policies.add(new SubscriptionPolicy("Silver"));
    policies.add(new SubscriptionPolicy("Bronze"));
    Set<String> tags = new HashSet<>();
    tags.add("food");
    tags.add("beverage");
    BusinessInformation businessInformation = new BusinessInformation();
    businessInformation.setBusinessOwner("John Doe");
    businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
    businessInformation.setTechnicalOwner("Jane Doe");
    businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    corsConfiguration.setEnabled(true);
    corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
    corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
    corsConfiguration.setAllowCredentials(true);
    corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
    API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition("swagger definition").wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
    apiBuilder.uriTemplates(Collections.emptyMap());
    return apiBuilder;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashSet(java.util.HashSet)

Example 73 with SubscriptionPolicy

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

the class APIMappingUtilTestCase method createApi.

private static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
    Set<String> transport = new HashSet<>();
    transport.add("http");
    Set<Policy> policies = new HashSet<>();
    policies.add(new SubscriptionPolicy("Silver"));
    policies.add(new SubscriptionPolicy("Bronze"));
    Set<String> tags = new HashSet<>();
    tags.add("food");
    tags.add("beverage");
    BusinessInformation businessInformation = new BusinessInformation();
    businessInformation.setBusinessOwner("John Doe");
    businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
    businessInformation.setTechnicalOwner("Jane Doe");
    businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    corsConfiguration.setEnabled(true);
    corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
    corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
    corsConfiguration.setAllowCredentials(true);
    corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
    API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition("").wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
    apiBuilder.uriTemplates(Collections.emptyMap());
    return apiBuilder;
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashSet(java.util.HashSet)

Example 74 with SubscriptionPolicy

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

the class APISubscriptionDAOImpl method createSubscriptionsWithApiInformationOnly.

private List<Subscription> createSubscriptionsWithApiInformationOnly(ResultSet rs) throws APIMgtDAOException {
    List<Subscription> subscriptionList = new ArrayList<>();
    try {
        Subscription subscription;
        while (rs.next()) {
            String subscriptionId = rs.getString("SUBS_UUID");
            String subscriptionTier = rs.getString("SUBS_POLICY");
            API.APIBuilder apiBuilder = new API.APIBuilder(rs.getString("API_PROVIDER"), rs.getString("API_NAME"), rs.getString("API_VERSION"));
            apiBuilder.id(rs.getString("API_ID"));
            apiBuilder.context(rs.getString("API_CONTEXT"));
            API api = apiBuilder.build();
            subscription = new Subscription(subscriptionId, null, api, new SubscriptionPolicy(subscriptionTier));
            subscription.setStatus(APIMgtConstants.SubscriptionStatus.valueOf(rs.getString("SUB_STATUS")));
            subscriptionList.add(subscription);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "creating subscriptions api information", e);
    }
    return subscriptionList;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Subscription(org.wso2.carbon.apimgt.core.models.Subscription)

Example 75 with SubscriptionPolicy

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

the class APIPublisherImpl method validateSubscriptionPolicies.

private void validateSubscriptionPolicies(API.APIBuilder apiBuilder) throws APIManagementException {
    Set<Policy> subPolicies = new HashSet();
    for (Policy subscriptionPolicy : apiBuilder.getPolicies()) {
        Policy policy = getPolicyByName(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName());
        if (policy == null) {
            throw new APIManagementException("Api Policy " + apiBuilder.getApiPolicy() + "Couldn't " + "find", ExceptionCodes.POLICY_NOT_FOUND);
        }
        subPolicies.add(policy);
    }
    apiBuilder.policies(subPolicies);
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashSet(java.util.HashSet)

Aggregations

SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)74 Test (org.testng.annotations.Test)41 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)33 API (org.wso2.carbon.apimgt.core.models.API)30 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)30 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)24 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)21 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)19 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)16 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)15 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)15 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)14 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)14 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)13 ArrayList (java.util.ArrayList)12 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)12 HashSet (java.util.HashSet)10 Application (org.wso2.carbon.apimgt.core.models.Application)9 SQLException (java.sql.SQLException)8