JBPM学习(五):流程变量
2024-10-13 09:13:47
1.启动流程实例
// 启动流程实例
@Test
public void startProcessInstance() {
// 使用指定key的最新版本的流程定义启动流程实例
ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
System.out.println("processInstanceId=" + pi.getId());
}
2.设置流程变量
a) 一个设置流程变量实例
//设置流程变量
@Test
public void setVariable() {
String executionId = "test.140001";
String name = "请假天数";
Integer value = 3; //将name为"请假天数",value=3的流程变量设置到executionId为test.140001的执行对象上
processEngine.getExecutionService().setVariable(executionId, name, value);
}b) 所有设置流程变量方法
用到变量的类型:
Object value = "";
String executionId = "";
String taskId = "";
String name = "";
String processDefinitionKey = "";
String variableName = "";
Set<String> variableNames = new HashSet<String>();
Map<String, Object> variablesMap = new HashMap<String, Object>();具体方法:
// 根据Execution设置一个流程变量
processEngine.getExecutionService().setVariable(executionId, name, value);
// 根据Execution设置多个流程变量(需要先把流程变量放到一个Map中)
processEngine.getExecutionService().setVariables(executionId, variablesMap); // 根据Task设置多个流程变量(需要先把流程变量放到一个Map中,通过Task方法,它会先找到它所属的Execution然后设置流程变量)
processEngine.getTaskService().setVariables(taskId, variablesMap); // 使用指定key的最新版本的流程定义启动流程实例,并设置一些流程变量
processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey, variablesMap);
// 办理完指定的任务,并设置一些流程变量
processEngine.getTaskService().completeTask(taskId, variablesMap);
3.获取流程变量
a) 一个获取流程变量实例
//获取流程变量
@Test
public void getVariable() {
String executionId = "test.140001";
String variableName = "请假天数"; //从executionId为test.140001的执行对象上取出流程变量名为"请假天数"的流程变量的value
Integer value = (Integer) processEngine.getExecutionService().getVariable(executionId, variableName);
System.out.println(variableName + " = " + value);
}
b) 所有获取流程变量方法
用到变量的类型:
String executionId = "";
String taskId = "";
String variableName = "";
Set<String> variableNames = new HashSet<String>();具体方法:
// 根据Execution获取指定名称的一个流程变量
processEngine.getExecutionService().getVariable(executionId, variableName);
// 根据Execution获取所有流程变量的名称
processEngine.getExecutionService().getVariableNames(executionId);
// 根据Execution获取指定名称的所有流程变量
processEngine.getExecutionService().getVariables(executionId, variableNames); // 根据Task获取指定名称的一个流程变量
processEngine.getTaskService().getVariable(taskId, variableName);
// 根据Task获取所有流程变量的名称
processEngine.getTaskService().getVariableNames(taskId);
// 根据Task获取指定名称的所有流程变量
processEngine.getTaskService().getVariables(taskId, variableNames);
4.流程变量所支持的值的类型(jBPM User Guide,7.2. Variable types)
jBPM supports following Java types as process variables:
- java.lang.String
- java.lang.Long
- java.lang.Double
- java.util.Date
- java.lang.Boolean
- java.lang.Character
- java.lang.Byte
- java.lang.Short
- java.lang.Integer
- java.lang.Float
- byte[] (byte array)
- char[] (char array)
- hibernate entity with a long id
- hibernate entity with a string id
- serializable
For persistence of these variable, the type of the variable is checked in the order of this list. The first match will determine how the variable is stored.
最新文章
- 使用Object类型的多态引用是会付出代价的
- 【001:Tomcat搭建简单文件服务器】
- iOS开发笔记11:表单键盘遮挡、浮点数价格格式化显示、省市区选择器、View Debugging
- 如何从List<;T>;中筛选符合条件的数据的集合或个数
- IO的阻塞、非阻塞、同步、异步
- jquery mobile将页面内容当成弹框进行显示
- 4.2、Libgdx每个模块概述
- 分析Sizzle引擎 - 词法解析
- PHP 判断几秒前,几分钟,几小时前
- Qt 地址薄 (一) 界面设计
- replace into 浅析之一
- JavaScript深入之作用域链
- Java Web开发中的乱码问题
- day 34 线程队列 线程池 协程 Greenlet \Gevent 模块
- C#微信接口之推送模板消息功能示例
- 禁止requests请求https的提示InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more
- 【百度统计】设置页面元素点击事件转化pv、uv
- scss语法
- 第1章 1.9计算机网络概述--OSI参考模型和网络安全
- .net core webapi 定义多版本与 Swagger 的文档输出
热门文章
- WordPress 前端用户投稿插件 Frontend Publishing
- 网络编程(二)NSURLSessionConfiguration
- 152. Maximum Product Subarray
- [Quick-x]制作新手引导高亮区域方法之一:混合模式
- 【HDOJ】1225 Football Score
- bzoj1007
- [备忘]WCF中使用MessageContract的一些注意点
- HDU5654xiaoxin and his watermelon candy 离线+树状数组
- [摘]selenium-ide命令
- Fiddler On Linux