JBoss Community

Re: obsolete id

created by Francesco Pietrobelli in jBPM - View the full discussion

You can use this method:

 

/**
           * Get the node instance corresponding to a work item identified with
           * <code>workItemId</code>
           * 
           * @param workItemId
           *            identification of work item id
           * @param container
           *            the container that contains the node instance, in most case
           *            the process instance
           * @return null if no node instance is found, the correspond node instance
           *         otherwise
           */
          public static WorkItemNodeInstance findNodeInstance(long workItemId,
                              NodeInstanceContainer container) {
                    for (NodeInstance nodeInstance : container.getNodeInstances()) {
                              if (nodeInstance instanceof WorkItemNodeInstance) {
                                        WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance;
                                        if (workItemNodeInstance.getWorkItem().getId() == workItemId) {
                                                  return workItemNodeInstance;
                                        }
                              }
                              if (nodeInstance instanceof NodeInstanceContainer) {
                                        WorkItemNodeInstance result = findNodeInstance(workItemId,
                                                            ((NodeInstanceContainer) nodeInstance));
                                        if (result != null) {
                                                  return result;
                                        }
                              }
                    }
                    return null;
          }
 

 

and then invoke the method getNodeId() on returned object.

 

Of course your WorkItemHandler needs a reference to StatefulKnowledgeSession, but you can pass it when you register your WorkItemHandler on your session.

 

I hope this is useful.

Reply to this message by going to Community

Start a new discussion in jBPM at Community