JBoss Community

Re: How to get current node instance in a workitem handler?

created by Affan Dar in jBPM - View the full discussion

I had to store the ksession id and the process instances it is running separately for recovery. On server restart, I load all sessions and for all process instances stored in my session->processinstanceid mapping table I call ksession.getProcessInstance(processinstanceid).

 

From another thread here: https://community.jboss.org/thread/195459, it seems like it should be possible to load a process instance into a ksession different from the one it was created in (with some caveats) but I didn't go that route.

 

Once the right ksession is loaded and available to the workitemhandler, finding the nodeId is straightfoward. E.g. something like this:

 

private WorkItemNodeInstance getCurrentWorkItemNodeInstance(WorkItem workItem) {

          RuleFlowProcessInstance processInst = (RuleFlowProcessInstance)this.ksession.getProcessInstance(workItem.getProcessInstanceId());

          Collection<NodeInstance> nodeInstances = processInst.getNodeInstances();

          for(NodeInstance nodeInst : nodeInstances) {

                    if(nodeInst instanceof WorkItemNodeInstance) {

                              if(((WorkItemNodeInstance)nodeInst).getWorkItem().getId() == workItem.getId()) {

                              return ((WorkItemNodeInstance)nodeInst);

                              }

                    }

          }

          return null;

}

 

HTH

Reply to this message by going to Community

Start a new discussion in jBPM at Community