3 Replies Latest reply on Sep 2, 2014 8:08 AM by mdegan

    i want to get all the processInstances and know which step do they each get? jbpm5.4

    其凡 莫 Newbie

      i'm not familiar with the api , i just know how to start process and get tasks complete tasks but i want to know which step do the proess get ? can you help me?

        • 1. Re: i want to get all the processInstances and know which step do they each get? jbpm5.4
          Arif Mohammed Novice

          Can you explain little bit more ? If I understood you correctly, you want to know what is the current step/node in the process which is active. If so please note that a process can take multiple parallel paths and in that case you might have more than one active node. So you could get the current nodes of a process instance as follows

           

              public List<String> getActiveNodes(Long processInstanceId){

                  ProcessInstance instance = ksession.getProcessInstance(processInstanceId);

                  WorkflowProcessInstance wfInstance = ((WorkflowProcessInstance)instance);   

                 // get current active Node names

                 List<String> activeNodes = new ArrayList<String>();

                 getActiveNodes(wfInstance,activeNodes); 

                return activeNodes;

              }

            

              private void getActiveNodes(NodeInstanceContainer container, List<String> activeNodes) {  

                  for (NodeInstance nodeInstance: container.getNodeInstances()) {

                    activeNodes.add(nodeInstance.getNodeName());

                    if (nodeInstance instanceof NodeInstanceContainer) {

                       getActiveNodes((NodeInstanceContainer) nodeInstance, activeNodes);

                    }

                  }

              }

          1 of 1 people found this helpful
          • 2. Re: i want to get all the processInstances and know which step do they each get? jbpm5.4
            其凡 莫 Newbie

            sorry for my pool english.

            i think your answer is what i want and thx a lot.

            but after i tried , the question now is that i use ksession.getProcessInstances() to get all the processInstance but it return a collection of size 0 which confused me a lot

            how can i get all the processIds or processInstances in jbpm5.3 . ps:maybe my title is wrong because i find i use jbpm5.3

            waht's more,can jbpm generate a image that represent the current state of the process , not only the image we draw in bpmn2 but also the state of which node is completed and reserved .

            • 3. Re: Re: i want to get all the processInstances and know which step do they each get? jbpm5.4
              mdegan Newbie

              Hi,

               

              If you have DB Logging enabled, you can try this:

               

              Iterator<org.drools.definition.process.Process> it = ksession.getKnowledgeBase().getProcesses().iterator();
              while(it.hasNext())
              {
                List<ProcessInstanceLog> pl = JPAProcessInstanceDbLog.findProcessInstances(it.next().getId());
                for(int i=0;i<pl.size();i++)
                {
                     List<String> activeNodes = getActiveNodes(pl.get(i).getProcessInstanceId());
                }
              }
              

               

              This way you can use the previous response method getActiveNodes() to get the state for each process available in your ksession.

               

              Regards,

              Manny