Search in sources :

Example 1 with WorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException in project carbon-apimgt by wso2.

the class ApprovalWorkflowExecutor method execute.

/**
 * {@inheritDoc}
 */
@Override
public WorkflowResponse execute(Workflow workFlow) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing execute() in Workflow for " + workFlow.getWorkflowType());
    }
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    // set the state to pending
    workflowResponse.setWorkflowStatus(WorkflowStatus.CREATED);
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 2 with WorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException 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 3 with WorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException in project carbon-apimgt by wso2.

the class WorkflowConfigHolder method loadProperties.

private void loadProperties(List<WorkflowConfigProperties> properties, WorkflowExecutor workFlowExecutor) throws WorkflowException {
    for (Iterator iterator = properties.iterator(); iterator.hasNext(); ) {
        WorkflowConfigProperties workflowConfigProperties = (WorkflowConfigProperties) iterator.next();
        String propertyName = workflowConfigProperties.getName();
        String propertyValue = workflowConfigProperties.getValue();
        if (propertyName == null) {
            handleException("An Executor class property must specify the name attribute");
        } else {
            setInstanceProperty(propertyName, propertyValue, workFlowExecutor);
        }
    }
}
Also used : Iterator(java.util.Iterator) WorkflowConfigProperties(org.wso2.carbon.apimgt.core.models.WorkflowConfigProperties)

Example 4 with WorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException 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);
    }
}
Also used : WorkflowConfig(org.wso2.carbon.apimgt.core.models.WorkflowConfig) WorkflowException(org.wso2.carbon.apimgt.core.exception.WorkflowException)

Example 5 with WorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException in project carbon-apimgt by wso2.

the class ApprovalWorkflowExecutorTestCase method testWorkflowResponses.

@Test(description = "Test workflow responses")
public void testWorkflowResponses() throws WorkflowException {
    WorkflowExecutor executor = new ApprovalWorkflowExecutor();
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    Workflow workflow = new SubscriptionCreationWorkflow(apiSubscriptionDAO, workflowDAO, apiGateway);
    WorkflowResponse respone = executor.execute(workflow);
    Assert.assertEquals(respone.getJSONPayload(), "");
    Assert.assertEquals(respone.getWorkflowStatus(), WorkflowStatus.CREATED);
    workflow.setStatus(WorkflowStatus.APPROVED);
    respone = executor.complete(workflow);
    Assert.assertEquals(respone.getWorkflowStatus(), WorkflowStatus.APPROVED);
    executor.cleanUpPendingTask(workflow.getExternalWorkflowReference());
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) WorkflowExecutor(org.wso2.carbon.apimgt.core.api.WorkflowExecutor) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)56 Test (org.junit.Test)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)49 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)32 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)25 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)24 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)24 Application (org.wso2.carbon.apimgt.api.model.Application)18 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)17 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)15 HashMap (java.util.HashMap)14 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)13 JSONObject (org.json.simple.JSONObject)12 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)12 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)11 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)10 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)10 AbstractWorkflow (org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow)10 XMLStreamException (javax.xml.stream.XMLStreamException)9