1 Reply Latest reply on Apr 2, 2013 4:18 AM by bird86

    Getting Node Name from Node Instance in jBPM 5.4

    ciberg

      Hi,

       

      I'm trying to get the node name for a process that at a given moment has a gateway making two tasks active simultaneasly.

       

      The problem is that when I get the NodeInstance collection it seems that it is not iterating correctly, when I use a do/while with a hasNext I enter a infinite loop and only one NodeName is obtained.

      Then I changed it for using size, and although the size is correct (in my case size is 2) the getNameName method always returns the same node name as if the iterator was always in the same place.

       

      Can you help me on this?

       

      Here is the code:

      ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);

      WorkflowProcessInstance workflowProcessInstance = null;

      Collection<NodeInstance> nodes = ((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance).getNodeInstances();

      int nodeSize = nodes.size();

      System.out.println("Number of nodes - " + nodeSize);

      int count = 0;

      do {

        processTasks = nodes.iterator().next().getNodeName();

        System.out.println(processTasks + "  -  " + count);

        count = count + 1;

      } while (count < nodes.size());

       

      The result of this code is:

      Number of nodes - 2

      Digitalize Document - 0

      Digitalize Document - 1

       

       

      Instead of:

      Number of nodes - 2

      Digitalize Document - 0

      Insert data - 1

       

      Thank you

        • 1. Re: Getting Node Name from Node Instance in jBPM 5.4
          bird86

          You could code this:

           

          Iterator<NodeInstance> iterator = nodes.iterator();

          do {

            processTasks = iterator.next().getNodeName();

            System.out.println(processTasks + "  -  " + count);

            count = count + 1;

          } while (count < nodes.size());

           

           

          iterator() method will give you a new iterator instance when you invoke it every time.So you get the first Nodeinstance every time.