jbpm5

com.sky.plugin.jbpm.def.DynamicCreateTaskInstance
代码
public class DynamicCreateTaskInstance implements ActionHandler {   
       
    private static final long serialVersionUID = 1L;   
  
    public void execute(ExecutionContext context) throws Exception {   
           
        ProcessDefinition processDefinition = context.getProcessDefinition();   
  
        TaskNode taskNode = (TaskNode) context.getNode();   
        Task task = (Task)taskNode.getTasks().iterator().next();   
  
        Long processDefinitionId = processDefinition.getId();   
        Long taskId = task.getId();   
           
        Token token = context.getToken();   
        TaskMgmtInstance tmi = context.getTaskMgmtInstance();   
           
        //获取自定义的进行会签的人员   
        ServiceFactory serviceFactory = ServiceFactory.getInstance();   
        ProcessService ps = serviceFactory.getProcessService();   
        String[] actors = ps.loadTaskActors(processDefinitionId, taskId);   
           
        //根据会签人员,每人创建一个TaskInstance   
        for(String actor : actors){   
            tmi.createTaskInstance(task, token).setActorId(actor);   
        }   
    }   
}   
com.sky.plugin.jbpm.def.ConuntersignActionHandler
代码
public class ConuntersignActionHandler implements ActionHandler {   
  
    private static final long serialVersionUID = 1L;   
  
    @SuppressWarnings("unchecked")   
    public void execute(ExecutionContext context) throws Exception {   
  
        Token token = context.getToken();   
  
        TaskMgmtInstance tmi = context.getTaskMgmtInstance();   
  
        Collection<TaskInstance> unfinishedTasks = tmi   
                .getUnfinishedTasks(token);   
  
        Object variable = context.getVariable("selectedTransition");   
        String selectedTransition;   
        if (variable == null) {   
            throw new RuntimeException(   
                    "Jbpm transition error: user selected transition is null!");   
        } else {   
            // 获取当前TaskInstance选择的路径   
            selectedTransition = variable.toString();   
        }   
  
        // 如果用户选择的路径是流程定义中制定的不通过的路径,则自动完成余下所有的会签Task并转到相应路径   
        if (selectedTransition.equals("拒绝到复核人")) {   
            for (TaskInstance unfinishedTaskInstance : unfinishedTasks) {   
                // 把被结束的没有完成的TaskInstance的ActorId改为automatic complete   
                if (!unfinishedTaskInstance.hasEnded()) {   
                    unfinishedTaskInstance.setActorId("automatic complete");   
                    unfinishedTaskInstance.end("拒绝到复核人");   
                }   
            }   
        }   
    }   
  
}   
这个类对于会签是至关重要的,要通过这个Action来判断会签的情况。在这个Action中有这样几句代码:
代码
Object variable = context.getVariable("selectedTransition");   
        String selectedTransition;   
        if (variable == null) {   
            throw new RuntimeException(   
                    "Jbpm transition error: user selected transition is null!");   
        } else {   
            // 获取当前TaskInstance选择的路径   
            selectedTransition = variable.toString();   
        }   

其中的selectedTransition是用户选择的路径,也就是通过这个来判断会签的用户选择了“同意”或者“拒绝到复核人”,你可以通过流程变量的形式来保存。
如果“同意”,则继续下去,直到该TaskNode中所有的TaskInstance完成以后,通过会签,继续下去,如果选择“拒绝到复核人”,则会自动完成余下的所有TaskInstance,然后转到Transition“拒绝到复核人”,会签不通过。
其中有一句,设置所有自动完成的TaskInstance的Actor为“automatic complete”,这个可以解决在“以办事务”中出现自动完成的任务(TaskInstance)
代码
unfinishedTaskInstance.setActorId("automatic complete"); 
到这里整个会签的实现都在这里了,行文有点乱。哈哈!

你可能感兴趣的:(jbpm)