先上流程实例:
BPMN 排他网关(那个X状符号)是指分支的执行路径不可以并行,只能走一条执行路径
ReceiveTask 是一个特殊的任务节点,他不能用taskService.complete驱动,流程执行至此就“中断”了,需外来的消息来驱动流程执行执行
所有有一个标识符。
测试代码如下:
package com.annto;
import static org.junit.Assert.*;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.task.TaskDefinition;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:com/annto/SpringTransactionIntegrationTest-context.xml")
public class MyProcessTest {
@Autowired
private ProcessEngine processEngine;
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
RepositoryService repositoryService;
@Test
public void simpleProcessTest() throws Exception {
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("test/付款申请签字审批流程.bpmn20.xml").deploy();
System.out.println("deploymentId:" + deployment.getId());
// 获取流程定义
ProcessDefinitionEntity processDefEn = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.createProcessDefinitionQuery().processDefinitionName("付款申请签字审批流程").singleResult();
System.out.println("definitionId : " + processDefEn.getId());
processDefEn = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(processDefEn.getId());
assertNotNull(processDefEn.getTaskDefinitions());
assert (processDefEn.getTaskDefinitions().size() > 0);
// 通过流程实例获取
printProcessTasks(processDefEn);
System.out.println("find process def " + processDefEn.getTaskDefinitions());
HashMap map = new HashMap();
map.put("price", 5000);
map.put("this_出纳_财务经理", "herist");
map.put("区域成本", "herist");
map.put("this_出纳_财务经理", "herist");
// 启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("付款申请签字审批流程", map);
System.out.println("Started Process instance id " + processInstance.getProcessInstanceId());
Task task = null;
do {
task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId())
.singleResult();
if (task != null) {
System.out.print("\n--找到-- " + task.getName());
taskService.complete(task.getId());
System.out.print(" 完成 \n" + processInstance.isEnded());
renderStatusImg(processInstance);
}
} while (task != null);
HistoryService historySvc = processEngine.getHistoryService();
HistoricProcessInstance hisProcInst = historySvc.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId())
.singleResult();
System.err.println("ended " + hisProcInst.getEndTime() + " . " + hisProcInst.getEndActivityId());
HistoricActivityInstance hisActInst = historySvc.createHistoricActivityInstanceQuery()
.processInstanceId(processInstance.getProcessInstanceId())
.unfinished()
.singleResult();
System.err.println("alive act " + hisActInst.getActivityName());
renderStatusImg(processInstance);
//signal 驱动节点到完成状态
this.runtimeService.signal(processInstance.getProcessInstanceId());
hisProcInst = historySvc.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId())
.singleResult();
System.err.println("ended " + hisProcInst.getEndTime() + " . " + hisProcInst.getEndActivityId());
}
/**
* 绘制状态图 和 审批活动的状态图
*
* @param processInstance
* @throws IOException
*/
private void renderStatusImg(ProcessInstance processInstance) throws IOException {
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId())
.singleResult();
if (processInstance == null || processInstance.isEnded()) {
System.err.println("流程结束");
return;
}
String definitionId = processInstance.getProcessDefinitionId();
ProcessDefinitionEntity processDefEn = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(definitionId);
// 获得当前活动,并绘制状态图
List<String> activeIds = runtimeService.getActiveActivityIds(processInstance.getId());
String actName = processEngine.getHistoryService().createHistoricActivityInstanceQuery()
.activityId(activeIds.get(0)).singleResult().getActivityName();
InputStream inputStream = ProcessDiagramGenerator.generateDiagram(processDefEn, "png", activeIds);
saveToFile(actName + ".png", inputStream);
}
/**
* 获取流程定义的所有任务,打印之
*/
public void printProcessTasks(ProcessDefinitionEntity processDefEn) throws Exception {
for (String taskKey : processDefEn.getTaskDefinitions().keySet()) {
TaskDefinition taskDef = processDefEn.getTaskDefinitions().get(taskKey);
System.out.println(taskKey + ": " + taskDef.getNameExpression());
}
for (ActivityImpl actvity : processDefEn.getActivities()) {
if(processDefEn.getTaskDefinitions().containsKey(actvity.getId()))
System.out.println( "actvity: " + processDefEn.getTaskDefinitions().get(actvity.getId()).getAssigneeExpression());
else
System.out.println( "actvity: " + actvity.getId());
}
}
public void saveToFile(String fileName, InputStream in) throws IOException {
FileOutputStream fos = null;
BufferedInputStream bis = null;
// URL url = null;
int BUFFER_SIZE = 1024;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
bis = new BufferedInputStream(in);
// //建立文件
fos = new FileOutputStream(fileName);
//
// //保存文件
while ((size = bis.read(buf)) != -1)
fos.write(buf, 0, size);
//
fos.close();
bis.close();
}
}
执行过程的图片:
流程执行结束:
ended Mon Jun 18 21:12:48 CST 2012 . endevent1
应用场景:
在物流ERP中做业务流程整合,有部分流程是历史模块的应用,一个业务执行逻辑可能包括n个人工维护系统数据 + 系统后台的Job处理过程,如:报销流程的最后一个环节为系统的付款操作(需要人工执行批量支付,然后Job负责定时往Oracle ERP中记账,再通过Job把付款状态回写到本系统中来,再继续执行网银的付款,所以短时间内,未能把每个业务操作都整合到流程节点来,所以可以用一个Receive Task节点来表示一个这个付款业务,在这个节点结束之后,流程才真正完成!
- 大小: 15 KB
- 大小: 14.9 KB
- 大小: 14.4 KB
分享到:
相关推荐
压缩包中的 "activiti-5.8" 文件很可能包含了以下关键组成部分: 1. **源代码**:用于理解Activiti的工作原理,开发者可以查看并修改源码以满足特定需求。 2. **文档**:包括用户手册、API参考、开发者指南等,帮助...
Activiti 5.8 支持多种数据库,包括MySQL、Oracle、PostgreSQL等,提供了一种灵活的方式来存储和管理流程实例和相关数据。 8. **社区和文档**: 由于是开源项目,Activiti有一个活跃的社区,提供丰富的文档、示例...
在企业工作流管理系统中,Activiti 是一个广泛使用的开源流程引擎,它允许开发者设计、运行和管理业务流程。本篇文章将深入探讨Activiti中的一个重要概念——排他网关(Exclusive Gateway),也称为独占网关。排他...
Activiti5.8是一款流行的开源工作流引擎,被广泛应用于企业的业务流程管理(BPM)系统中。这个入门资源集包含了丰富的信息,帮助初学者快速掌握Activiti5.8的核心概念、功能和使用方法。下面我们将深入探讨Activiti...
使用 activiti-5.8.zip 和 activiti-designer-5.8.0.zip 文件,你可以搭建一个完整的 Activiti 开发环境。首先,你需要将 activiti-5.8.zip 解压,这会包含 Activiti 引擎的库文件,你可以将它们添加到你的项目依赖...
赠送jar包:activiti-engine-5.21.0.jar; 赠送原API文档:activiti-engine-5.21.0-javadoc.jar; 赠送源代码:activiti-engine-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-engine-5.21.0.pom; 包含...
在JEE(Java Enterprise Edition)环境下整合Activiti5.8是一项关键的任务,它涉及到将流行的开源工作流引擎Activiti与企业级Java应用平台相结合,以实现业务流程自动化。本篇内容将深入探讨如何在JEE环境中集成...
赠送jar包:activiti-crystalball-5.21.0.jar; 赠送原API文档:activiti-crystalball-5.21.0-javadoc.jar; 赠送源代码:activiti-crystalball-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-crystalball-...
赠送jar包:activiti-json-converter-5.21.0.jar; 赠送原API文档:activiti-json-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-json-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
本示例"activiti-demo6-springboot-master.zip"是将Activiti与SpringBoot相结合的简单示例,旨在帮助开发者快速理解如何在SpringBoot环境中配置和使用Activiti。 1. **SpringBoot简介** SpringBoot是Spring框架的...
activiti-spring-boot-starter-basic-6.0.0适配springboot2.1.2
赠送jar包:activiti-json-converter-5.21.0.jar; 赠送原API文档:activiti-json-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-json-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
activiti-bpmn-converter-5.18.0-sources.jar
activiti-spring-boot-starter-7.1.0.M1
赠送jar包:activiti-bpmn-model-5.21.0.jar; 赠送原API文档:activiti-bpmn-model-5.21.0-javadoc.jar; 赠送源代码:activiti-bpmn-model-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-bpmn-model-...
赠送jar包:activiti-common-rest-5.21.0.jar; 赠送原API文档:activiti-common-rest-5.21.0-javadoc.jar; 赠送源代码:activiti-common-rest-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-common-rest-...
赠送jar包:activiti-image-generator-5.21.0.jar; 赠送原API文档:activiti-image-generator-5.21.0-javadoc.jar; 赠送源代码:activiti-image-generator-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
赠送jar包:activiti-image-generator-5.21.0.jar; 赠送原API文档:activiti-image-generator-5.21.0-javadoc.jar; 赠送源代码:activiti-image-generator-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
Activiti 是一个开源的工作流程和业务自动化引擎,它在企业级应用中被广泛用于处理业务流程。Eclipse 插件是开发工具集的一部分,它为 Eclipse IDE 提供了对 Activiti 的集成支持,使得开发者可以在熟悉的环境中设计...
这个“activiti-userguide-5-16”压缩包文件包含了 Activiti 5.16 版本的用户指南,帮助我们深入理解并有效使用这个流程管理工具。 1. **BPMN 2.0 规范**:Business Process Model and Notation 2.0(业务流程模型...