JBPM-动态的赋值任务申请人:
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="">
<start g="314,21,48,48">
<transition to="申请请假" g="-71,-17"/>
</start>
<end g="330,339,48,48"/>
<task g="142,103,92,52" assignee="#{applicator}">
<transition to="部门经理审批" g="-111,11"/>
</task>
<task g="296,170,92,52">
<assignment-handler></assignment-handler>
<transition to="总经理审批" g="-92,8"/>
</task>
<task g="405,261,92,52" assignee="#{boss}">
<transition 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 g="296,170,92,52">
* <assignment-handler>
* </assignment-handler>
* </task>
* 可以在MyAssignmentHandler中给当前的任务赋值执行人,当进入当前节点时,assign方法执行
* * 在*.jpdl.xml文件中
* <task 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", "王二麻子的哥");
}
}