use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class WorkflowConfigHolder method load.
public void load() throws WorkflowException {
workflowExecutorMap = new ConcurrentHashMap<>();
try {
WorkflowConfig config = WorkflowExtensionsConfigBuilder.getWorkflowConfig();
// Load application creation workflow configurations
loadWorkflowConfigurations(config.getApplicationCreation(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
// Load application deletion workflow configurations
loadWorkflowConfigurations(config.getApplicationDeletion(), WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION);
// Load subscription creation workflow configurations
loadWorkflowConfigurations(config.getSubscriptionCreation(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
// Load subscription deletion workflow configurations
loadWorkflowConfigurations(config.getSubscriptionDeletion(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
// Load api state change workflow configurations
loadWorkflowConfigurations(config.getApiStateChange(), WorkflowConstants.WF_TYPE_AM_API_STATE);
// Load application update workflow configurations
loadWorkflowConfigurations(config.getApplicationUpdate(), WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE);
} catch (ClassNotFoundException e) {
handleException("Unable to find class", e);
} catch (InstantiationException e) {
handleException("Unable to instantiate class", e);
} catch (IllegalAccessException e) {
handleException("Illegal attempt to invoke class methods", e);
} catch (WorkflowException e) {
handleException("Unable to load workflow executor class", e);
}
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionPolicyArrayToListDTO.
/**
* Converts an array of Subscription Policy objects into a List DTO
*
* @param subscriptionPolicies Array of Subscription Policies
* @return A List DTO of converted Subscription Policies
* @throws SubscriptionThrottlePolicyException - If error occurs
*/
public static SubscriptionThrottlePolicyListDTO fromSubscriptionPolicyArrayToListDTO(List<SubscriptionPolicy> subscriptionPolicies) throws SubscriptionThrottlePolicyException {
SubscriptionThrottlePolicyListDTO listDTO = new SubscriptionThrottlePolicyListDTO();
List<SubscriptionThrottlePolicyDTO> subscriptionPolicyDTOList = new ArrayList<>();
if (subscriptionPolicies != null) {
for (SubscriptionPolicy policy : subscriptionPolicies) {
SubscriptionThrottlePolicyDTO dto = fromSubscriptionThrottlePolicyToDTO(policy);
subscriptionPolicyDTOList.add(dto);
}
}
listDTO.setCount(subscriptionPolicyDTOList.size());
listDTO.setList(subscriptionPolicyDTOList);
return listDTO;
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionThrottlePolicyToDTO.
/**
* Converts a single Subscription Policy model into REST API DTO
*
* @param policy Subscription Policy model object
* @return Converted Subscription policy REST API DTO object
* @throws SubscriptionThrottlePolicyException - If error occurs
*/
public static SubscriptionThrottlePolicyDTO fromSubscriptionThrottlePolicyToDTO(SubscriptionPolicy policy) throws SubscriptionThrottlePolicyException {
try {
SubscriptionThrottlePolicyDTO policyDTO = new SubscriptionThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(policy, policyDTO);
SubscriptionPolicy subscriptionPolicy = policy;
policyDTO.setBillingPlan(subscriptionPolicy.getBillingPlan());
policyDTO.setRateLimitCount(subscriptionPolicy.getRateLimitCount());
policyDTO.setRateLimitTimeUnit(subscriptionPolicy.getRateLimitTimeUnit());
policyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
byte[] customAttributes = subscriptionPolicy.getCustomAttributes();
if (customAttributes != null && customAttributes.length > 0) {
List<CustomAttributeDTO> customAttributeDTOs = new ArrayList<>();
JSONParser parser = new JSONParser();
JSONArray attributeArray = (JSONArray) parser.parse(new String(customAttributes, StandardCharsets.UTF_8));
for (Object attributeObj : attributeArray) {
JSONObject attribute = (JSONObject) attributeObj;
CustomAttributeDTO customAttributeDTO = CommonThrottleMappingUtil.getCustomAttribute(attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_NAME).toString(), attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_VALUE).toString());
customAttributeDTOs.add(customAttributeDTO);
}
policyDTO.setCustomAttributes(customAttributeDTOs);
}
if (policy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(policy.getDefaultQuotaPolicy()));
}
return policyDTO;
} catch (ParseException | UnsupportedThrottleLimitTypeException e) {
throw new SubscriptionThrottlePolicyException(e.getMessage(), e);
}
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createSubscription.
public static Subscription createSubscription(String uuid) {
if (StringUtils.isEmpty(uuid)) {
uuid = UUID.randomUUID().toString();
}
Subscription subscription = new Subscription(uuid, createDefaultApplication(), createDefaultAPI().build(), goldApiPolicy);
subscription.setStatus(APIMgtConstants.SubscriptionStatus.ACTIVE);
return subscription;
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class WorkflowExtensionsConfigBuilderTestCase method testWorkflowConfigWithoutConfigFile.
@Test(description = "Test situation where workflow config file loading during a missing config file")
public void testWorkflowConfigWithoutConfigFile() {
WorkflowConfig config = WorkflowExtensionsConfigBuilder.getWorkflowConfig();
Assert.assertNotNull(config.getApplicationCreation(), "Default application creation workflow not set");
Assert.assertNotNull(config.getSubscriptionCreation(), "Default subscription creation workflow not set");
Assert.assertNotNull(config.getApplicationDeletion(), "Default application deletion workflow not set");
Assert.assertNotNull(config.getSubscriptionDeletion(), "Default subscription deletion workflow not set");
WorkflowExtensionsConfigBuilder obj = new WorkflowExtensionsConfigBuilder();
Assert.assertNotNull(obj);
}
Aggregations