流程定义和部署管理——部署

一、process-list.jsp页面中有部署的入口


提示:点击xml或者png链接可以查看具体内容!
部署流程

其中主要是两个:

/workflow/deploy,部署新流程;

/workflow/redeploy/all,重新部署所有流程;


二、部署新流程

上传zip、bar、bpmn、bpmn20.xml,然后部署新流程,部署完之后返回process-list页面。

ActivitiController中有

@RequestMapping(value = "/deploy")
    public String deploy(@Value("#{APP_PROPERTIES['export.diagram.path']}") String exportDir, @RequestParam(value = "file", required = false) MultipartFile file) {

        String fileName = file.getOriginalFilename();

        try {
            InputStream fileInputStream = file.getInputStream();
            Deployment deployment = null;

            String extension = FilenameUtils.getExtension(fileName);
            if (extension.equals("zip") || extension.equals("bar")) {
                ZipInputStream zip = new ZipInputStream(fileInputStream);
                deployment = repositoryService.createDeployment().addZipInputStream(zip).deploy();
            } else {
                deployment = repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy();
            }

            List list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();

            for (ProcessDefinition processDefinition : list) {
                WorkflowUtils.exportDiagramToFile(repositoryService, processDefinition, exportDir);
            }

        } catch (Exception e) {
            logger.error("error on deploy process, because of file input stream", e);
        }

        return "redirect:/workflow/process-list";
    }

要点:

1、根据上传文件后缀调用不同的部署方法:

zip和bar调用

repositoryService.createDeployment().addZipInputStream(zip).deploy();

bpmn和bpmn20.xml调用

repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy();


deploy()方法都返回Deployment接口实例,这个接口提供方法如下:

public abstract interface Deployment
{
  public abstract String getId();
  
  public abstract String getName();
  
  public abstract Date getDeploymentTime();
  
  public abstract String getCategory();
  
  public abstract String getTenantId();
}


2、根据部署ID查流程定义,然后导出图片文件到硬盘,简化之后代码调用如下:

List list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
 for (ProcessDefinition processDefinition : list) {
    InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
 }


三、部署全部流程

部署四个流程,读deployments目录下的四个bar包,然后调用deploy()方法部署流程,导出流程图片,简化后代码如下:

 
  
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
ResourceLoader resourceLoader = new DefaultResourceLoader();
String[] processKeys = {"leave", "leave-dynamic-from", "leave-formkey", "dispatch"};
for (String loopProcessKey : processKeys) {
    String classpathResourceUrl = "classpath:/deployments/" + processKey + ".bar";
    Resource resource = resourceLoader.getResource(classpathResourceUrl);
        InputStream inputStream = resource.getInputStream();
        if (inputStream != null) {
            ZipInputStream zis = new ZipInputStream(inputStream);
            Deployment deployment = repositoryService.createDeployment().addZipInputStream(zis).deploy();

            // export diagram
            List list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
            for (ProcessDefinition processDefinition : list) {
               InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
            } 
         }
}

下面用一个类图来说明流程定义列表和部署遇到的接口和类,主要是围绕着RepositoryService展开的:

流程定义和部署管理——部署_第1张图片

你可能感兴趣的:(activiti工作流引擎)