Activiti工作流的流程部署和删除流程部署
流程部署代码:
/**
* 部署流程
*/
public class ActivitiTest { RepositoryService repositoryService; RuntimeService runtimeService; @Before
public void setUp() throws Exception {
//获取流程引擎,配置文件必须命名为activiti.cfg.xml
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取流程定义
repositoryService = processEngine.getRepositoryService();
//获取运行时
runtimeService = processEngine.getRuntimeService();
} /**
* 第一种部署流程方式
* select * from act_re_deployment;-- 部署信息表
* select * from act_ge_bytearray;-- 二进制数据表
* select * from act_re_procdef;-- 流程定义数据表
* 如果key相同,再次部署会在原有的key的流程上做版本的累加,版本号+1
* 如果key不同,再次部署,版本号从1开始
*/
@Test
public void deployActiviti(){
//创建部署对象
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
//加载流程的配置文件和图片
deploymentBuilder.addClasspathResource("diagrams/activiti.bpmn")
.name("申请事假")
.category("申请")
.addClasspathResource("diagrams/activiti.png");
//部署流程
deploymentBuilder.deploy();
} /**
* 第二种流程部署方式,使用zip压缩包方式部署流程
*/
@Test
public void deployActivitiWithZip(){
//创建部署对象
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("diagrams/activiti.zip");
ZipInputStream zipInputStream = new ZipInputStream(in); //加载流程的配置文件和图片
deploymentBuilder.addZipInputStream(zipInputStream)
.name("申请事假")
.category("申请");
//部署流程
deploymentBuilder.deploy();
} /**
* 删除流程部署
*/
@Test
public void deleteActivitiDeploy(){
//如果流程已经启动,那么删除会报错
//repositoryService.deleteDeployment("201");相当于deleteDeployment("201", false)
//级联删除:是:true 否:false
//false:有正在运行流程是删除会报错
//true:有正在运行流程也会被删除
repositoryService.deleteDeployment("201", true);
} }
执行deployActiviti:
insert into ACT_RE_DEPLOYMENT(ID_, NAME_, CATEGORY_, DEPLOY_TIME_) values(?, ?, ?, ?) >
Parameters: 1(String), 申请事假(String), 申请(String), 2017-02-17 10:21:56.156(Timestamp)> insert into ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_, GENERATED_) values (?, 1, ?, ?, ?, ?) >
Parameters: 2(String), diagrams/activiti.bpmn(String), java.io.ByteArrayInputStream@940b84(ByteArrayInputStream), 1(String), false(Boolean)> insert into ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_, GENERATED_) values (?, 1, ?, ?, ?, ?) >
Parameters: 3(String), diagrams/activiti.png(String), java.io.ByteArrayInputStream@1a5ec6c(ByteArrayInputStream), 1(String), false(Boolean)> insert into ACT_RE_PROCDEF(ID_, REV_, CATEGORY_, NAME_, KEY_, VERSION_, DEPLOYMENT_ID_, RESOURCE_NAME_, DGRM_RESOURCE_NAME_, DESCRIPTION_, HAS_START_FORM_KEY_, SUSPENSION_STATE_) values (?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) >
Parameters: activiti_leave:1:4(String), http://www.activiti.org/test(String), 请假(String), activiti_leave(String), 1(Integer), 1(String), diagrams/activiti.bpmn(String), diagrams/activiti.png(String), null, false(Boolean), 1(Integer)>
部署流程操作的表:
act_re_deployment --部署信息表
act_ge_bytearray --二进制数据表
act_re_procdef --流程定义数据表