7 Replies Latest reply on Aug 19, 2005 11:03 AM by brittm

    How do I get a list of nodes?

    Guillem Gelabert Newbie

      I've got the following process definition:

      <process-definition name="traspaso_propiedad">
       <start-state name="start">
       <transition to="s" />
       </start-state>
       <state name="s">
       <transition to="end" />
       </state>
       <end-state name="end">
       </end-state>
      </process-definition>


      I'm trying to get a list of nodes to print out each name, my code is:
      Iterator istates = myProcessDefinition.getNodes().iterator();
       while (istates.hasNext()){
       Node tempNode = (Node)istates.next();
       System.out.println("NODE NAME: " + tempNode.getName());
       }


      But it prints nothing, i've checked and the list of nodes is empty, any idea about what am I missing?

        • 1. Re: How do I get a list of nodes?
          Peter Johnson Master

          My code to pring out the node names looks almost like yours. I would guess that the myProcessDefinition valirable doesn't contain your process. Try printing out myProcessDefinition.getName() as see if you get "traspaso_propiedad".

          • 2. Re: How do I get a list of nodes?
            Guillem Gelabert Newbie

            I tried to print out the process definition name and i get "traspaso_propiedad". I've also checked in the database the table jbpm_node and the nodes are there with the correct process definition. Can't figure out what's wrong maybe something about beginTranscation() and commitTransaction()?

            • 3. Re: How do I get a list of nodes?
              Alejandro Guizar Master

              Is the call to ProcessDefinition.getNodes() placed before you close your JbpmSession? Almost everything from the jBPM database is lazily loaded, and an empty collection is a typical symptom of a closed session.

              • 4. Re: How do I get a list of nodes?
                Peter Johnson Master

                I looked at my code and I have a beginTransaction before doing anything, and a commitTransaction after printing out all the names.

                • 5. Re: How do I get a list of nodes?
                  Guillem Gelabert Newbie

                  Now it works, i've looked in the jbpm_processdefinition table and checked that, actually there were two rows with the same version of the same processdefinition but in jpmb_node table all my nodes belonged to the second one, removing the first row has corrected the problem, now I must check why the "empty" :P thanks to everyone for the help ;)

                  • 6. Re: How do I get a list of nodes?
                    Guillem Gelabert Newbie

                    Finally I've found out why there were two records for each process definition version, it was because my code to add one new process definition looked like:

                    ProcessDefinition myProcessDefinition = ProcessDefinition.parseXmlResource(myProcessDefinitionFile);
                    jbpmSession.beginTransaction();
                    jbpmSession.getGraphSession().saveProcessDefinition(myProcessDefinition);
                    jbpmSession.commitTransaction();
                    


                    But GraphSession.saveProcessDefinition() saves it with its own transaction.
                    By removing my beginTransaction()/commitTransaction() the problem has been solved.

                    • 7. Re: How do I get a list of nodes?
                      brittm Novice

                      I can't see how nested transacitons should duplicate the entry. That sounds more to me like a bug. I had come to the conclusion that

                      jbpmSession.getGraphSession().saveProcessDefinition(myProcessDefinition);

                      simply does not properly support versioning of the process definition. I use the following code instead and never have any problems:
                      jbpmSession.beginTransaction();
                       ProcessArchiveDeployer pad = new ProcessArchiveDeployer(jbpmSessionFactory);
                      
                       String resource = request.getParameter("file");
                       if(resource.toUpperCase().endsWith(".XML")) {
                       FileInputStream fis = new FileInputStream(resource);
                       ProcessDefinition pd = ProcessDefinition.parseXmlInputStream(fis);
                       //jbpmSession.getGraphSession().saveProcessDefinition(pd); //does not handle versioning
                       pad.deployProcessDefinition(pd);
                       }else if(resource.toUpperCase().endsWith(".PAR")) {
                       pad.deployResource(resource);
                       }
                      
                      jbpmSession.commitTransaction();


                      -Britt