flowable / flowable/flowable-engine
using BpmnAutoLayout generate ,not get SequenceFlow bpmnElement in xml
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 7h 8m
- Merged PRs (30d)
- 2
Description
**Describe the bug**
flowable 6.6.0 version:

but after generator , in xml or graph,no SequenceFlow
but in activiti 5.22.0 version: it is ok
**Expected behavior**
hope get SequenceFlow
**Code**
`package be.stacktrace.activiti.dynamicprocess;
import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.flowable.bpmn.BpmnAutoLayout;
import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import org.flowable.engine.*;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.flowable.image.impl.DefaultProcessDiagramGenerator;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.StringUtils;
import javax.sound.midi.Soundbank;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class FlowableSubProcessTest {
// @Rule
// public ActivitiRule activitiRule = new ActivitiRule();
RuntimeService runtimeService;
TaskService taskService;
RepositoryService repositoryService;
HistoryService historyService;
//定义流程画布生成器
ProcessDiagramGenerator processDiagramGenerator;
@Before
public void init(){
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")
.setJdbcUsername("sa")
.setJdbcPassword("")
.setJdbcDriver("org.h2.Driver")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
ProcessEngine processEngine = cfg.buildProcessEngine();
runtimeService= processEngine.getRuntimeService();
taskService = processEngine.getTaskService();
repositoryService = processEngine.getRepositoryService();
historyService = processEngine.getHistoryService();
//定义流程画布生成器
processDiagramGenerator = cfg.getProcessDiagramGenerator();
}
@Test
public void testDynamicDeploy() throws Exception {
// 1. Build up the model from scratch
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
bpmnModel.addProcess(process);
process.setId("my-process");
process.addFlowElement(createStartEvent("start"));
process.addFlowElement(createUserTask("task1", "First usertask", "yzf"));
SubProcess subProcess = createSubProcess("yzf", "first subprocess");
fillChildProcess(subProcess,process);
SubProcess subProcess2 = createSubProcess("jingrong", "second subprocess");
fillChildProcess2(subProcess2,process);
process.addFlowElement(subProcess);
// process.addFlowElement(subProcess2);
process.addFlowElement(createEndEvent("end"));
process.addFlowElement(createSequenceFlow("start", "task1"));
process.addFlowElement(createSequenceFlow("task1", "yzf"));
//process.addFlowElement(createSequenceFlow("yzf", "jingrong"));
process.addFlowElement(createSequenceFlow("yzf", "end"));
// 2. Generate graphical information
BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(bpmnModel);
bpmnAutoLayout.execute();
FlowElement yzf = bpmnModel.getMainProcess().getFlowElement("yzf");
System.out.println( yzf instanceof SubProcess);
// SubProcess t= (SubProcess) yzf;
//System.out.println( t.getFlowElements());
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
byte[] convertToXML = bpmnXMLConverter.convertToXML(bpmnModel);
String bytes = new String(convertToXML);
System.out.println(bytes);
// 3. Deploy the process to the engine
Deployment deployment =repositoryService.createDeployment()
.addBpmnModel("dynamic-model.bpmn",bpmnModel).name("Dynamic process deployment").deploy();
// Deployment deployment2= activitiRule.getRepositoryService().createDeployment().addBpmnModel("yzflc.bpmn",model2).name("Dynamic process deployment2").deploy();
// 4. Start a process instance
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process");
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
// 5. Check if task is available
// List tasks = taskService.createTaskQuery().processDefinitionId(processInstance.getProcessDefinitionId()).list();
// System.out.println( tasks);
// Assert.assertEquals(1, tasks.size());
// taskService.complete(tasks.get(0).getId());
//Assert.assertEquals("First task", tasks.get(0).getName());
// Assert.assertEquals("fred", tasks.get(0).getAssignee());
List historyProcess = historyService.createHistoricActivityInstanceQuery().
processInstanceId(processInstance.getProcessInstanceId()).orderByHistoricActivityInstanceStartTime().asc().list();
List activityIds = new ArrayList();
List flows = new ArrayList();
for (HistoricActivityInstance hi : historyProcess) {
String activityType = hi.getActivityType();
if (activityType.equals("sequenceFlow") || activityType.equals("exclusiveGateway")) {
flows.add(hi.getActivityId());
} else if (activityType.equals("userTask") || activityType.equals("startEvent")) {
activityIds.add(hi.getActivityId());
}
}
// 6. Save process diagram to a file
InputStream processDiagram2 = repositoryService.getProcessDiagram(processInstance.getProcessDefinitionId());
FileUtils.copyInputStreamToFile(processDiagram2, new File("target/diagram.png"));
DefaultProcessDiagramGenerator defaultProcessDiagramGenerator=new DefaultProcessDiagramGenerator();
// activityIds.addAll( runtimeService.getActiveActivityIds(tasks.get(0).getExecutionId()));
// InputStream png = processDiagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows,
// "宋体","宋体","宋体",this.getClass().getClassLoader(),1.0, true);
//
// FileUtils.copyInputStreamToFile(png, new File("target/highlight.png"));
// // 7. Save resulting BPMN xml to a file
InputStream processBpmn = repositoryService.getResourceAsStream(deployment.getId(), "dynamic-model.bpmn");
FileUtils.copyInputStreamToFile(processBpmn, new File("target/process.bpmn20.xml"));
}
private void fillChildProcess(SubProcess subProcess, Process process) {
// BpmnModel model = new BpmnModel();
subProcess.addFlowElement(createStartEvent("childStart1"));
subProcess.addFlowElement(createUserTask("first", "first task", ""));
//subProcess.addFlowElement(createUserTask("second", "Second task", "a2"));
// subProcess.addFlowElement(createExclusiveGateway("audit","exclusive gw"));
subProcess.addFlowElement(createEndEvent("childEnd1"));
subProcess.addFlowElement(createSequenceFlow("childStart1", "first"));
// subProcess.addFlowElement(createSequenceFlow("first", "second"));
// subProcess.addFlowElement(createSequenceFlow("second", "audit"));
// subProcess.addFlowElement(createSequenceFlow("audit", "first"));
subProcess.addFlowElement(createSequenceFlow("first", "childEnd1"));
// BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(model);
//bpmnAutoLayout.execute();
}
private void fillChildProcess2(SubProcess subProcess, Process process) {
subProcess.addFlowElement(createStartEvent("childStart2"));
subProcess.addFlowElement(createUserTask("first2", "first task", "a1"));
subProcess.addFlowElement(createUserTask("second2", "Second task", "a2"));
subProcess.addFlowElement(createEndEvent("childEnd2"));
subProcess.addFlowElement(createSequenceFlow("childStart2", "first2"));
subProcess.addFlowElement(createSequenceFlow("first2", "second2"));
subProcess.addFlowElement(createSequenceFlow("second2", "childEnd2"));
}
private ExclusiveGateway createExclusiveGateway(String id, String name) {
ExclusiveGateway exclusiveGateway=new ExclusiveGateway();
exclusiveGateway.setName(name);
exclusiveGateway.setId(id);
return exclusiveGateway;
}
protected SubProcess createSubProcess(String id, String name) {
SubProcess subProcess = new SubProcess();
subProcess.setName(name);
subProcess.setId(id);
//subProcess.setAsynchronous(true);
// callActivity.setAsynchronous(true);
return subProcess;
}
protected UserTask createUserTask(String id, String name, String assignee) {
UserTask userTask = new UserTask();
userTask.setName(name);
userTask.setId(id);
userTask.setAssignee(assignee);
return userTask;
}
protected SequenceFlow createSequenceFlow(String from, String to) {
return createSequenceFlow(from,to,null);
}
protected SequenceFlow createSequenceFlow(String from, String to,String conditionExpress) {
SequenceFlow flow = new SequenceFlow();
flow.setSourceRef(from);
flow.setTargetRef(to);
if(!StringUtils.isEmpty(conditionExpress)){
flow.setConditionExpression(conditionExpress);
}
return flow;
}
protected StartEvent createStartEvent(String startId) {
StartEvent startEvent = new StartEvent();
startEvent.setId(startId);
return startEvent;
}
protected EndEvent createEndEvent(String endId) {
EndEvent endEvent = new EndEvent();
endEvent.setId(endId);
return endEvent;
}
}`
xml:
------
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.