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

本人博客开始迁移,博客整个架构自己搭建及编码 http://www.cookqq.com/listBlog.action 

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

 其实一切很简单...


 


 






转载于:https://my.oschina.net/winHerson/blog/179022

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值