jbpm 5.4为特定用户完成任务

时间:2015-05-04 12:14:56

标签: jbpm

我正在使用JBPM 5.4,我可以获得分配的任务 特定用户的候选任务。

我想知道如何为用户及其输出完成已完成的任务

List<TaskSummary> tasks = taskSummaryResponseHandler.getResults();  
finsihTask(taskId,"Mahmoud");

responseHandler.waitTillDone(1000);
System.out.println("looping on mahmoud tasks "+tasks.size());

for(TaskSummary taskSummary : tasks){
    System.out.println("status is "+taskSummary.getStatus());
    System.out.println("created by "+taskSummary.getCreatedBy());
    System.out.println("created date "+taskSummary.getCreatedOn());

    if("InProgress".equalsIgnoreCase(taskSummary.getStatus().name())){
        System.out.println("user will finish task "+taskSummary.getName());
        finsihTask(taskSummary.getId(), "Mahmoud");
    }

    if("Reserved".equalsIgnoreCase(taskSummary.getStatus().name())){
        System.err.println("user will take task "+taskSummary.getName());
    }
}

1 个答案:

答案 0 :(得分:0)

您可以实施ProcessEventListener。 afterNodeLeft方法应在任何节点完成后执行,因此如果您要查找特定节点和/或用户,则可能需要添加一些检查。

http://www.mywebsite.com/wp-content/plugins/myplugin/

您需要在创建会话时将侦听器注册到会话中。

public class CustomProcessEventListener implements ProcessEventListener {    

    public void afterNodeLeft(ProcessNodeLeftEvent event) {
        NodeInstance ni = event.getNodeInstance();

        //Only check for User Tasks
        if (ni instanceof HumanTaskNodeInstance) {
            HumanTaskNodeInstance htni = (HumanTaskNodeInstance)ni;
            Map<String, Object> results = htni.getWorkItem().getResults();

            //Get the userId of the actor
            String actorId = (String)htni.getWorkItem().getResult("ActorId");

            //You can filter for a specific user
            if (actorId.equals("YOUR_USER")) {
                 //TODO: cycle through results map to find 
            }

            //You can also certain nodes
            if (htni.getNodeName().equals("NODE_NAME") {
                ....
            }
        }
    }

    //other unimplemented methods not shown
}