1
votes

I am using JBPM 5.4 and I can get the assigned tasks and candidate tasks for specific user.

I want to know how can i get the completed tasks for the user and his outputs

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

1 Answers

0
votes

You could potentially implement a ProcessEventListener. The afterNodeLeft method should execute after any node is complete, so if you are looking for a specific node and/or user you might need to add some checks.

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
}

You will need to register the listener to your session when you create it.

KieSession ksession = //however you gain access to your ksession
ksession.addEventListener(new CustomProcessEventListener());