流程部署創(chuàng)建主要影響以下幾張表
ACT_RE_*:’RE’表示repository(存儲)颈渊。RepositoryService接口操作的表终佛。帶此前綴的表包含的是靜態(tài)信息,如,流程定義榜贴,流程的資源(圖片,規(guī)則等)鹃共。
表名 | 說明 |
---|---|
ACT_GE_BYTEARRAY | 流程定義和流程資源 |
ACT_RE_DEPLOYMENT | 部署單元信息 |
ACT_RE_MODEL | 模型信息(主要針對于flowable在線設(shè)計(jì)器) |
ACT_RE_PROCDEF | 流程定義數(shù)據(jù)表 |
flowable流程創(chuàng)建是由DeploymentBuilder接口提供驶拱,支持以下幾種方式創(chuàng)建:
DeploymentBuilder addInputStream(String var1, InputStream var2);
DeploymentBuilder addClasspathResource(String var1);
DeploymentBuilder addString(String var1, String var2);
DeploymentBuilder addBytes(String var1, byte[] var2);
DeploymentBuilder addZipInputStream(ZipInputStream var1);
DeploymentBuilder addBpmnModel(String var1, BpmnModel var2);
addInputStream輸入流創(chuàng)建:
//在resources文件夾下創(chuàng)建 org/flowable/engine/test/repository/one.bpmn20.xml
InputStream bpmnInputStream = this.getClass().getClassLoader().getResourceAsStream("org/flowable/engine/test/repository/one.bpmn20.xml");
Deployment deployment = repositoryService.createDeployment()
.addInputStream("one.bpmn20.xml", bpmnInputStream)
.deploy();
以上創(chuàng)建部署時(shí)的方法返回的結(jié)果還是DeploymentBuilder接口 蓝纲。所以,如果要是創(chuàng)建多個(gè)bpmn税迷,可以在后面追加如下代碼:
Deployment deployment = repositoryService.createDeployment()
.addInputStream("one.bpmn20.xml", bpmnInputStream)
.addInputStream("two.bpmn20.xml", bpmnInputStream)
.deploy();
addClasspathResource (springboot項(xiàng)目會常用),resources文件夾下創(chuàng)建:
repositoryService.createDeployment().addClasspathResource("org/flowable/engine/test/db/processOne.bpmn20.xml").deploy();
此種方式慕嚷,無需轉(zhuǎn)換成InputStream
addString方式,可以通過字符串直接進(jìn)行創(chuàng)建:
private static String UNSAFE_XML = "<?xml version='1.0' encoding='UTF-8'?>" + "<!-- Billion Laugh attacks : http://portal.sliderocket.com/CJAKM/xml-attacks -->" + "<!DOCTYPE lols ["
+ "<!ENTITY lol 'lol'>" + "<!ENTITY lol1 '&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;'>" + "<!ENTITY lol2 '&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;'>"
+ "<!ENTITY lol3 '&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;'>" + "<!ENTITY lol4 '&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;'>"
+ "<!ENTITY lol5 '&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;'>" + "<!ENTITY lol6 '&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;'>"
+ "<!ENTITY lol7 '&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;'>" + "<!ENTITY lol8 '&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;'>"
+ "<!ENTITY lol9 '&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;'>" + "]>" + "<lolz>&lol9;</lolz>" + "<definitions " + "xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL'"
+ "xmlns:activiti='http://activiti.org/bpmn'" + "targetNamespace='Examples'>" + "<process id='oneTaskProcess' name='The One org.flowable.task.service.Task Process'>"
+ " <documentation>This is a process for testing purposes</documentation>" + " <startEvent id='theStart' />" + " <sequenceFlow id='flow1' sourceRef='theStart' targetRef='theTask' />"
+ " <userTask id='theTask' name='my task' />" + " <sequenceFlow id='flow2' sourceRef='theTask' targetRef='theEnd' />" + " <endEvent id='theEnd' />" + "</process>" + "</definitions>";
repositoryService.createDeployment().addString("test.bpmn20.xml", UNSAFE_XML).deploy().getId();
addBytes字節(jié)方式:
可以根據(jù)上面的addString方式進(jìn)行修改,將UNSAFE_XML字符串轉(zhuǎn)換為Bytes[]數(shù)組
repositoryService.createDeployment().addString("Bytes[]方式測試", String.valueOf(UNSAFE_XML .getBytes("UTF-8"))).deploy();
addZipInputStream zip壓縮包方式:
InputStream inputStream = this.getClass()
.getClassLoader()
.getResourceAsStream("org/flowable/engine/test/api/repository/test-processes.zip");
addBpmnModel BpmnModel模型方式創(chuàng)建:
org.flowable.bpmn.model.Process process = new org.flowable.bpmn.model.Process();
process.setId("oneTaskProcess");
process.setName("The one task process");
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
startEvent.setName("The start");
process.addFlowElement(startEvent);
UserTask userTask = new UserTask();
userTask.setName("The Task");
userTask.setId("theTask");
userTask.setAssignee("kermit");
process.addFlowElement(userTask);
EndEvent endEvent = new EndEvent();
endEvent.setId("theEnd");
endEvent.setName("The end");
process.addFlowElement(endEvent);
process.addFlowElement(new SequenceFlow("start", "theTask"));
process.addFlowElement(new SequenceFlow("theTask", "theEnd"));
BpmnModel model = new BpmnModel();
model.addProcess(process);
repositoryService.createDeployment().addBpmnModel("模型方式創(chuàng)建流程", model).deploy();
最后:注意澡谭,無論哪種方式加載 模型名稱 也就是 resourcesName 結(jié)尾必須以bpmn20.xml, bpmn為結(jié)尾译暂,不然不會插入ACT_RE_PROCDEF 流程定義表,源碼位置ParsedDeploymentBuilder.class->build()
while(true) {
EngineResource resource;
do {
if (!var5.hasNext()) {
return new ParsedDeployment(deploymentEntity, processDefinitions, processDefinitionsToBpmnParseMap, processDefinitionsToResourceMap);
}
resource = (EngineResource)var5.next();
} while(!this.isBpmnResource(resource.getName()));//此處根據(jù)名稱判斷是否符合規(guī)規(guī)范
LOGGER.debug("Processing BPMN resource {}", resource.getName());
BpmnParse parse = this.createBpmnParseFromResource(resource);
Iterator var8 = parse.getProcessDefinitions().iterator();
while(var8.hasNext()) {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity)var8.next();
processDefinitions.add(processDefinition);
processDefinitionsToBpmnParseMap.put(processDefinition, parse);
processDefinitionsToResourceMap.put(processDefinition, resource);
}
}