<?xml version="1.0" encoding="UTF-8"?>
<process name="task" xmlns="http://jbpm.org/4.4/jpdl">
<start name="start1" g="314,21,48,48">
<transition name="to 申请请假" to="申请请假" g="-71,-17"/>
</start>
<end name="end1" g="330,339,48,48"/>
<task name="申请请假" g="142,103,92,52" assignee="#{applicator}">
<transition name="to 部门经理审批" to="部门经理审批" g="-111,11"/>
</task>
<task name="部门经理审批" g="296,170,92,52">
<assignment-handler class="cn.itcast.jbpm0909.task.MyAssignmentHandler"></assignment-handler>
<transition name="to 总经理审批" to="总经理审批" g="-92,8"/>
</task>
<task name="总经理审批" g="405,261,92,52" assignee="#{boss}">
<transition name="to end1" to="end1" g="-47,-17"/>
</task>
</process>
public class MyAssignmentHandler implements AssignmentHandler{
@Override
public void assign(Assignable assignable, OpenExecution execution)
throws Exception {
String manager = execution.getVariable("manager").toString();//execution的上下文
assignable.setAssignee(manager);
}
}
/**
* 给任务的执行人动态的赋值
* * 在*.jpdl.xml文件中
* 在task元素中
* <task name="部门经理审批" g="296,170,92,52">
* <assignment-handler class="cn.itcast.jbpm0909.task.MyAssignmentHandler">
* </assignment-handler>
* </task>
* 可以在MyAssignmentHandler中给当前的任务赋值执行人,当进入当前节点时,assign方法执行
* * 在*.jpdl.xml文件中
* <task name="申请请假" g="142,103,92,52" assignee="#{applicator}">
* assignee可以通过流程变量的方式进行赋值
* 在执行该任务节点之前,必须给applicator赋值
* * 可以通过taskService.assignTask(String taskId,String userId);给正在执行的任务赋值任务的执行人
* @author Administrator
*
*/
public class TaskTest extends BaseJbpm{
@Test
public void testDeploy(){
processEngine.getRepositoryService()
.createDeployment()
.addResourceFromClasspath("cn/itcast/jbpm0909/task/task.jpdl.xml")
.deploy();
}
@Test
public void testStartPI(){
Map<String, String> variables = new HashMap<String, String>();
variables.put("manager", "王二麻子");
variables.put("applicator", "张三");
processEngine.getExecutionService()
.startProcessInstanceById("task-2",variables);
}
@Test
public void testFinishTask(){
processEngine.getTaskService()
.completeTask("150004");
}
@Test
public void testAssigneeWhenTask(){
/**
* 该API只能给当前的任务赋值
*/
processEngine.getTaskService()
.assignTask("290001", "王二麻子的哥");
}
}