项目源码仓库

BPMN2.0(Business Process Model and Notation)是一套业务流程模型与符号建模标准,以XML为载体,以符号可视化业务,支持精准的执行语义来描述元素的操作。

Flowable诞生于Activiti,是一个使用Java编写的轻量级业务流程引擎。Flowable流程引擎可用于部署BPMN 2.0流程定义,可以十分灵活地加入你的应用/服务/构架。

本文给出两种从flowable导出流程定义bpmn20.xml的方式。

导入Maven依赖

  1. <dependency>
  2. <groupId>org.flowable</groupId>
  3. <artifactId>flowable-spring-boot-starter-basic</artifactId>
  4. <version>6.4.1</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.flowable</groupId>
  8. <artifactId>flowable-json-converter</artifactId>
  9. <version>6.4.1</version>
  10. </dependency>

从流程模型导出流程定义bpmn20.xml

通过流程编辑器制作的流程模型(如下图所示), 可以通过模型ID(Model.id),调用flowable 的 RepositoryService 来生成bpmn20.xml。

  1. @Service
  2. public class MyModelServiceImpl implements MyModelService {
  3. @Autowired
  4. private RepositoryService repositoryService;
  5. /**
  6. * 通过模型ID,生成模型BPMN20.xml
  7. * @param guid 模型id,即model.id
  8. * @return
  9. * @throws Exception
  10. */
  11. @Override
  12. public ResultDTO genXml(String guid) throws Exception {
  13. /**通过ID获取模型 **/
  14. Model modelData = repositoryService.getModel(guid);
  15. byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
  16. if (bytes == null) {
  17. return ResultDTO.failureCustom("模型数据为空,请先设计流程并成功保存,再进行发布。");
  18. }
  19. JsonNode modelNode = new ObjectMapper().readTree(bytes);
  20. BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
  21. if (model.getProcesses().size() == 0) {
  22. return ResultDTO.failureCustom("数据模型不符要求,请至少设计一条主线流程。");
  23. }
  24. /** 设置名称 **/
  25. model.getMainProcess().setName(modelData.getName());
  26. /** 设置 targetNamespace **/
  27. if(StringUtils.isNotBlank(modelData.getCategory())) {
  28. model.setTargetNamespace(modelData.getCategory());
  29. }
  30. byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
  31. String xml = new String(bpmnBytes, "UTF-8");
  32. return ResultDTO.success(xml);
  33. }
  34. }

运行效果如下:

{% asset_img res1.gif 导出效果 %}

从流程定义导出流程定义bpmn20.xml

对于flowable已经部署的流程,可根据流程定义(ProcessDefinition.id),调用flowable 的RepositoryService来导出其bpmn20.xml。

  1. @RestController
  2. @Slf4j
  3. public class ProcessController {
  4. @Autowired
  5. private MyProcessService processService;
  6. /**
  7. * 通过processDefinition.id和resType导出流程XML或图片资源
  8. * @param id processDefinition.id
  9. * @param resType 取值 “image/png”或“text/xml”
  10. * @param response
  11. * @throws Exception
  12. */
  13. @GetMapping(value = "/res/exp")
  14. @ApiOperation("通过processDefinition.id和resType导出流程XML或图片资源")
  15. public void resourceRead(@RequestParam("id") String id,@RequestParam("resType") String resType, HttpServletResponse response) throws Exception {
  16. /** resType取值 “image/png”或“text/xml” **/
  17. InputStream resourceAsStream = processService.resourceRead(id,resType);
  18. byte[] b = new byte[1024];
  19. int len = -1;
  20. while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
  21. response.getOutputStream().write(b, 0, len);
  22. }
  23. }
  24. }
  1. @Service
  2. public class MyProcessServiceImpl implements MyProcessService {
  3. @Autowired
  4. private RepositoryService repositoryService;
  5. @Override
  6. public InputStream resourceRead(String id, String resType) throws Exception {
  7. ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
  8. String resourceName = "";
  9. if (resType.equals("image/png")) {
  10. resourceName = processDefinition.getDiagramResourceName();
  11. } else if (resType.equals("text/xml")) {
  12. resourceName = processDefinition.getResourceName();
  13. }
  14. InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
  15. return resourceAsStream;
  16. }
  17. }

运行效果如下:

项目源码仓库

Springboot整合Flowable6.x导出bpmn20的更多相关文章

  1. springboot整合elasticsearch(基于es7.2和官方high level client)

    前言 最近写的一个个人项目(传送门:全终端云书签)中需要用到全文检索功能,目前 mysql,es 都可以做全文检索,mysql 胜在配置方便很快就能搞定上线(参考这里),不考虑上手难度,es 在全文检 ...

  2. SpringBoot 整合 MyCat 实现读写分离

    MyCat一个彻底开源的,面向企业应用开发的大数据库集群.基于阿里开源的Cobar产品而研发.能满足数据库数据大量存储:提高了查询性能.文章介绍如何实现MyCat连接MySQL实现主从分离,并集成Sp ...

  3. Https双向验证与Springboot整合测试-人来人往我只认你

    1 简介 不知不觉Https相关的文章已经写了6篇了,本文将是这个专题的最后一篇,起码近期是最后一篇.前面6篇讲的全都是单向的Https验证,本文将重点介绍一下双向验证.有兴趣的同学可以了解一下之前的 ...

  4. springboot整合xxl-job分布式定时任务【图文完整版】

    一.前言 定时任务有很多种,有一些大的框架也有一些简单的实现. 比如常见的: JDK的Timer和TimerTask Quartz异步任务调度框架 分布式定时任务XXL-JOB Spring Task ...

  5. spring-boot整合mybatis(1)

    sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...

  6. SpringBoot整合Mybatis之项目结构、数据源

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  7. springboot整合mq接收消息队列

    继上篇springboot整合mq发送消息队列 本篇主要在上篇基础上进行activiemq消息队列的接收springboot整合mq发送消息队列 第一步:新建marven项目,配置pom文件 < ...

  8. springboot整合mybaits注解开发

    springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...

  9. SpringBoot整合Redis、ApachSolr和SpringSession

    SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...

  10. SpringBoot整合ElasticSearch实现多版本的兼容

    前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...

随机推荐

  1. IT工具知识-14:如何通过adb操作安卓剪切板?

    1.安装apk 下载地址 2.运行服务(每次重启系统都需要运行一次) adb shell am startservice ca.zgrs.clipper/.ClipboardService 3.设置剪 ...

  2. Q:oracle 日期筛选

    一.oracle where条件日期筛选 两种方法:tochar和todate todate:将字符串按照指定的格式输出,得到的是日期类型. to_date('2019-12-01','yyyy-MM ...

  3. Edge 访问网站强制HTTPS

    edge://net-internals/#hsts 1)開啟Edge chromium 瀏覽器,輸入edge://net-internals/#hsts,開啟設定介面2)找到 Delete doma ...

  4. mysql驱动下载

    下载地址:https://dev.mysql.com/downloads/connector/j/ 下载步骤:Select Operating System: Platform Independent

  5. python&C++区别

    1.类的定义  struct ListNode {  *     int val;  *     ListNode *next;  *     ListNode(int x) : val(x), ne ...

  6. vs2022和wsl2开发和调试c++代码(转载)

    看见一个不错的帖子(知乎) https://zhuanlan.zhihu.com/p/390757559 里面最主要就是要保证wsl里面安装的东西够了,第二就是vs2022已经安装了linux的相关模 ...

  7. Qt打包win应用的流程(转载)

    基本就是命令:windeployqt  目标文件.exe 一定要新开一个文件夹再执行这个命令. 参考网站: https://blog.csdn.net/weixin_39504048/article/ ...

  8. Docker安装:Centos7.6安装Docker

    Docker03:Centos7.6安装Docker 前提条件 内核版本 更新yum 包 卸载旧版本(如果安装过旧版本的话) 安装依赖包 设置yum源(阿里云源) 更新缓存 安装容器 启动并加入开机启 ...

  9. [rk3568][common] 环境搭建

    1. 安装依赖 sudo apt-get install uuid uuid-dev zlib1g-dev liblz-dev liblzo2-2 liblzo2-dev lzop \ git-cor ...

  10. FPGA实现国密算法SM4

    本文基于FPGA实现高速SM4加密与解密,提供开源Verilog RTL设计和可综合工程:https://github.com/cassuto/SM4-FPGA. 本文仅讨论实现细节,不涉及算法原理. ...