package com.zsj.test.jbpm; import java.util.List; import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.task.Task; import org.junit.BeforeClass; import org.junit.Test; /** * 基本步骤 * 一 构建流程 * 二 部署流程 * 三 生成流程实例 * 四 处理任务以及流程扭转 * @author hadoop * */ public class TestJbpm { static ProcessEngine processEngine = null; @BeforeClass public static void setUpBeforeClass() throws Exception { processEngine = Configuration.getProcessEngine(); } /** * 部署流程 */ @Test public void deploy() { try { RepositoryService repositoryService = processEngine .getRepositoryService(); repositoryService.createDeployment() .addResourceFromClasspath("test.jpdl.xml") .addResourceFromClasspath("test.png").deploy(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 启动流程实例 */ @Test public void createInstance() { // ProcessEngine processEngine = Configuration.getProcessEngine(); ExecutionService executionService = processEngine.getExecutionService(); ProcessInstance processInstance = executionService .startProcessInstanceByKey("test"); System.out.println(processInstance.getId()); } /** * 获取指定人员要处理的任务 */ @Test public void getTask() { TaskService taskService = processEngine.getTaskService(); List<Task> tasks = taskService.findPersonalTasks("李四"); for (int i = 0; i < tasks.size(); i++) { System.out.println("who " + tasks.get(i).getAssignee() + "taskId" + tasks.get(i).getId()); System.out.println("节点名称 " + tasks.get(i).getActivityName()); } } /** * 获取当前节点名称 */ @Test public void getCurrentActivity() { ExecutionService executionService = processEngine.getExecutionService(); String name = executionService.createProcessInstanceQuery() .processInstanceId("test.40001").uniqueResult() .findActiveActivityNames().toString(); System.out.println(name); } /** * 完成任务推进 */ @Test public void completeTask() { TaskService taskService = processEngine.getTaskService(); taskService.completeTask("40001"); } }
设置流程变量
public void createInstance() { // TODO Auto-generated method stub super.startUp(); Map<String, String> map = new HashMap<String, String>(); map.put("id", "000001"); map.put("name", "zuoshunjian"); ProcessInstance processInstance = this.executionService .startProcessInstanceByKey("test", map); super.print("流程实例ID", processInstance.getId()); }获取流程变量
/** * 获取流程变量 */ @Test public void getVariable() { super.startUp(); String idString = this.executionService.getVariable("test.10001", "id") .toString(); super.print("流程实例变量ID", idString); }修改流程变量
public void updateVariable() { super.startUp(); this.executionService.setVariable("test.10001", "id", "00002"); String idString = this.executionService.getVariable("test.10001", "id") .toString(); System.out.println(idString); }