activiti--部署bpmn/bar文件详解
cookqq ›博客列表 ›activiti

activiti--部署bpmn/bar文件详解

2013-11-26 13:29:19.0|分类: activiti|浏览量: 2877

摘要: Everything that is related to 'static' data (such as process definitions) are acc...

Everything that is related to 'static' data (such as process definitions) are accessed through the RepositoryService. Conceptually, every such static piece of data is content of the 'repository' of the Activiti engine.

当配置好工作流,启动工作流。我们的第一步就是配置bpmn、bar、bpmn20.xml等文件。

部署bpmn的简单代码:

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
repositoryService.createDeployment()
  .addClasspathResource("org/activiti/test/AssigneeUserAndGroup.bpmn")
  .deploy();

简单解释:创建一个部署引擎DeploymentBuilder,然后通过addClasspathResource把文件路径设置进去(最起码activiti需要知道部署哪一个文件啊),然后启动部署方法deploy()。

addClasspathResource()方法其实就是把文件读入到一个输入流中,然后调用addInputStream()方法。addInputStream()主要是创建一个资源类,然后设置名称,字节,并且把这个资源给deployment实体

public DeploymentBuilder addInputStream(String resourceName, InputStream inputStream) {
    if (inputStream==null) {
      throw new ActivitiIllegalArgumentException("inputStream for resource '"+resourceName+"' is null");
    }
    byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);
    ResourceEntity resource = new ResourceEntity();
    resource.setName(resourceName);
    resource.setBytes(bytes);
    deployment.addResource(resource);
    return this;
  }

  public DeploymentBuilder addClasspathResource(String resource) {
    InputStream inputStream = ReflectUtil.getResourceAsStream(resource);
    if (inputStream==null) {
      throw new ActivitiIllegalArgumentException("resource '"+resource+"' not found");
    }
    return addInputStream(resource, inputStream);
  }



所以也可以直接调用addInputStream(String resourceName, InputStream inputStream)进行文件的部署。

注意:单独部署一个bpmn文件,png会在底层BpmnDeployer中分解出来,并且保存到数据库中。

如果一个部署中涉及到多个文件,我们可以打包一起部署,例如方法addZipInputStream(ZipInputStream zipInputStream),其实addZipInputStream会把这个包下面的所有文件逐一找出来,然后创建资源类,设置到deployment实体中。

public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) {
    try {
      ZipEntry entry = zipInputStream.getNextEntry();
      while (entry != null) {
        if (!entry.isDirectory()) {
          String entryName = entry.getName();
          byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName);
          ResourceEntity resource = new ResourceEntity();
          resource.setName(entryName);
          resource.setBytes(bytes);
          deployment.addResource(resource);
        }
        entry = zipInputStream.getNextEntry();
      }
    } catch (Exception e) {
      throw new ActivitiException("problem reading zip input stream", e);
    }
    return this;
  }



下面说说.bar文件怎么打包:

(1)把文件都拷到同一目录下面


(2)对diagrams文件夹进行打包

diagrams.zip

(3)修改文件的扩展名diagrams.bar

 其实一切很简单...








一键分享文章

分类列表

  • • struts源码分析
  • • flink
  • • struts
  • • redis
  • • kafka
  • • ubuntu
  • • zookeeper
  • • hadoop
  • • activiti
  • • linux
  • • 成长
  • • NIO
  • • 关键词提取
  • • mysql
  • • android studio
  • • zabbix
  • • 云计算
  • • mahout
  • • jmeter
  • • hive
  • • ActiveMQ
  • • lucene
  • • MongoDB
  • • netty
  • • flume
  • • 我遇到的问题
  • • GRUB
  • • nginx
  • • 大家好的文章
  • • android
  • • tomcat
  • • Python
  • • luke
  • • android源码编译
  • • 安全
  • • MPAndroidChart
  • • swing
  • • POI
  • • powerdesigner
  • • jquery
  • • html
  • • java
  • • eclipse
  • • shell
  • • jvm
  • • highcharts
  • • 设计模式
  • • 列式数据库
  • • spring cloud
  • • docker+node.js+zookeeper构建微服务
版权所有 cookqq 感谢访问 支持开源 京ICP备15030920号
CopyRight 2015-2018 cookqq.com All Right Reserved.