11 Replies Latest reply on Sep 13, 2011 2:01 PM by Francesco Pietrobelli

    Basic API Question

    Diogo Saad Newbie

      Hello Folks,


      What's the API to detect in which Node from the Workflow a processInstance curently is?




        • 1. Re: Basic API Question
          Francesco Pietrobelli Newbie

          Hi Diogo,

          you can use the method

          Collection<NodeInstance> getNodeInstances()


          for example:

          import org.jbpm.workflow.instance.WorkflowProcessInstance;
          WorkflowProcessInstance processInstance=(WorkflowProcessInstance)ksession.startProcess("processId");
          Collection<NodeInstance> currentNodeInstances=processInstance.getNodeInstances();


          in collection currentNodeInstances you'll find all active nodes of processInstance!


          I have answered your question?


          • 2. Re: Basic API Question
            Mauricio Salatino Master

            a more basic question is why do you need that?

            We usually try to avoid doing that...


            • 3. Re: Basic API Question
              Diogo Saad Newbie

              For reporting, I would like to list all process instances that I have and which status it has, along with "where" (node) they are stopped.


              Do you suggest another way of doing this?

              Why do you usually avoid it?




              • 4. Re: Basic API Question
                Francesco Pietrobelli Newbie

                If you enable persistence and BAM feature as explain in user guide (http://docs.jboss.org/jbpm/v5.1/userguide/ch07.html#d0e2836) you can query your database to retrieve all NodeInstanceLog that has an entry with type = 0 but not his related entry with type = 1.



                • 5. Re: Basic API Question
                  Diogo Saad Newbie

                  Nice!! I've read the ch07 but I could not find examples on how to retrieve the ProcessInstanceLog/NodeInstanceLog objects. Can you please provide examples?



                  • 6. Re: Basic API Question
                    Francesco Pietrobelli Newbie

                    You can use the EntityManagerFactory that you put in the Enviroment to create a SteatefulKnowledgeSession to get an EntityManager and create a query like

                    SELECT n FROM org.jbpm.process.audit.NodeInstanceLog WHERE ...

                    • 7. Re: Basic API Question
                      Demian Calcaprina Master



                      You can check how it is used in console:



                      Or for example this test:



                      Basically, you create a logger to save information in bam tables:

                      new JPAWorkingMemoryDbLogger(session);


                      and then you can use a


                      JPAProcessInstanceDbLog processLog = new JPAProcessInstanceDbLog(session.getEnvironment());


                      to get the information with its methods:









                      • 8. Re: Basic API Question
                        Mauricio Salatino Master

                        I usually recommend to use the history logs or a custom processEventListner to find out that information. Using the java apis will probably not give you enough flexibility to have a query mechanism for all the situations.


                        • 9. Re: Basic API Question
                          Diogo Saad Newbie

                          I'm trying to follow the path indicated by Demian (save and retrieve information from BAM tables) but I simply can not make persistence work.

                          I get this exception where I try to excute the following junit test :



                                              SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();


                                                // Construct DataSource

                                              JdbcDataSource ds = new org.h2.jdbcx.JdbcDataSource();




                                               builder.bind("jdbc/DataSource", ds);



                                              Environment env = KnowledgeBaseFactory.newEnvironment();

                                              env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"));

                                              env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );

                                              session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);




                          Caused by: java.lang.reflect.InvocationTargetException

                                    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                                    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

                                    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

                                    at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:116)

                                    ... 33 more

                          Caused by: java.lang.RuntimeException: Could not commit session or rollback

                                    at org.drools.persistence.SingleSessionCommandService.rollbackTransaction(SingleSessionCommandService.java:317)

                                    at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:130)

                                    ... 38 more

                          Caused by: java.lang.RuntimeException: Unable to rollback transaction

                                    at org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:189)

                                    at org.drools.persistence.SingleSessionCommandService.rollbackTransaction(SingleSessionCommandService.java:314)

                                    ... 39 more

                          Caused by: java.lang.NullPointerException

                                    at org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:185)



                          Please find attached my persistence.xml file



                          What am I missing?




                          • 10. Re: Basic API Question
                            Demian Calcaprina Master

                            I am not sure which transaction-type is default, but could you try adding transaction-type="JTA" to your persistence.xml?

                            • 11. Re: Basic API Question
                              Francesco Pietrobelli Newbie

                              I also haven't no idea!

                              maybe if you are in a Java Standard Edition environment you should set also the TransactionManager in environment and then handle the transaction boundary your self as explain in user guide (http://docs.jboss.org/jbpm/v5.1/userguide/ch07.html#d0e2820). Instead if you are in Java Enterprise Edition i haven't any suggestion...


                              I have used bitronix 1.3.3 in SE!


                              Of course your problem is related to transactions....