http://77857.blog.51cto.com/67857/171334
http://tech.ddvip.com/2009-09/1252499380131731_3.html jbpm
http://www.pcjx.net/Java/J2eeh/216094.html 实现并发流程
一、任务分派 (单个任务,多个用户,把一个任务分派给一个用户)
package org.jbpm.tutorial.taskmgmt;
import junit.framework.TestCase;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class TaskAssignmentTest extends TestCase {
public void testTaskAssignment() {
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
"<process-definition name='the baby process'>" +
" <start-state>" +
" <transition name='baby cries' to='t' />" +
" </start-state>" +
" <task-node name='t'>" +
" <task name='change nappy'>" +
" <assignment class='org.jbpm.tutorial.taskmgmt.NappyAssignmentHandler' />" +
" </task>" +
" <transition to='end' />" +
" </task-node>" +
" <end-state name='end' />" +
"</process-definition>"
);
ProcessInstance processInstance =
new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
token.signal();
assertSame(processDefinition.getNode("t"), token.getNode());
// When execution arrived in the task-node, a task 'change nappy'
// was created and the NappyAssignmentHandler was called to determine
// to whom the task should be assigned. The NappyAssignmentHandler
// returned 'papa'.
// In a real environment, the tasks would be fetched from the
// database with the methods in the org.jbpm.db.TaskMgmtSession.
// Since we don't want to include the persistence complexity in
// this example, we just take the first task-instance of this
// process instance (we know there is only one in this test
// scenario.
TaskInstance taskInstance = (TaskInstance)
processInstance
.getTaskMgmtInstance()
.getTaskInstances()
.iterator().next();
// Now, we check if the taskInstance was actually assigned to 'papa'.
assertEquals("papa", taskInstance.getActorId() );
taskInstance.end();
// Since this was the last (only) task to do, the completion of this
// task triggered the continuation of the process instance execution.
assertSame(processDefinition.getNode("end"), token.getNode());
}
}
import org.jbpm.graph.exe.*;
import org.jbpm.taskmgmt.def.*;
import org.jbpm.taskmgmt.exe.Assignable;
public class NappyAssignmentHandler implements AssignmentHandler {
private static final long serialVersionUID = 1L;
public void assign(Assignable assignable, ExecutionContext executionContext) {
assignable.setActorId("papa");
}
}
------------------------------------------------------------------------------------------------------------
<task name="撤回请假单" swimlane="applyman" template="apply_3_new.ftl"><controller><variable name="reason" access="read" mapped-name="reason"><task-node name="审核"><task template="apply_2.ftl" swimlane="boss" name="审核员工请假"><controller><variable mapped-name="reason" access="read" name="reason"><variable mapped-name="day" access="read,write" name="day"><task template="apply_3_new.ftl" swimlane="applyman" name="撤回请假单"><controller><variable mapped-name="reason" access="read" name="reason"><variable mapped-name="day" access="read" name="day">
这个节点包含了我们刚才说的两个任务.我们知道当流传到这个节点的时候.这两个任务会同时创建并分配给各自的人员.有一个人完成任务后 节点向指定的节点转向.同时结束另一个任务. signal="first" 有一个任务结束节点就流转. end-tasks="true" 结束该节点的时候自动结束其他没有完成的任务.
1、node(自动节点)
这种节点和State相反,也称自动节点。当业务程序实例执行到这个节点不会停止执行。而是会继续往下执行。如果该节点存在多个离开转向。那么,就会执行其中的第一个离开转向,在Node状态中,不需要外部参与者的参与,业务流程的这个部分是自动的、即时完成的。
TaskInstances 和 SwimlaneInstance s 两者都可以分配给指定的用户或参与者池. 分配一个TaskInstance给用户, 调用 Assignable.setActorId(String actorId) . 分配一个TaskInstance给候选参与者池, 调用 Assignable.setPooledActors(String[] actorIds).
流程中的每个任务都可以用在运行时间执行分配handler的实现关联起来.
当流程中多个任务被分配给同一个人或一组参与者,考虑 swimlane用途
----------------------------------------------------------------------------------------------在tasknode中,多个transition
public void approveByManager(boolean pass){
System.out.println("==FirstFlowProcessTest.approveByManager()==");
ProcessInstance pi=this.getContext().getProcessInstance(4);
Iterator<TaskInstance> it = pi.getTaskMgmtInstance().getTaskInstances().iterator();
for( ;it.hasNext(); ){
TaskInstance ti = it.next();
if(ti.getActorId().equals("DepartmentManager")){
List<Transition> transitions = ti.getToken().getNode().getLeavingTransitions();
for(Transition t : transitions){
System.out.println("----Transition" + t.getName());
}
// assertEquals("DepartmentManager",ti.getActorId());
if(pass){
ti.end("部门经理审批通过"); //对于在tasknode结点中多个transition,用end(transition_name)
}else{ //方法来指向下一个结点
ti.end("部门经理驳回");
}
return;
}
}
}
<task-node name="部门经理审批">
<task name="Task_ManagerApprove">
<assignment class="com.firstflow.task.DepartmentManagerApproveAssignmentHandler"></assignment>
</task>
<transition to="金额判定" name="部门经理审批通过">
<action name="Task_ManagerApproved" class="com.firstflow.action.ManagerApprovedActionHandler"></action>
</transition>
<transition to="结束" name="部门经理驳回">
<action name="Action_ManagerDisapprove" class="com.firstflow.action.ManagerDisapproveActionHandler"></action>
</transition>
</task-node>