- <?xml version="1.0" encoding="UTF-8"?>
- <process-definition
- xmlns="urn:jbpm.org:jpdl-3.2" name="testcountersign">
- <start-state name="start">
- <transition to="会签任务节点"></transition>
- </start-state>
- <task-node name="会签任务节点">
- <task name="会签任务"> </task>
- <event type="node-enter">
- <action class="com.bf.CountersignAction"></action>
- </event>
- <transition name="" to="end1"></transition>
- </task-node>
- <end-state name="end1"></end-state>
- </process-definition>
- package com.bf;
- import java.util.List;
- import org.jbpm.graph.def.ActionHandler;
- import org.jbpm.graph.exe.ExecutionContext;
- import org.jbpm.graph.exe.Token;
- import org.jbpm.graph.node.TaskNode;
- import org.jbpm.taskmgmt.def.Task;
- import org.jbpm.taskmgmt.exe.TaskInstance;
- import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
- //设置参与者
- public class CountersignAction implements ActionHandler {
- public void execute(ExecutionContext executeContext) throws Exception {
- System.out.println("aaaaa");
- Token token = executeContext.getToken();
- TaskMgmtInstance tmi = executeContext.getTaskMgmtInstance();
- TaskNode taskNode = (TaskNode)executeContext.getNode();
- Task task = taskNode.getTask("会签任务");
- //从流程上下文里获取会签人列表
- List<String> ls = (List<String>)executeContext.getVariable("actorList");
- for(String actorId : ls) {
- TaskInstance ti = tmi.createTaskInstance(task, token);
- ti.setActorId(actorId);
- }
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <process-definition
- xmlns="urn:jbpm.org:jpdl-3.2" name="ordercountersign">
- <start-state name="start">
- <transition name="" to="传阅节点"></transition>
- </start-state>
- <task-node name="传阅节点" signal="never">
- <task name="传阅任务">
- <assignment class="com.bf.OrderCountersignAssignment"></assignment>
- </task>
- <transition name="" to="end1"></transition>
- </task-node>
- <end-state name="end1"></end-state>
- </process-definition>
- package com.test;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import javax.transaction.Transaction;
- import org.apache.commons.collections.map.HashedMap;
- import org.jbpm.JbpmConfiguration;
- import org.jbpm.JbpmContext;
- import org.jbpm.context.exe.ContextInstance;
- import org.jbpm.db.GraphSession;
- import org.jbpm.graph.def.ProcessDefinition;
- import org.jbpm.graph.def.Transition;
- import org.jbpm.graph.exe.ProcessInstance;
- import org.jbpm.graph.exe.Token;
- import org.jbpm.taskmgmt.exe.TaskInstance;
- public class Test01 {
- public static void main(String[] args)throws Exception {
- //newProcessInstance();
- endTask("李四");
- }
- // 创建流程实例
- public static void newProcessInstance() throws Exception {
- JbpmConfiguration config = JbpmConfiguration.getInstance();
- JbpmContext context = config.createJbpmContext();
- GraphSession gs = context.getGraphSession();
- ProcessDefinition pd = gs
- .findLatestProcessDefinition("ordercountersign");
- ProcessInstance pi = new ProcessInstance(pd);
- // 创建放传阅人信息列表
- List ls = new LinkedList();
- Map map1 = new HashedMap();
- // 传阅人ID
- map1.put("actorId", "张三");
- // 是否创建了任务实例
- map1.put("taskCreate", "0");
- ls.add(map1);
- Map map2 = new HashedMap();
- // 传阅人ID
- map2.put("actorId", "李四");
- // 是否创建了任务实例
- map2.put("taskCreate", "0");
- ls.add(map2);
- Map map3 = new HashedMap();
- // 传阅人ID
- map3.put("actorId", "王五");
- // 是否创建了任务实例
- map3.put("taskCreate", "0");
- ls.add(map3);
- pi.getContextInstance().setVariable("list", ls);
- Token token = pi.getRootToken();
- token.signal();
- context.close();
- }
- // 结束工作
- public static void endTask(String actorId) throws Exception {
- JbpmConfiguration config = JbpmConfiguration.getInstance();
- JbpmContext context = config.createJbpmContext();
- TaskInstance ti = (TaskInstance) context.getTaskList(actorId).get(0);
- ti.end();
- // 从流程上下文中获取传阅人
- List ls = (List) ti.getContextInstance().getVariable("list");
- for (int i = 0; i < ls.size(); i++) {
- Map map = (Map) ls.get(i);
- // 修改当前传阅人额度创建标识为1
- if (map.get("actorId").toString().equals(actorId)) {
- map.put("taskCreate", "1");
- break;
- }
- }
- //创建下一个传阅人的任务实例
- boolean flag = true;
- for(int i=0;i<ls.size();i++) {
- Map map = (Map)ls.get(i);
- String taskCreate = map.get("taskCreate").toString();
- if(taskCreate.equals("0")) {
- String actor = map.get("actorId").toString();
- TaskInstance newTaskInstance = ti.getTaskMgmtInstance().createTaskInstance(ti.getTask(),ti.getToken());
- newTaskInstance.setActorId(actor);
- flag = false;
- break;
- }
- }
- ti.getContextInstance().setVariable("list", ls);
- //如果没有任务实例,表示传阅完成 进入下一个节点。
- if(flag) {
- ti.getToken().signal();
- }
- context.close();
- }
- }