Search in sources :

Example 1 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class ApplicationDeletionWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    if (application == null) {
        // this is when complete method is executed through workflow rest api
        this.application = applicationDAO.getApplication(getWorkflowReference());
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application Deletion workflow complete: Approved");
        }
        applicationDAO.deleteApplication(getWorkflowReference());
        try {
            getApiGateway().deleteApplication(application.getId());
        } catch (GatewayException ex) {
            // This log is not harm to therefore not rethrow
            log.warn("Failed to send the Application Deletion Event ", ex);
        }
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application Deletion workflow complete: Rejected");
        }
    }
    updateWorkflowEntries(this);
    return response;
}
Also used : GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 2 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class ApplicationUpdateWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    String appId = getWorkflowReference();
    String name = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_NAME);
    String updatedUser = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_UPDATEDBY);
    String applicationId = getWorkflowReference();
    String tier = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_TIER);
    String policyId = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_POLICY_ID);
    String description = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_DESCRIPTION);
    String permission = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_PERMISSION);
    Application application = new Application(name, updatedUser);
    application.setPolicy(new ApplicationPolicy(policyId, tier));
    application.setDescription(description);
    application.setId(applicationId);
    application.setUpdatedUser(updatedUser);
    application.setPermissionString(permission);
    application.setUpdatedTime(LocalDateTime.now());
    if (existingApplication == null && updatedApplication == null) {
        // this is when complete method is executed through workflow rest api
        existingApplication = applicationDAO.getApplication(appId);
        updatedApplication = application;
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application update workflow complete: Approved");
        }
        application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
        applicationDAO.updateApplication(appId, application);
        try {
            getApiGateway().updateApplication(application);
        } catch (GatewayException ex) {
            // This log is not harm to therefore not rethrow
            log.warn("Failed to send the Application Update Event ", ex);
        }
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application update workflow complete: Rejected");
        }
        String existingAppStatus = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS);
        applicationDAO.updateApplicationState(appId, existingAppStatus);
    }
    updateWorkflowEntries(this);
    return response;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 3 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class ApprovalWorkflowExecutor method complete.

/**
 * Complete the external process status
 * Based on the workflow status we will update the status column of the
 * Application table
 *
 * @param workFlow - Workflow
 */
public WorkflowResponse complete(Workflow workFlow) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing complete() in Workflow for " + workFlow.getWorkflowType());
    }
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(workFlow.getStatus());
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 4 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SubscriptionCreationWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    if (subscription == null) {
        // this is when complete method is executed through workflow rest api
        subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    APIMgtConstants.SubscriptionStatus subscriptionState = null;
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Subscription Creation workflow complete: Approved");
        }
        subscriptionState = APIMgtConstants.SubscriptionStatus.ACTIVE;
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Subscription Creation workflow complete: Rejected");
        }
        subscriptionState = APIMgtConstants.SubscriptionStatus.REJECTED;
    }
    // Add subscription to gateway
    apiSubscriptionDAO.updateSubscriptionStatus(getWorkflowReference(), subscriptionState);
    updateWorkflowEntries(this);
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (subscription.getApi() != null && subscription.getApplication() != null) {
            List<SubscriptionValidationData> subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
            if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
                apiGateway.addAPISubscription(subscriptionValidationDataList);
                if (log.isDebugEnabled()) {
                    log.debug("Subscription created for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "published to gateway");
                }
            }
        }
    }
    return response;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) APIMgtConstants(org.wso2.carbon.apimgt.core.util.APIMgtConstants)

Example 5 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class TestUtil method createSummaryApplication.

/**
 * Create a summary Applocation only with Application ID, Name, Callback URL, Application Owner and Status
 *
 * @param app Complete Application object
 * @return Summary Application object
 */
public static Application createSummaryApplication(Application app) {
    Application summaryApp = new Application(app.getName(), app.getCreatedUser());
    summaryApp.setId(app.getId());
    summaryApp.setStatus(app.getStatus());
    return summaryApp;
}
Also used : Application(org.wso2.carbon.apimgt.core.models.Application)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)14 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)5 List (java.util.List)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 RepositoryService (org.activiti.engine.RepositoryService)2 Element (org.w3c.dom.Element)2