activiti如何部署bpmn/bar文件

这篇文章给大家分享的是有关activiti如何部署bpmn/bar文件的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

当配置好工作流,启动工作流。我们的第一步就是配置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)把文件都拷到同一目录下面

activiti如何部署bpmn/bar文件
 

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

diagrams.zip

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

感谢各位的阅读!关于“activiti如何部署bpmn/bar文件”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!