Activiti7 zip部署,查询及其删除
阅读原文时间:2023年07月10日阅读:2

zip部署

package com.itheima.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
* 使用ZIP压缩包部署
*/
public class ActivitiZipDeployment {

public static void main(String\[\] args) throws IOException {

    ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();

    RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();

    InputStream resourceAsStream = ActivitiZipDeployment.class.getClassLoader().getResourceAsStream("pic.zip");

    ZipInputStream zipInputStream = new ZipInputStream(resourceAsStream);

    Deployment deploy = repositoryService.createDeployment().addZipInputStream(zipInputStream).name("请假申请流程").deploy();

    zipInputStream.close();

    resourceAsStream.close();

    System.out.println("流程部署ID:" + deploy.getId());  
    System.out.println("流程部署名称:" + deploy.getName());

}

}

查询

/**
* 查询流程定义
*/
@Test
public void queryProceccDefinition() {
// 定义流程KEY
String processDefinitionKey = "holiday";
// 获取RepositoryService
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
// 创建流程定义查询
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
// 查询返回列表
List list = processDefinitionQuery.processDefinitionKey(processDefinitionKey).orderByProcessDefinitionVersion().desc().list();
// 打印输出
list.forEach(processDefinition -> {
System.out.println("流程部署ID:" + processDefinition.getDeploymentId());
System.out.println("流程定义ID:" + processDefinition.getId());
System.out.println("流程定义名称:" + processDefinition.getName());
System.out.println("流程定义key:" + processDefinition.getKey());
System.out.println("流程定义版本:" + processDefinition.getVersion());
});
}

删除

@Test
public void deleteDeployment(){
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
// 部署流程ID
String deploymentId = "1";
// 删除流程定义,如果该流程定义已有流程实例启动则删除报错
// repositoryService.deleteDeployment(deploymentId);
// 设置true 级联删除流程定义,即使该流程有流程实例启动也可以删除,设置为false非级别删除方式,如果流程
repositoryService.deleteDeployment(deploymentId, true);

}

作者:彼岸舞

时间:2020\08\31

内容关于:Activiti工作流

本文来源于网络,只做技术分享,一概不负任何责任