use of org.activiti.workflow.simple.definition.ParallelStepsDefinition 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;
}
use of org.activiti.workflow.simple.definition.ParallelStepsDefinition 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;
}
use of org.activiti.workflow.simple.definition.ParallelStepsDefinition 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());
}
Aggregations