首页 > 其他分享 >Activiti流程定义模型管理

Activiti流程定义模型管理

时间:2023-02-24 11:12:36浏览次数:41  
标签:定义 Activiti 流程 System println new repositoryService 模型 out

Activiti流程定义模型管理

上文链接:https://www.cnblogs.com/wangshaoyun/p/16356115.html

查询所有流程模型

@Autowired
RepositoryService repositoryService;
    
@Test
public void modelList() {
    //1,模型查询对象
    ModelQuery query = repositoryService.createModelQuery();
    List<Model> list = query.orderByCreateTime()
            .desc()
            .list();
    list.forEach(item -> {
        System.out.println("模型id:" + item.getId());
        System.out.println("模型名称:" + item.getName());
        System.out.println("模型描述:" + item.getMetaInfo());
        System.out.println("模型标识key:" + item.getKey());
        System.out.println("模型版本号:" + item.getVersion());
    });
}

删除流程模型

@Autowired
RepositoryService repositoryService;
​
@Test
public void deleteModel() {
    String modelId = "841ed641-b24e-11ed-bc00-38f3abe10e1d";
    repositoryService.deleteModel(modelId);
    System.out.println("删除成功!!");
}

导出下载zip压缩包

@Autowired
RepositoryService repositoryService;
@Autowired
ObjectMapper objectMapper;
​
@Test
public void exportZip() throws IOException {
    //1,查询模型基本信息
    String modelId = "1a5bbc00-b25f-11ed-8cfb-38f3abe10e1d";
    Model model = repositoryService.getModel(modelId);
    if (null != model) {
        //2,查询流程定义模型的json字节码
        byte[] bpmnJsonBytes = repositoryService.getModelEditorSource(modelId);
        //2.1,将json字节码转换为xml字节码
        byte[] xmlBytes = bpmnJsonXmlForBytes(bpmnJsonBytes);
        if (null == xmlBytes) {
            System.out.println("数据模型数据为空-请先设计流程定义模型,再导出");
        } else {
            String zipName = model.getName() + "." + model.getKey() + ".zip";
            File file = new File("C:/study/activiti/" + zipName);
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
            //将xml添加压缩包中(指定xml文件名:请假流程.bpmn20.xml)
            zipOutputStream.putNextEntry(new ZipEntry(model.getName() + ".bpmn20.xml"));
            zipOutputStream.write(xmlBytes);
            //3,查询流程定义模型的图片字节码
            byte[] pngBytes = repositoryService.getModelEditorSource(modelId);
            if (null != pngBytes) {
                //图片文件名
                zipOutputStream.putNextEntry(new ZipEntry(model.getName() + "." + model.getKey() + ".png"));
                zipOutputStream.write(pngBytes);
            }
            //4,以压缩包的方式导出流程定义模型文件
            zipOutputStream.closeEntry();
            zipOutputStream.close();
            System.out.println("导出成功!!");
        }
    } else {
        System.out.println("流程模型不存在!!");
    }
}
​
private byte[] bpmnJsonXmlForBytes(byte[] jsonBytes) throws IOException {
    if (null == jsonBytes) {
        return null;
    }
    
    //json字节码转成 BpmnModel 对象
    JsonNode jsonNode = objectMapper.readTree(jsonBytes);
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(jsonNode);
    if (bpmnModel.getProcesses().size() == 0) {
       return null;
    }
    //BpmnModel 对象转为xml字节码
    return new BpmnXMLConverter().convertToXML(bpmnModel);
}

导出下载xml文件

@Autowired
RepositoryService repositoryService;
@Autowired
ObjectMapper objectMapper;
​
@Test
public void exportXml() throws IOException {
    //1,查询模型基本信息
    String modelId = "1a5bbc00-b25f-11ed-8cfb-38f3abe10e1d";
    byte[] bytes = repositoryService.getModelEditorSource(modelId);
    String fileName = null;
    ByteArrayInputStream inputStream = null;
    if (null != bytes) {
        //json字节码转成 BpmnModel 对象
        JsonNode jsonNode = objectMapper.readTree(bytes);
        BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(jsonNode);
        if (bpmnModel.getProcesses().size() > 0) {
            byte[] xmlBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
            inputStream = new ByteArrayInputStream(xmlBytes);
            fileName = StringUtils.isBlank(bpmnModel.getMainProcess().getName())
                    ? bpmnModel.getMainProcess().getName() : bpmnModel.getMainProcess().getId();
        }
    }
​
    if (null == fileName) {
        fileName = "模型数据为空,请先设计流程,再导出";
        inputStream = new ByteArrayInputStream(fileName.getBytes(StandardCharsets.UTF_8));
    }
​
    FileOutputStream outputStream = new FileOutputStream(new File("C:/study/activiti/" + fileName + "bpmn20.xml"));
    IOUtils.copy(inputStream, outputStream);
    outputStream.close();
    inputStream.close();
    System.out.println("导出xml成功!");
}

标签:定义,Activiti,流程,System,println,new,repositoryService,模型,out
From: https://www.cnblogs.com/wangshaoyun/p/17150560.html

相关文章

  • JSON_概念与JSON_语法_定义
    JSON_概念1.概念:JavaScriptObjectNotationJavaScript对象表示法Personp=newPerson();p.setName("张三"); p.setA......
  • 禅道表定义
    bug:zt_bugbug表用例zt_case用例表zt_casestep用例步骤禅道的查询特殊字用英文的`,~下面的select*fromzt_casestepwhere`case`='161'zt_testsuilt ......
  • el-select change自定义参数
    只有带value参数的默认方法 <el-table-column            label="eleName"            width="180"><templa......
  • 自定义注解+反射机制
    @Target用来表示注解作用范围,超过这个作用范围,编译的时候就会报错。@Target:注解的作用目标@Target(ElementType.TYPE)——接口、类、枚举、注解@Target(ElementType.FIE......
  • 软件架构的定义与分类
    软件架构(SoftwareArchitecture)是一系列相关的抽象模式,用于指导大型软件系统各个方面的设计。软件架构是一个系统的草图。通俗地来讲,技术架构就是对软件系统各个维度进行不......
  • 49.接口的定义
    1.抽象基类和纯虚函数在设计时,常常希望基类仅仅作为其派生类的一个接口。这就是说,仅想对基类进行向上类型转换,使用它的接口,而不希望用户实际的创建一个基类的对象。同......
  • Nano SIM 卡引脚定义//京鸿通信科技(深圳)有限公司 www.kyohoon.com 15507589165
    前言想做个接口板,将第三方的4G模块接进来.先查了下SIM卡的引脚定义,这样就可以将硬件接口先定下来,板子可以分开作。  作为接口板,只需要引出以下引脚:电源接口VCC/GN......
  • MySQL的执行流程
    MySQL架构MySQL分为Sever层和存储引擎层Server层负责建立连接、分析和执行SQL连接器、查询缓存、解析器、预处理器、优化器、执行器内置函数:日期、事件、数学、加密......
  • TCGA代码分析流程 - 3.3 生存模型:Lasso回归
    LASSO回归什么是Lasso回归Tibshirani(1996) 引入了LASSO (LeastAbsoluteShrinkageandSelectionOperator)模型,用于参数的选择和收缩。当我们分析大数据时,这个模型......
  • iOS上架之使用appuploader创建构建版本的流程
    1、打开appuploader软件2、登录苹果开发者账号3、点击appuploader右上角的设置编辑切换为居中添加图片注释,不超过140字(可选)4、设置苹果app上传密码5、开始上传ipa的安装包......