实现AssignmentHandler接口,在接口的实现方法中,查询角色下面的用户,并将任务实例分配给这些用户即可。
<?xml version="1.0" encoding="UTF-8"?>
<process-definition
xmlns="urn:jbpm.org:jpdl-3.2" name="test11">
<start-state name="开始">
<transition name="" to="领导审批"></transition>
</start-state>
<task-node name="领导审批">
<task name="审批">
<assignment class="com.ygtim.domain.RoleAssignmentHandler">
<roleName>领导</roleName>
</assignment>
</task>
<transition name="" to="结束" ></transition>
</task-node>
<end-state name="结束"></end-state>
</process-definition>
public class RoleAssignmentHandler implements AssignmentHandler {
/** Comment for <code>serialVersionUID</code> */
private static final long serialVersionUID = -5348773299229669146L;
/**
* 由JBPM来注入
*/
private String roleName;
@Override
public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
if (roleName == null) {
throw new RuntimeException("角色不能为空");
} else if ("领导".equals(roleName)) {
//根据角色查找下面的所有用户
assignable.setPooledActors(new String[] { "张三", "李四" });
} else {
throw new RuntimeException("该角色不存在");
}
}
}