1.啓動流程實例
-
-
@Test
-
public void startProcessInstance() {
-
-
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;
-
-
-
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>();
具體方法:
-
-
processEngine.getExecutionService().setVariable(executionId, name, value);
-
-
processEngine.getExecutionService().setVariables(executionId, variablesMap);
-
-
-
-
processEngine.getTaskService().setVariables(taskId, variablesMap);
-
-
-
processEngine.getExecutionService()
-
.startProcessInstanceByKey(processDefinitionKey, variablesMap);
-
-
processEngine.getTaskService().completeTask(taskId, variablesMap);
3.獲取流程變量
a) 一個獲取流程變量實例
-
-
@Test
-
public void getVariable() {
-
String executionId = "test.140001";
-
String variableName = "請假天數";
-
-
-
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>();
具體方法:
-
-
processEngine.getExecutionService().getVariable(executionId, variableName);
-
-
processEngine.getExecutionService().getVariableNames(executionId);
-
-
processEngine.getExecutionService().getVariables(executionId, variableNames);
-
-
-
processEngine.getTaskService().getVariable(taskId, variableName);
-
-
processEngine.getTaskService().getVariableNames(taskId);
-
-
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