Search in sources :

Example 1 with SubscriptionDeletionWorkflow

use of org.wso2.carbon.apimgt.core.workflow.SubscriptionDeletionWorkflow in project carbon-apimgt by wso2.

the class WorkflowExecutorFactory method createWorkflow.

/**
 * Create a DTO object related to a given workflow type.
 *
 * @param workflowType Type of the workflow.
 * @return WorkFlow instance
 */
public Workflow createWorkflow(String workflowType) throws APIMgtDAOException {
    Workflow workflow = null;
    if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(workflowType)) {
        workflow = new ApplicationCreationWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equals(workflowType)) {
        workflow = new ApplicationDeletionWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(workflowType)) {
        workflow = new SubscriptionCreationWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equals(workflowType)) {
        workflow = new SubscriptionDeletionWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(workflowType)) {
        workflow = new APIStateChangeWorkflow(DAOFactory.getApiDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().geApiLifecycleManager(), APIManagerFactory.getInstance().getApiGateway(), DAOFactory.getLabelDAO());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE.equals(workflowType)) {
        workflow = new ApplicationUpdateWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else {
        throw new APIMgtDAOException("Invalid workflow type: " + workflowType + " specified", ExceptionCodes.WORKFLOW_INVALID_WFTYPE);
    }
    return workflow;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 2 with SubscriptionDeletionWorkflow

use of org.wso2.carbon.apimgt.core.workflow.SubscriptionDeletionWorkflow in project carbon-apimgt by wso2.

the class APIStoreImpl method deleteAPISubscription.

/**
 * @see APIStore#deleteAPISubscription(String)
 */
@Override
public WorkflowResponse deleteAPISubscription(String subscriptionId) throws APIManagementException {
    try {
        WorkflowExecutor removeSubscriptionWFExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
        // check for pending subscription creation
        if (subscriptionId == null) {
            String errorMsg = "Subscription Id is not provided";
            log.error(errorMsg);
            throw new APIManagementException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
        }
        Subscription subscription = getApiSubscriptionDAO().getAPISubscription(subscriptionId);
        if (subscription == null) {
            String errorMsg = "Subscription not found for the id - " + subscriptionId;
            log.error(errorMsg);
            throw new APIManagementException(errorMsg, ExceptionCodes.SUBSCRIPTION_NOT_FOUND);
        } else {
            // remove pending tasks for subscription creation first
            cleanupPendingTaskForSubscriptionDeletion(subscription);
            SubscriptionDeletionWorkflow workflow = new SubscriptionDeletionWorkflow(getApiSubscriptionDAO(), getWorkflowDAO(), getApiGateway());
            workflow.setWorkflowReference(subscriptionId);
            workflow.setSubscription(subscription);
            workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
            workflow.setStatus(WorkflowStatus.CREATED);
            workflow.setCreatedTime(LocalDateTime.now());
            workflow.setExternalWorkflowReference(UUID.randomUUID().toString());
            workflow.setSubscriber(getUsername());
            String workflowDescription = "API [ " + subscription.getApi().getName() + " - " + subscription.getApi().getVersion() + " ] subscription deletion request from subscriber - " + getUsername() + "  for the application - " + subscription.getApplication().getName() + "";
            workflow.setWorkflowDescription(workflowDescription);
            WorkflowResponse response = removeSubscriptionWFExecutor.execute(workflow);
            workflow.setStatus(response.getWorkflowStatus());
            if (WorkflowStatus.CREATED != response.getWorkflowStatus()) {
                completeWorkflow(removeSubscriptionWFExecutor, workflow);
            } else {
                // add entry to workflow table if it is only in pending state
                // haven't changed the subscription's state to allow to use it till approval
                addWorkflowEntries(workflow);
            }
            return response;
        }
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while deleting api subscription - " + subscriptionId;
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) WorkflowExecutor(org.wso2.carbon.apimgt.core.api.WorkflowExecutor) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionDeletionWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionDeletionWorkflow)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 WorkflowExecutor (org.wso2.carbon.apimgt.core.api.WorkflowExecutor)1 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)1 SubscriptionDeletionWorkflow (org.wso2.carbon.apimgt.core.workflow.SubscriptionDeletionWorkflow)1