Flowable中6种部署方式

1. addClasspathResource

src/main/resources/processes/LeaveProcess.bpmn20.xml

Deployment deploy = repositoryService.createDeployment()
        .name("请假审批")
        .addClasspathResource("processes/LeaveProcess.bpmn20.xml")
        .deploy();

2. addInputStream

InputStream is = new FileInputStream("/Users/xxx/processes/LeaveProcess.bpmn20.xml");
        Deployment deploy = repositoryService.createDeployment()
                .name("请假审批")
                .addInputStream("LeaveProcess.bpmn20.xm", is)
                .deploy();

3. addZipInputStream

zip中可以同时包含bpmn文件和png文件,也可以只有bpmn文件。

InputStream zip = new FileInputStream("/Users/xxx/Temp/LeaveProcess.zip");
        Deployment deploy = repositoryService.createDeployment()
                .name("请假审批")
                .addZipInputStream(new ZipInputStream(zip))
                .deploy();

4. addBytes

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();

5. addString

可以直接使用bpmn文件中的内容来部署,文件内容可以前端传参,也可以保存到数据库中获取。

String text = "\n" +
  "\n" +
    "  \n" +
    "    \n" +
    "    \n" +
    "    \n" +
    "    \n" +
    "    \n" +
    "  \n" +
    "  \n" +
    "    \n" +
    "      \n" +
    "        \n" +
    "      \n" +
    "      \n" +
    "        \n" +
    "      \n" +
    "      \n" +
    "        \n" +
    "      \n" +
    "      \n" +
    "        \n" +
    "        \n" +
    "      \n" +
    "      \n" +
    "        \n" +
    "        \n" +
    "      \n" +
    "    \n" +
    "  \n" +
    "\n";

Deployment deploy = repositoryService.createDeployment()
        .name("请假审批")
        .addString("HelloWorld.bpmn20.xml", text)
        .deploy();

6. addBpmnModel

通过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();

Flowable中6种部署方式_第1张图片

你可能感兴趣的:(Flowable,flow)