use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class ChoiceStepsDefinitionConverter method createProcessArtifact.
protected ExclusiveGateway createProcessArtifact(ChoiceStepsDefinition choiceStepsDefinition, WorkflowDefinitionConversion conversion) {
// First choice gateway
ExclusiveGateway forkGateway = createExclusiveGateway(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>();
List<SequenceFlow> bypassingFlows = new ArrayList<SequenceFlow>();
for (ListConditionStepDefinition<ChoiceStepsDefinition> stepListDefinition : choiceStepsDefinition.getStepList()) {
StringBuilder conditionBuilder = new StringBuilder();
for (ConditionDefinition conditionDefintion : stepListDefinition.getConditions()) {
if (conditionBuilder.length() > 0) {
conditionBuilder.append(" && ");
} else {
conditionBuilder.append("${");
}
conditionBuilder.append(conditionDefintion.getLeftOperand());
conditionBuilder.append(" ");
conditionBuilder.append(conditionDefintion.getOperator());
conditionBuilder.append(" ");
conditionBuilder.append(conditionDefintion.getRightOperand());
}
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) {
if (conditionBuilder.length() > 0) {
conditionBuilder.append("}");
SequenceFlow mainFlow = addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId(), conditionBuilder.toString());
if (stepListDefinition.getName() != null) {
mainFlow.setName(stepListDefinition.getName());
}
} else {
addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId());
}
}
if ((i + 1) == stepListDefinition.getSteps().size()) {
endElements.add(flowElement);
}
}
if (stepListDefinition.getSteps().isEmpty()) {
// Special case for a "stepless" stepListDefinition, which should just create a sequence-flow from the fork to the join
SequenceFlow created = null;
if (conditionBuilder.length() > 0) {
conditionBuilder.append("}");
created = addSequenceFlow(conversion, forkGateway.getId(), null, conditionBuilder.toString());
} else {
created = addSequenceFlow(conversion, forkGateway.getId(), null);
}
if (stepListDefinition.getName() != null) {
created.setName(stepListDefinition.getName());
}
bypassingFlows.add(created);
}
}
conversion.setSequenceflowGenerationEnabled(false);
// Second choice gateway
ExclusiveGateway joinGateway = createExclusiveGateway(conversion);
conversion.setLastActivityId(joinGateway.getId());
conversion.setSequenceflowGenerationEnabled(true);
// Create sequenceflow from all generated steps to the second gateway
for (FlowElement endElement : endElements) {
if (!(endElement instanceof EndEvent)) {
addSequenceFlow(conversion, endElement.getId(), joinGateway.getId());
}
}
for (SequenceFlow bypassingFlow : bypassingFlows) {
bypassingFlow.setTargetRef(joinGateway.getId());
}
return forkGateway;
}
use of org.activiti.bpmn.model.SequenceFlow in project herd by FINRAOS.
the class JobDefinitionServiceTest method testUpdateJobDefinitionAssertSuccessWhenFirstTaskAsync.
/**
* Asserts that update job definition proceeds without exceptions when first task is set to async
*
* @throws Exception
*/
@Test
public void testUpdateJobDefinitionAssertSuccessWhenFirstTaskAsync() throws Exception {
String namespace = NAMESPACE;
String jobName = JOB_NAME;
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
process.setId(namespace + '.' + jobName);
{
StartEvent element = new StartEvent();
element.setId("start");
process.addFlowElement(element);
}
{
ScriptTask element = new ScriptTask();
element.setId("script");
element.setScriptFormat("js");
element.setScript("// do nothing");
element.setAsynchronous(true);
process.addFlowElement(element);
}
{
EndEvent element = new EndEvent();
element.setId("end");
process.addFlowElement(element);
}
process.addFlowElement(new SequenceFlow("start", "script"));
process.addFlowElement(new SequenceFlow("script", "end"));
bpmnModel.addProcess(process);
String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
namespaceDaoTestHelper.createNamespaceEntity(namespace);
jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
jobDefinitionService.updateJobDefinition(namespace, jobName, new JobDefinitionUpdateRequest(null, activitiJobXml, null, null), true);
// Assert no exceptions
}
use of org.activiti.bpmn.model.SequenceFlow in project herd by FINRAOS.
the class JobDefinitionServiceTest method testCreateJobDefinitionAssertSuccessWhenFirstTaskNotAsyncable.
/**
* Asserts that create job definition proceeds without exceptions when first task does not support async (ex. events)
*
* @throws Exception
*/
@Test
public void testCreateJobDefinitionAssertSuccessWhenFirstTaskNotAsyncable() throws Exception {
String namespace = NAMESPACE;
String jobName = JOB_NAME;
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
process.setId(namespace + '.' + jobName);
{
StartEvent element = new StartEvent();
element.setId("start");
process.addFlowElement(element);
}
{
EndEvent element = new EndEvent();
element.setId("end");
process.addFlowElement(element);
}
process.addFlowElement(new SequenceFlow("start", "end"));
bpmnModel.addProcess(process);
String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
namespaceDaoTestHelper.createNamespaceEntity(namespace);
jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
// Assert no exceptions
}
use of org.activiti.bpmn.model.SequenceFlow in project herd by FINRAOS.
the class JobDefinitionServiceTest method testCreateJobDefinitionAssertSuccessWhenFirstTaskAsync.
/**
* Asserts that create job definition proceeds without exceptions when first task is set to async
*
* @throws Exception
*/
@Test
public void testCreateJobDefinitionAssertSuccessWhenFirstTaskAsync() throws Exception {
String namespace = NAMESPACE;
String jobName = JOB_NAME;
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
process.setId(namespace + '.' + jobName);
{
StartEvent element = new StartEvent();
element.setId("start");
process.addFlowElement(element);
}
{
ScriptTask element = new ScriptTask();
element.setId("script");
element.setScriptFormat("js");
element.setScript("// do nothing");
element.setAsynchronous(true);
process.addFlowElement(element);
}
{
EndEvent element = new EndEvent();
element.setId("end");
process.addFlowElement(element);
}
process.addFlowElement(new SequenceFlow("start", "script"));
process.addFlowElement(new SequenceFlow("script", "end"));
bpmnModel.addProcess(process);
String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
namespaceDaoTestHelper.createNamespaceEntity(namespace);
jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
// Assert no exceptions
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class SimpleConverterTest method validateModel.
private void validateModel(BpmnModel model) {
assertThat(model.getDefinitionsAttributes()).hasSize(2);
assertThat(model.getDefinitionsAttributeValue("http://activiti.com/modeler", "version")).isEqualTo("2.2A");
assertThat(model.getDefinitionsAttributeValue("http://activiti.com/modeler", "exportDate")).isEqualTo("20140312T10:45:23");
assertThat(model.getMainProcess().getId()).isEqualTo("simpleProcess");
assertThat(model.getMainProcess().getName()).isEqualTo("Simple process");
assertThat(model.getMainProcess().getDocumentation()).isEqualTo("simple doc");
assertThat(model.getMainProcess().isExecutable()).isEqualTo(true);
FlowElement flowElement = model.getMainProcess().getFlowElement("flow1");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(SequenceFlow.class);
assertThat(flowElement.getId()).isEqualTo("flow1");
flowElement = model.getMainProcess().getFlowElement("catchEvent");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(IntermediateCatchEvent.class);
assertThat(flowElement.getId()).isEqualTo("catchEvent");
IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) flowElement;
assertThat(catchEvent.getEventDefinitions().size() == 1).isTrue();
EventDefinition eventDefinition = catchEvent.getEventDefinitions().get(0);
assertThat(eventDefinition).isInstanceOf(TimerEventDefinition.class);
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
assertThat(timerDefinition.getTimeDuration()).isEqualTo("PT5M");
flowElement = model.getMainProcess().getFlowElement("userTask1");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(UserTask.class);
UserTask task = (UserTask) flowElement;
assertThat(task.getDocumentation()).isEqualTo("task doc");
flowElement = model.getMainProcess().getFlowElement("flow1Condition");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(SequenceFlow.class);
assertThat(flowElement.getId()).isEqualTo("flow1Condition");
SequenceFlow flow = (SequenceFlow) flowElement;
assertThat(flow.getConditionExpression()).isEqualTo("${number <= 1}");
flowElement = model.getMainProcess().getFlowElement("gateway1");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(ExclusiveGateway.class);
}
Aggregations