1.启动流程实例
1
2
3
4
5
6
7
|
// 启动流程实例
@Test
public
void startProcessInstance() { // 使用指定key的最新版本的流程定义启动流程实例 ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey( “test” ); System.out.println( “processInstanceId=” + pi.getId());
}
|
2.设置流程变量
a) 一个设置流程变量实例
12345678910 //设置流程变量@Testpublic
void
setVariable() {
String executionId =
“test.140001”
;
String name =
“请假天数”
;
Integer value =
3
;
//将name为”请假天数”,value=3的流程变量设置到executionId为test.140001的执行对象上
processEngine.getExecutionService().setVariable(executionId, name, value);}b) 所有设置流程变量方法
用到变量的类型:
12345678 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>();具体方法:
123456789101112 // 根据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) 一个获取流程变量实例
12345678910 //获取流程变量@Testpublic
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) 所有获取流程变量方法
用到变量的类型:
1234 String executionId =
“”
;String taskId =
“”
;String variableName =
“”
;Set<String> variableNames =
new
HashSet<String>();具体方法:
12345678910111213 // 根据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.
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/12132.html