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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations