13 Replies Latest reply on Jan 10, 2013 3:12 PM by roxy1987

    Get Activity Coordinates

    roxy1987

      Hi,

       

      In jBPM 4, we could use the RepositoryService to get the activity coordinates. Whats the API to achieve the same in jBPM 5?

       

      Regards.

        • 1. Re: Get Activity Coordinates
          roxy1987

          Anything regarding this question guys pls..

          • 2. Re: Get Activity Coordinates
            zabalet

            Maybe there is a simple way, but here goes something:

             

             

            This gives you the list of visited nodes (actuals and past)

            List<NodeInstanceLog> nodeInstanceLogs = JPAProcessInstanceDbLog.findNodeInstances(new Long(processInstanceId));

             

            Iterates and acquire Node objects

            for (NodeInstanceLog nodeInstanceLog : nodeInstanceLogs) {

                Node node = ((WorkflowProcess) process).getNode(Long.parseLong(nodeInstanceLog.getNodeId()));

                // ie: this gives you x coordinate: node.getMetaData().get("x");

            }

             

            Hope this help.

            • 3. Re: Get Activity Coordinates
              roxy1987

              Cool. I am gonna give it a try. Any help is much appreciated. I will get back with the output. Thanks a lot Marcelo.

              • 4. Re: Get Activity Coordinates
                roxy1987

                What is the object "process" here? How do i get it? All i have is the processinstance id.

                • 5. Re: Get Activity Coordinates
                  zabalet

                  Sorry, I forgot this...

                   

                  org.drools.definition.process.Process process = knowledgeBase.getProcess(processInstanceId);

                  1 of 1 people found this helpful
                  • 6. Re: Get Activity Coordinates
                    roxy1987

                    Ok. So the following is giving me an NPE.

                     

                    Process process = knowledgeBase.getProcess(processInstanceId);

                     

                    I am not able to retrieve the process from knowledge base. I must tel you that I am running a web application integrated with jbpm 5 on tomcat 6 and db2. There is no human task server war. I have a startup servlet which takes care of the task service(as suggested by bpmn2user).

                     

                    With so many changes to the configuration, i dont feel that directly using a knowledge base is fine. But since we dont need a task client to get the processes, it should be okay to just use the knowledge base. I dont know man.. I am confused with persistence and connections and services

                     

                    I am able to retrieve the nodes from db. I cross checked the node ids.

                    Another question regarding the same topic. Do you know about class BPMNShapeHandler.NodeInfo? I saw methods like getX(), getY(), getWidth(), getHeight();

                    • 7. Re: Get Activity Coordinates
                      zabalet

                      Ah, ok, I understand, I thought you was interested on the active nodes of an instance, and I see now you are interested on all nodes of a process definition.

                      I IMHO I suggest two ways.

                       

                      One is expose the bpmn file to the front end because this file is a standard and has a lot of sense to use it directly for a RIA. It is relative simple to extract diagram information and parsing it with javascript.

                       

                      The other way is using the api, this has sense too because this way you have only one authorithy of information in your system and some more control. Moreover, if you need another runtime information, you must go this way.

                       

                      Here some sample code. I'm not yet using it... take it with care

                       

                      Somewhere in your code you have surely something like this...

                       

                      org.drools.builder.KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                      org.drools.KnowledgeBase knowledgeBase = builder.newKnowledgeBase();

                      // add some process definitions

                      // builder.add(resource, ResourceType.BPMN2);

                       

                      org.drools.runtime.StatefulKnowledgeSession knowledgeSession = JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBase, null, env);

                       

                      Then, you can do something like this:

                       

                      // import org.drools.definition.process.Process

                      Process process = knowledgeBase.getProcess("the.process.definition.id.you.are.interested.in");

                       

                      You could find a lot of info inside process object, ie:

                       

                      // import org.jbpm.workflow.core.impl.NodeImpl

                      // import org.jbpm.workflow.core.impl.WorkflowProcessImpl

                      for (NodeImpl nodeImpl : (NodeImpl[]) ((WorkflowProcessImpl) process).getNodes()) {

                          node.getMetaData().get("height");

                          node.getName();

                      }

                      • 8. Re: Get Activity Coordinates
                        roxy1987

                        I would go for the APIs. I am gonna give it a shot.

                        But do I need to parse the proc definition again using a Knowledge Session to get the coordinates?

                        If it doesnt work then I can use the XML file instead to read the coordinates. Thanks Man.

                        For now I am gonna mark it as correct.

                         

                        Another question if you could help me with.

                        https://community.jboss.org/thread/218412

                        Thanks.

                        • 9. Re: Get Activity Coordinates
                          roxy1987

                          Okay so I tried the code and it gave me a class cast exception. Then I tried your previous code, it seems to be giving me the coordinates but not exactly in a way I need them.

                           

                          I have got a process with a start node, 3 human task nodes, and an end node. So total of 5 nodes.

                           

                          Out of the 3 human task nodes, I have completed 1 human task. It is at 2nd human task.

                           

                          The code returned me 5 nodes. But the first 2 nodes returned are both start nodes, next 2 are both of first human task and 5th node is of second human task. Even in the db I have 5 nodes. I am not sure if thats how the information is logged or if this is a bug.

                           

                          But what I am looking for is the coordinate of just the second human task since the process is pending at it.

                           

                          But at least I am getting the coordinates now thanks to you. I am gonna try to figure out the problem/logic. If you already know then you are most welcome to share. Thanks.

                          • 10. Re: Get Activity Coordinates
                            zabalet

                            Taht's because it logs the enter and the exit, so, usually, when a process instance ends, you end up with two registers per node. The NodeInstanceLog object has a type attribute. You could use it to determine if you are "in" the node or you "passed" the node. If you have ENTER but not EXIT, you are in.

                             

                            nodeInstanceLog.getType() == NodeInstanceLog.NodeInstanceLog.TYPE_ENTER

                             

                            nodeInstanceLog.getType() == NodeInstanceLog.NodeInstanceLog.TYPE_EXIT

                             

                            Hope this help.

                            • 11. Re: Get Activity Coordinates
                              roxy1987

                              Cool. This helped. It wont give me the current active node though. But It will surely filter the list to the enter type nodes.

                              • 12. Re: Get Activity Coordinates
                                zabalet

                                This was the class cast exception, my mistake

                                 

                                replace // import org.jbpm.workflow.core.impl.NodeImpl

                                by        // import org.drools.definition.process.Node

                                • 13. Re: Get Activity Coordinates
                                  roxy1987

                                  Great. It is working now.

                                  I mixed your two code frags to get the currently active task. Becuase the previous code gives me both type 0 and type 1 nodes and the other code gives me all the nodes of the process. So I am checking if a node has both type 0 and type 1 then it has definitely been completed. Otherwise it is pending. Btw. I am hoping that there are only 2 types for a task. Enter and Exit.

                                   

                                   

                                  List<NodeInstanceLog> nodeInstanceLogList;
                                  
                                  
                                  for (Node node : (Node[]) ((WorkflowProcessImpl) process).getNodes()){
                                  nodeInstanceLogList = JPAProcessInstanceDbLog.findNodeInstances(Long.parseLong(processInstanceId), 
                                  new Long(node.getId()).toString());
                                  if(nodeInstanceLogList.size() == 1){
                                  System.
                                  out.println();System.
                                  out.println(node.getName());System.
                                  out.println(node.getMetaData().get("height"));System.
                                  out.println(node.getMetaData().get("width"));coordinates.add(node.getMetaData().get(
                                  "height"));coordinates.add(node.getMetaData().get(
                                  "width"));}
                                  }