6 Replies Latest reply on Apr 26, 2014 1:42 PM by 其凡 莫

    Continue Previous Process Instance

    TC ONG Newbie

      I am using Drools 5.4 and jbom 5.3.

      I am using perisitance.

      I run my apps in Tomcat + Spring + Hibernate.

       

      I started with:

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

      ProcessInstance processInstance = ksession.startProcess(processName, processVariables);

      these works.

       

      Then I try:

      ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env );

      int processInstancesSize = ksession.getProcessInstances().size();     // = 0

       

      at this stage ksession.getProcessInstances() is empty.

      So how can I continue my processInstance?

      How to do it?

      Any example?

      I'll search around the github, but any help will be great.

      Thanks.

        • 1. Re: Continue Previous Process Instance
          TC ONG Newbie

          Found these on GitHub:

          https://github.com/droolsjbpm/jbpm/blob/master/jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/processinstance/ProcessInstanceResolverStrategyTest.java

           

          May be I have to recreate the processInstance with the id i have. Will tell you the outcome.

              @Test
              public void testWithDatabaseAndStartProcessInstance() throws Exception {
                  // Create variable
                  Map params = new HashMap();
                  NonSerializableClass processVar = new NonSerializableClass();
                  processVar.setString("1234567890");
                  params.put(VAR_NAME, processVar);
              
                  // Persist variable
                  UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
                  ut.begin();
                  EntityManagerFactory emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
                  EntityManager em = emf.createEntityManager();
                  em.setFlushMode(FlushModeType.COMMIT);
                  em.joinTransaction();
                  em.persist(processVar);
                  em.close();
                  ut.commit();
              
                  // Create process,
                  ProcessInstance processInstance = ksession.createProcessInstance(PROCESS_ID, params);
                  long processInstanceId = processInstance.getId();
                  Assert.assertTrue(processInstanceId > 0);
                  Assert.assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
                  
                  // insert process,
                  ksession.insert(processInstance);
             
                  // and start process
                  ksession.startProcessInstance(processInstanceId);
                  ksession.fireAllRules();
              
                  // Test results
                  processInstance = ksession.getProcessInstance(processInstanceId);
                  Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
                  processVar = (NonSerializableClass) ((WorkflowProcessInstance) processInstance).getVariable(VAR_NAME);
                  Assert.assertNotNull(processVar);
              }
          • 2. Re: Continue Previous Process Instance
            TC ONG Newbie

            Nope. that is not what I want. Question: when we call

            JPAKnowledgeService.loadStatefulKnowledgeSession(...)

            does it also load the processinstances of the knowledgeSession from the database?

            I can see records created in processinstanceinfo table but...  

            • 3. Re: Continue Previous Process Instance
              marcosdutto Newbie

              Did you find any solution for this problem?

               

              Thanks

              • 4. Re: Continue Previous Process Instance
                hansi007 Newbie

                Hi there. I Think I had the same problem you have (but with jBPM 5.2). I used to following workaround:

                 

                  ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, config, env );
                                              registerWorkItemHandlersAndEventListeners();
                                              initPersistenceLogger();
                                              if(workitemId != -1){
                                                        WorkItemManager wManager =  ksession.getWorkItemManager();
                                                        wManager.completeWorkItem(workitemId,null);
                                              }
                

                 

                So i had to store the sessionId and the actual workItemId.

                • 5. Re: Continue Previous Process Instance
                  Esteban Aliverti Master

                  As far as I remember, ksession.getProcessInstances() ALWAYS returns an empty list when you are using persistence. The idea is not to get all the instances from the DB since you could have a lot of them.

                  If you want to continue the execution of a previous instance you don't need (most of the times) the id of the process, what you need to do is execute the action the instance is waiting for: complete a User Task, complete a Work Item or signal an event.

                   

                  Best Regards,

                  • 6. Re: Continue Previous Process Instance
                    其凡 莫 Newbie

                    but how can i get all the process Id in jbpm if i want ? i want to monitor all the process so i want to get the process id list

                    i hava see a lot of topic here someone say we can use history log but i dont know how to do it? can you help me ?