jbpm中的流程变量

package com.njupt.jbpm;

import java.util.Map;
import java.util.Set;

import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.TaskService;
import org.junit.Test;

public class ProcessVariableTest {

	private ProcessEngine processEngine = Configuration.getProcessEngine();
	private ExecutionService executionService = processEngine.getExecutionService();
	private TaskService taskService = processEngine.getTaskService();

	// 启动流程实例
	@Test
	public void testStartProcessInstance() throws Exception {
		ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
		System.out.println("id=" + pi.getId() + ", processDefinitionId=" + pi.getProcessDefinitionId());
	}

	// 设置流程变量
	@Test
	public void testSetVariable() throws Exception {
		String executionId = "test.110001";
		// processEngine.getExecutionService().setVariable(executionId, "请假天数", new Integer(3));

		Form form = new Form();
		form.setId(1L); // 通过设置id让其与数据库中的id为1的记录对应
		form.setTitle("张三要请假3天");
		processEngine.getExecutionService().setVariable(executionId, "form", form);

		// 通过Execution设置流程变量
		// executionService.setVariable(executionId, name, value); // 设置一个
		// executionService.setVariables(executionId, variablesMap); // 设置多个

		// 通过Task设置流程变量
		// taskService.setVariables(taskId, variablesMap); // 设置多个

		// 在启动流程实例时,同时设置一些流程变量
		// executionService.startProcessInstanceByKey(key);
		// executionService.startProcessInstanceByKey(key, variablesMap);

		// 在完成任务时,同时设置一些流程变量
		// taskService.completeTask(taskId);
		// taskService.completeTask(taskId, variablesMap);
	}

	// 获取流程变量
	@Test
	public void testGetVariable() throws Exception {
		String executionId = "test.110001";
		// Integer days = (Integer) processEngine.getExecutionService().getVariable(executionId, "请假天数");
		// System.out.println("请假天数 = " + days);

		Form form = (Form) processEngine.getExecutionService().getVariable(executionId, "form");
		System.out.println(form);

		// // 通过Execution获取流程变量
		// Object value = executionService.getVariable(executionId, variableName); // 获取一个
		// Set<String> namesSet = executionService.getVariableNames(executionId); // 获取所有变量的名称
		// Map<String, Object> map = executionService.getVariables(executionId, variableNamesSet); // 获取多个

		// 通过Task获取流程变量
		// taskService.getVariable(taskId, variableName);
		// taskService.getVariableNames(taskId);
		// taskService.getVariables(taskId, variableNames);
	}
}

你可能感兴趣的:(jbpm,流程变量)