6 Replies Latest reply on Oct 10, 2011 5:33 AM by skodagally

    Query the workflow process definition

    skodagally

      Are there any api’s on the Knowledge base or Knowledge Session to query the workflow process definition to 

       

      1. Get the list of Human Activities.
      2. Get the list of transitions attached to a Gateway.
        • 1. Re: Query the workflow process definition
          melc

          Hello,

          Take a look here and the referenced threads

          http://community.jboss.org/message/623594#623594

           

          it shows how to iterate the process structure... so with the appropriate casting of the nodes you may get the info you need.

          • 2. Re: Query the workflow process definition
            skodagally

            Thanks Chris,

             

            My requirement is also to get the list of human activities from knowledge base, since i need this list even when no process instances are running.

             

            So based on the processid is there a way to query the process definition?

            • 3. Re: Query the workflow process definition
              calca

              Hi,

               

              I don't know if it can be obtained from the kbase. I have made it from bpmn file, but parsing it and obtaining userTask nodes. You can check it here:

              https://github.com/Salaboy/smart-tasks/blob/master/smart-tasks-utils/src/main/java/com/wordpress/salaboy/smarttasks/taskform/HumanTaskSemanticModule.java

               

              Regards,

               

              Demian

              • 4. Re: Query the workflow process definition
                swiderski.maciej

                Have you tried to use knowledge base to get processes and then cast it to NodeContainer?

                 

                 

                Collection<Process> processes = kbase.getProcesses();
                
                for (Process p : processes) {
                     NodeContainer container = (NodeContainer) p;
                     // following line should return all nodes in the process - hopefully 
                     container.getNodes();
                }
                

                 

                NOTE: It is written by hand the code so it can have some typos... don't have access to my development environment now so was not able to verify that.

                 

                HTH

                • 5. Re: Query the workflow process definition
                  melc

                  Hello,

                  You can get any node you like

                  i.e.

                  WorkflowProcess workFlowProcess = ((WorkflowProcess) knowledgeBase.getProcess("yourProcessId"));

                          nodes = workFlowProcess.getNodes();

                   

                  then you can loop and cast to whatever node you want look at the types in package org.jbpm.workflow.core.node i.e. there is a HumanTaskNode etc

                  i.e. finding the start node

                   

                  Node startNode = null;

                          for (Node node : nodes) {

                              if (node instanceof StartNode) {

                                  startNode = node;

                              }

                          }

                   

                  you can even traverse your process

                  i.e. call the following method as traverseProcessForHumanTaskNodes(startNode, new ArrayList<Node>()); then it will return a collection with all the human task nodes

                   

                  public static Collection traverseProcessForHumanTaskNodes(Node startNode, Collection<Node> nodes) {

                  /*you can choose one of your outgoing connections based on some logic, here it is assumed that there is always one outgoing that moves forward etc*/

                          Node nextNode = startNode.getOutgoingConnections("DROOLS_DEFAULT").get(0).getTo();

                   

                          if (nextNode instanceof HumanTaskNode) {

                                  nodes.add(nextNode);

                          } else if (nextNode instanceof EndNode) {

                              return nodes;

                          }

                          return traverseProcessForHumanTaskNodes(nextNode, nodes);

                      }

                   

                  This is just to get you starting.... with a little debugging you will see that everything is connected and you can easily retrieve it.

                  • 6. Re: Query the workflow process definition
                    skodagally

                    Thank you all,

                     

                    Thanks Chris i was able to get the list of Human Tasks and Constraints (transitions) associated with a Split node.