activiti 多方向流程实例(六)

import java.io.InputStream;
import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

/**
 * 多方向流程实例<br>
 * 
 * 
 * select * from act_re_deployment ; # 部署对象表<br>
 * 
 * select * from act_re_procdef; # 流程定义表<br>
 * select * from act_ge_bytearray; #资源文件表<br>
 * select * from act_ge_property; #<br>
 * 
 * select * from act_ru_execution; # 正在执行的对象<br>
 * select * from act_hi_procinst; #流程实例历史表<br>
 * select * from act_ru_task; # 正在执行的任务表(只有节点是UserTask时,该表中才存在数据)<br>
 * 
 * select * from act_hi_taskinst; #任务历史表<br>
 * 
 * select * from act_ru_variable; #变量表<br>
 * 
 * @author ZHEN.L
 * 
 */
public class SequenceFlowTest {

	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

	/**
	 * 部署流程定义
	 */
	@Test
	public void deloymentProcessDefinition() {
		InputStream bpmn = this.getClass().getResourceAsStream(
				"diagrams/sequenceFlow.bpmn");
		InputStream png = this.getClass().getResourceAsStream(
				"diagrams/sequenceFlow.png");
		Deployment deployment = processEngine.getRepositoryService()
				.createDeployment().addInputStream("sequenceFlow.bpmn", bpmn)
				.addInputStream("sequenceFlow.png", png).name("多箭头流程实例")
				.deploy();
		System.out.println(deployment.getId() + "; " + deployment.getName());
	}

	/**
	 * 启动流程实例
	 */
	@Test
	public void startProcessInstance() {
		String processDefinitionKey = "sequenceFlow";
		ProcessInstance p = processEngine.getRuntimeService()
				.startProcessInstanceByKey(processDefinitionKey); // 根据key启动,启动最新版本
		System.out.println(p.getId() + "; " + p.getProcessDefinitionId());
	}

	/**
	 * 查询任务
	 */
	@Test
	public void findTask() {
		String assignee = "向问天";
//		String assignee = "任我行";
		List<Task> list = processEngine.getTaskService().createTaskQuery()
				.taskAssignee(assignee).list();
		if (list != null && list.size() > 0) {
			for (Task t : list) {
				System.out.println(t.getId() + "; " + t.getName() + "; "
						+ t.getAssignee() + "; " + t.getProcessInstanceId());
			}
		}
	}
	
	/**
	 * 完成任务
	 */
	@Test
	public void completeTask(){
		String taskId = "2706";
		TaskService taskService = processEngine.getTaskService();
		taskService.setVariable(taskId, "money", 50);
		taskService.complete(taskId);
	}
}

你可能感兴趣的:(activiti 多方向流程实例(六))