src/main/resources/processes/LeaveProcess.bpmn20.xml
Deployment deploy = repositoryService.createDeployment()
.name("请假审批")
.addClasspathResource("processes/LeaveProcess.bpmn20.xml")
.deploy();
InputStream is = new FileInputStream("/Users/xxx/processes/LeaveProcess.bpmn20.xml");
Deployment deploy = repositoryService.createDeployment()
.name("请假审批")
.addInputStream("LeaveProcess.bpmn20.xm", is)
.deploy();
zip中可以同时包含bpmn文件和png文件,也可以只有bpmn文件。
InputStream zip = new FileInputStream("/Users/xxx/Temp/LeaveProcess.zip");
Deployment deploy = repositoryService.createDeployment()
.name("请假审批")
.addZipInputStream(new ZipInputStream(zip))
.deploy();
byte[] 可以从数据库中读取,也可以从文件中获取,也可以从字符串中获取。
InputStream is = new FileInputStream("/Users/mengday/Temp/springboot-flowable/src/main/resources/processes/LeaveProcess.bpmn20.xml");
byte[] bytes = new byte[is.available()];
is.read(bytes);
is.close();
Deployment deploy = repositoryService.createDeployment()
.name("请假审批")
.addBytes("LeaveProcess.bpmn20.xml", bytes)
.deploy();
可以直接使用bpmn文件中的内容来部署,文件内容可以前端传参,也可以保存到数据库中获取。
String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:flowable=\"http://flowable.org/bpmn\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"http://www.omg.org/spec/DD/20100524/DI\" typeLanguage=\"http://www.w3.org/2001/XMLSchema\" expressionLanguage=\"http://www.w3.org/1999/XPath\" targetNamespace=\"http://www.flowable.org/processdef\">\n" +
" <process id=\"HelloWorld\" name=\"HelloWorld\" isExecutable=\"true\">\n" +
" <startEvent id=\"start\"/>\n" +
" <userTask id=\"UserTask1\" name=\"提交\"/>\n" +
" <endEvent id=\"end\"/>\n" +
" <sequenceFlow id=\"sid-82f14707-cd94-46d1-aec7-39fef470fbb8\" sourceRef=\"start\" targetRef=\"UserTask1\"/>\n" +
" <sequenceFlow id=\"sid-e1bab619-907a-40ac-a3ea-234896b048d6\" sourceRef=\"UserTask1\" targetRef=\"end\"/>\n" +
" </process>\n" +
" <bpmndi:BPMNDiagram id=\"BPMNDiagram_HelloWorld\">\n" +
" <bpmndi:BPMNPlane bpmnElement=\"HelloWorld\" id=\"BPMNPlane_HelloWorld\">\n" +
" <bpmndi:BPMNShape id=\"shape-7af2fe47-7aa1-4914-b067-6cc4ca20f0b5\" bpmnElement=\"start\">\n" +
" <omgdc:Bounds x=\"-40.0\" y=\"60.0\" width=\"30.0\" height=\"30.0\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"shape-b82b6f62-7593-4152-bd56-b237310e14e4\" bpmnElement=\"UserTask1\">\n" +
" <omgdc:Bounds x=\"40.000004\" y=\"57.5\" width=\"54.999996\" height=\"35.0\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"shape-b13a4cf4-5071-41bb-8e6d-97bcc6bb0064\" bpmnElement=\"end\">\n" +
" <omgdc:Bounds x=\"145.0\" y=\"60.0\" width=\"30.0\" height=\"30.0\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNEdge id=\"edge-8c366281-90fb-43b6-b462-1ff3a6f14027\" bpmnElement=\"sid-82f14707-cd94-46d1-aec7-39fef470fbb8\">\n" +
" <omgdi:waypoint x=\"-10.0\" y=\"75.0\"/>\n" +
" <omgdi:waypoint x=\"40.0\" y=\"75.0\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"edge-e0337398-70b4-46b5-8c0d-5bba82f50332\" bpmnElement=\"sid-e1bab619-907a-40ac-a3ea-234896b048d6\">\n" +
" <omgdi:waypoint x=\"95.0\" y=\"75.0\"/>\n" +
" <omgdi:waypoint x=\"145.0\" y=\"75.0\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" </bpmndi:BPMNPlane>\n" +
" </bpmndi:BPMNDiagram>\n" +
"</definitions>\n";
Deployment deploy = repositoryService.createDeployment()
.name("请假审批")
.addString("HelloWorld.bpmn20.xml", text)
.deploy();
通过Java代码来创建xml中的对象。
// StartEvent -flow1-> UserTask -flow2-> EndEvent
SequenceFlow flow1 = new SequenceFlow();
flow1.setId("flow1");
flow1.setName("start-userTask1");
flow1.setSourceRef("start");
flow1.setTargetRef("userTask1");
SequenceFlow flow2 = new SequenceFlow();
flow1.setId("flow2");
flow1.setName("userTask1-end");
flow1.setSourceRef("userTask1");
flow1.setTargetRef("end");
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
startEvent.setOutgoingFlows(Arrays.asList(flow1));
UserTask userTask1 = new UserTask();
userTask1.setId("userTask1");
userTask1.setName("提交");
userTask1.setIncomingFlows(Arrays.asList(flow1));
userTask1.setOutgoingFlows(Arrays.asList(flow2));
EndEvent endEvent = new EndEvent();
endEvent.setId("end");
endEvent.setIncomingFlows(Arrays.asList(flow2));
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
process.setId("HelloWorld");
process.setName("请假审批");
process.addFlowElement(startEvent);
process.addFlowElement(flow1);
process.addFlowElement(userTask1);
process.addFlowElement(flow2);
process.addFlowElement(endEvent);
bpmnModel.addProcess(process);
Deployment deploy = repositoryService.createDeployment()
.name("自定义BpmnModel")
.addBpmnModel("HelloWorld", bpmnModel)
.deploy();