Activiti5 输出指定流程模型的xml
Posted 在奋斗的大道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti5 输出指定流程模型的xml相关的知识,希望对你有一定的参考价值。
前提条件:
1、SpringBoot + Activiti5.22
2、创建流程模型
Controller输出指定流程模型的XML
/**
* 导出指定模型xml 文件
* @param modelId
* @param response
*/
@GetMapping(value = "export/modelId")
public void export(@PathVariable String modelId, HttpServletResponse response)
try
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
OutputStream outputStream = response.getOutputStream();
IOUtils.copy(in, outputStream);
String filename = bpmnModel.getMainProcess().getId() + ".bpmn.xml";
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
outputStream.flush();
outputStream.close();
catch (Exception e)
logger.error("导出model的xml文件失败:", e.getMessage(), e);
运行效果截图:
浏览器输出:http://localhost:8080/activiti/export/7501
流程XML展示:
<?xml version="1.0" encoding="UTF-8"?>
<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:activiti="http://activiti.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.activiti.org/processdef">
<process id="未定义" isExecutable="true">
<startEvent id="sid-26ADDD10-82A2-4A7E-8314-35EE643337D3"></startEvent>
<userTask id="user1" name="发起请假流程"></userTask>
<userTask id="manager1" name="部门经理审批" activiti:assignee="$manager"></userTask>
<exclusiveGateway id="sid-522696AE-6D29-4D93-9B25-AAC7664690E9"></exclusiveGateway>
<endEvent id="sid-8AB4379F-AFD9-460D-A87E-A0312A1E9FEB"></endEvent>
<sequenceFlow id="flow4" sourceRef="user1" targetRef="manager1"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="sid-26ADDD10-82A2-4A7E-8314-35EE643337D3" targetRef="user1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="manager1" targetRef="sid-522696AE-6D29-4D93-9B25-AAC7664690E9"></sequenceFlow>
<sequenceFlow id="flow1" name="同意" sourceRef="sid-522696AE-6D29-4D93-9B25-AAC7664690E9" targetRef="sid-8AB4379F-AFD9-460D-A87E-A0312A1E9FEB">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[$accept =='同意']]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow2" sourceRef="sid-522696AE-6D29-4D93-9B25-AAC7664690E9" targetRef="user1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[$accept=='驳回']]></conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_未定义">
<bpmndi:BPMNPlane bpmnElement="未定义" id="BPMNPlane_未定义">
<bpmndi:BPMNShape bpmnElement="sid-26ADDD10-82A2-4A7E-8314-35EE643337D3" id="BPMNShape_sid-26ADDD10-82A2-4A7E-8314-35EE643337D3">
<omgdc:Bounds height="30.0" width="30.0" x="272.0" y="115.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="user1" id="BPMNShape_user1">
<omgdc:Bounds height="80.0" width="100.0" x="435.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="manager1" id="BPMNShape_manager1">
<omgdc:Bounds height="85.0" width="96.0" x="664.0" y="85.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-522696AE-6D29-4D93-9B25-AAC7664690E9" id="BPMNShape_sid-522696AE-6D29-4D93-9B25-AAC7664690E9">
<omgdc:Bounds height="40.0" width="40.0" x="900.0" y="107.5"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-8AB4379F-AFD9-460D-A87E-A0312A1E9FEB" id="BPMNShape_sid-8AB4379F-AFD9-460D-A87E-A0312A1E9FEB">
<omgdc:Bounds height="28.0" width="28.0" x="1050.0" y="113.5"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="939.5664335664336" y="127.93356643356644"></omgdi:waypoint>
<omgdi:waypoint x="1050.0000849826545" y="127.54878019169809"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="920.5" y="147.0"></omgdi:waypoint>
<omgdi:waypoint x="920.5" y="248.0"></omgdi:waypoint>
<omgdi:waypoint x="485.0" y="248.0"></omgdi:waypoint>
<omgdi:waypoint x="485.0" y="170.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="760.0" y="127.5"></omgdi:waypoint>
<omgdi:waypoint x="900.0" y="127.5"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="535.0" y="129.44933920704847"></omgdi:waypoint>
<omgdi:waypoint x="664.0" y="128.0286343612335"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="302.0" y="130.0"></omgdi:waypoint>
<omgdi:waypoint x="435.0" y="130.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
以上是关于Activiti5 输出指定流程模型的xml的主要内容,如果未能解决你的问题,请参考以下文章
全网最新Spring Boot2.5.1整合Activiti5.22.0企业实战教程<指定任务委派人篇>
全网最新Spring Boot2.5.1整合Activiti5.22.0企业实战教程<指定任务委派人篇>