Search in sources :

Example 1 with ListStepDefinition

use of org.activiti.workflow.simple.definition.ListStepDefinition in project Activiti by Activiti.

the class SimpleTableEditor method createWorkflow.

protected WorkflowDefinition createWorkflow() {
    WorkflowDefinition workflow = new WorkflowDefinition();
    workflow.setName((String) nameField.getValue());
    String description = (String) descriptionField.getValue();
    if (description != null && description.length() > 0) {
        workflow.setDescription(description);
    }
    List<HumanStepDefinition> steps = taskTable.getSteps();
    for (int i = 0; i < steps.size(); i++) {
        HumanStepDefinition currentStep = steps.get(i);
        // Check if we have a parallel block
        int nextIndex = i + 1;
        ParallelStepsDefinition parallelStepsDefinition = null;
        while (nextIndex < steps.size() && steps.get(nextIndex).isStartsWithPrevious()) {
            if (parallelStepsDefinition == null) {
                parallelStepsDefinition = new ParallelStepsDefinition();
                ListStepDefinition<ParallelStepsDefinition> listStepDef = new ListStepDefinition<ParallelStepsDefinition>();
                listStepDef.addStep(currentStep);
                parallelStepsDefinition.addStepList(listStepDef);
            }
            ListStepDefinition<ParallelStepsDefinition> listStepDef = new ListStepDefinition<ParallelStepsDefinition>();
            listStepDef.addStep(steps.get(nextIndex));
            parallelStepsDefinition.addStepList(listStepDef);
            nextIndex++;
        }
        if (parallelStepsDefinition != null) {
            workflow.addStep(parallelStepsDefinition);
            i = nextIndex - 1;
        } else {
            workflow.addStep(currentStep);
        }
    }
    return workflow;
}
Also used : HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition)

Example 2 with ListStepDefinition

use of org.activiti.workflow.simple.definition.ListStepDefinition in project Activiti by Activiti.

the class ParallelStepsDefinitionConverter method createProcessArtifact.

protected ParallelGateway createProcessArtifact(ParallelStepsDefinition parallelStepsDefinition, WorkflowDefinitionConversion conversion) {
    // First parallel gateway
    ParallelGateway forkGateway = createParallelGateway(conversion);
    // Sequence flow from last activity to first gateway
    addSequenceFlow(conversion, conversion.getLastActivityId(), forkGateway.getId());
    conversion.setLastActivityId(forkGateway.getId());
    // Convert all other steps, disabling activity id updates which makes all 
    // generated steps have a sequence flow to the first gateway
    WorkflowDefinitionConversionFactory conversionFactory = conversion.getConversionFactory();
    List<FlowElement> endElements = new ArrayList<FlowElement>();
    for (ListStepDefinition<ParallelStepsDefinition> stepListDefinition : parallelStepsDefinition.getStepList()) {
        for (int i = 0; i < stepListDefinition.getSteps().size(); i++) {
            if (i == 0) {
                conversion.setSequenceflowGenerationEnabled(false);
            } else {
                conversion.setSequenceflowGenerationEnabled(true);
            }
            StepDefinition step = stepListDefinition.getSteps().get(i);
            FlowElement flowElement = (FlowElement) conversionFactory.getStepConverterFor(step).convertStepDefinition(step, conversion);
            if (i == 0) {
                addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId());
            }
            if ((i + 1) == stepListDefinition.getSteps().size()) {
                endElements.add(flowElement);
            }
        }
    }
    conversion.setSequenceflowGenerationEnabled(false);
    // Second parallel gateway
    ParallelGateway joinGateway = createParallelGateway(conversion);
    conversion.setLastActivityId(joinGateway.getId());
    conversion.setSequenceflowGenerationEnabled(true);
    // Create sequence flow from all generated steps to the second gateway
    for (FlowElement endElement : endElements) {
        addSequenceFlow(conversion, endElement.getId(), joinGateway.getId());
    }
    return forkGateway;
}
Also used : ParallelGateway(org.activiti.bpmn.model.ParallelGateway) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition)

Example 3 with ListStepDefinition

use of org.activiti.workflow.simple.definition.ListStepDefinition in project Activiti by Activiti.

the class JsonConverterTest method testParallelConversion.

@Test
public void testParallelConversion() {
    // Create definition
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inParallel().inList().addHumanStep("first task", "kermit").addHumanStep("second task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endParallel();
    // Write result to byte-array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(baos);
    converter.writeWorkflowDefinition(workflowDefinition, writer);
    // Parse definition based on written JSON
    WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
    // Check if parsed definition matches the original one
    assertEquals(workflowDefinition.getName(), parsedDefinition.getName());
    assertEquals(workflowDefinition.getDescription(), parsedDefinition.getDescription());
    ParallelStepsDefinition parallelDef = null;
    for (StepDefinition step : parsedDefinition.getSteps()) {
        if (step instanceof ParallelStepsDefinition) {
            parallelDef = (ParallelStepsDefinition) step;
        }
    }
    assertNotNull(parallelDef);
    assertEquals(2, parallelDef.getStepList().size());
    ListStepDefinition<ParallelStepsDefinition> listSteps = parallelDef.getStepList().get(0);
    assertEquals(2, listSteps.getSteps().size());
    listSteps = parallelDef.getStepList().get(1);
    assertEquals(1, listSteps.getSteps().size());
}
Also used : WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Aggregations

ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)3 ParallelStepsDefinition (org.activiti.workflow.simple.definition.ParallelStepsDefinition)3 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)2 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)2 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 ParallelGateway (org.activiti.bpmn.model.ParallelGateway)1 WorkflowDefinitionConversionFactory (org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory)1 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)1 Test (org.junit.Test)1