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>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值