13 Replies Latest reply on Jan 3, 2014 8:02 AM by Fer Gia

    Update ProcessInstanceLog using TaskService in JBPM6?

    Fer Gia Newbie

      Hi all!!

       

      I want to update the PROCESSINSTANCELOG table when each task in the workflow has completed.

      Also, when the process is completed it isnt marked in that table.

       

      When i create the new process, this log is working ok. Im doing this:

      RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
      KieSession session = engine.getKieSession();
      new JPAWorkingMemoryDbLogger(session);
      session.startProcess(...);
      ....
      
      
      
      

       

      In that case the records in the PROCESSINSTANCELOG and VARIABLEINSTANCELOG are created ok.

       

      But when I complete the task inside the process, the records is never updated, even if the process finish.

       

      Im doing this:

       

      RuntimeEngine engine =runtimeManager.getRuntimeEngine(ProcessInstanceIdContext
        .get(processInstanceId));
      KieSession session = engine.getKieSession();
      new JPAWorkingMemoryDbLogger(session);
      TaskService taskService= engine.getTaskService();
      taskService.completeTask(...);
      ...
      
      
      
      

       

      The PROCESSINSTANCELOG record is never marked with an End Date and the VARIABLEINSTANCELOG table is neither updated, just created

       

      What Im doing wrong?

       

      Thanks!!!

        • 1. Re: Update ProcessInstanceLog using TaskService in JBPM6?
          Maciej Swiderski Master

          not sure how exactly you create runtime manager but when default builder is used the JPA logger is already attached to it so no need to add that manually. So try to remove the logger you added on ksession and rely on what runtime manager provides by default.

           

          What might be useful is to configure hibernate to print out sql statements so we could see what is actually done on these operations.

           

          HTH

          • 2. Re: Update ProcessInstanceLog using TaskService in JBPM6?
            Fer Gia Newbie

            Hi Maciej, thanks for the reply.

             

            If I remove the new JPAWorkingMemoryDbLogger(session); line, no records are inserted in LOG tables at all.

             

            Im injecting the RuntimeManager like this:

            @Inject

            @PerProcessInstance

            private RuntimeManager runtimeManager;

             

            The problem is when I use the TaskService. All TaskService mothods incovations dont write in the LOG tables

             

            Greetings!

            • 3. Re: Re: Update ProcessInstanceLog using TaskService in JBPM6?
              Fer Gia Newbie

              Any ideas the reason that I cant do this work ?

              • 4. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                Fer Gia Newbie

                Anyone? I tried anything and no results...

                • 5. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                  bpmn2user Expert

                  Do you want to provide the complete test code so that one can try to reproduce the same error?

                  Here is a simple example (jBPM6 - Task Persistence Example) where you can see the data persisted in PROCESSINSTANCELOG table. As Maciej has mentioned, it does not use JPA logger.

                  • 6. Re: Re: Update ProcessInstanceLog using TaskService in JBPM6?
                    Fer Gia Newbie

                    Hi!

                    Thanks for reply!

                    I will post more information:

                    persistence.xml:

                    <persistence-unit name="jbpm.persistence.unit">
                    
                    
                      <description>Persistense Configuration</description>
                      <jta-data-source>jndiName</jta-data-source>
                    
                    
                      <mapping-file>META-INF/JBPMorm.xml</mapping-file>
                      <mapping-file>META-INF/Taskorm.xml</mapping-file>
                    
                      <class>org.jbpm.services.task.impl.model.AttachmentImpl</class>
                         <class>org.jbpm.services.task.impl.model.ContentImpl</class>
                         <class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class>
                         <class>org.jbpm.services.task.impl.model.CommentImpl</class>
                         <class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
                         <class>org.jbpm.services.task.impl.model.DelegationImpl</class>
                         <class>org.jbpm.services.task.impl.model.EscalationImpl</class>
                         <class>org.jbpm.services.task.impl.model.GroupImpl</class>
                         <class>org.jbpm.services.task.impl.model.I18NTextImpl</class>
                         <class>org.jbpm.services.task.impl.model.NotificationImpl</class>
                         <class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class>
                         <class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class>
                         <class>org.jbpm.services.task.impl.model.PeopleAssignmentsImpl</class>
                         <class>org.jbpm.services.task.impl.model.ReassignmentImpl</class>
                         <class>org.jbpm.services.task.impl.model.TaskImpl</class>
                         <class>org.jbpm.services.task.impl.model.TaskDefImpl</class>
                         <class>org.jbpm.services.task.impl.model.TaskDataImpl</class>
                         <class>org.jbpm.services.task.impl.model.UserImpl</class>
                         <class>org.jbpm.executor.entities.ErrorInfo</class>
                         <class>org.jbpm.executor.entities.RequestInfo</class>
                         
                         <!--BAM for task service -->
                         <class>org.jbpm.services.task.impl.model.BAMTaskSummaryImpl</class>
                         <!-- Event Classes -->
                         <class>org.jbpm.services.task.audit.TaskEventImpl</class>
                         
                         <class>org.drools.persistence.info.SessionInfo</class>
                         <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
                         <class>org.drools.persistence.info.WorkItemInfo</class>
                         <class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>
                         <class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>
                         <!-- manager -->
                         <class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>
                         
                         <!-- bam -->
                         <class>org.jbpm.process.audit.ProcessInstanceLog</class>
                         <class>org.jbpm.process.audit.NodeInstanceLog</class>
                         <class>org.jbpm.process.audit.VariableInstanceLog</class>
                    
                    
                      <exclude-unlisted-classes>true</exclude-unlisted-classes>
                      <properties>
                      <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                      <property name="hibernate.show_sql" value="true" />
                      <property name="hibernate.format_sql" value="${filter.db.format_sql}" />
                      </properties>
                      </persistence-unit>
                    

                     

                    Producer Class:

                    @Produces
                    @PerProcessInstance
                    public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf) {
                     RuntimeEnvironment environment = RuntimeEnvironmentBuilder
                      .getDefault()
                      .entityManagerFactory(emf)
                      .userGroupCallback(usergroupCallback)
                      .registerableItemsFactory(factory)
                      .addAsset(
                      ResourceFactory
                      .newClassPathResource("rprocess.bpmn").get();
                      return environment;
                      }
                    
                    @Produces
                      public EntityManagerFactory produceEntityManagerFactory() {
                      if (this.emf == null) {
                      this.emf = Persistence
                      .createEntityManagerFactory("jbpm.persistence.unit");
                      }
                      return this.emf;
                      }
                    

                     

                    Service class

                    @Inject
                    @PerProcessInstance
                    private RuntimeManager runtimeManager;
                    
                      @Override
                      public void startProcess(String processId,Map<String,Object> params)
                      throws Exception {
                         RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
                         KieSession session = engine.getKieSession();
                    
                    
                         //If I remove this next line nothing is logged in any log table
                         new JPAWorkingMemoryDbLogger(session);
                    
                         session.startProcess(processId,  params);
                      }
                    
                    
                    @Override
                      public void cancelProcess(Long processInstanceId) throws Exception {
                         RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
                         KieSession session = engine.getKieSession();
                    
                          //If I remove this next line nothing is logged in any log table
                         new JPAWorkingMemoryDbLogger(session);
                         session.abortProcessInstance(processInstanceId);
                      }
                    
                    @Override
                      public void startHumanTask(Long taskId, String user) throws Exception {
                           RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
                           TaskService taskService=  engine.getTaskService();
                           taskService.claim(taskId, user);
                           taskService.start(taskId, user);
                      }
                    
                    
                    @Override
                      public void completeHumanTask(Long taskId, String user,Map<String,Object> params) throws Exception {
                           RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
                           TaskService taskService=  engine.getTaskService();
                           taskService.complete(taskId, user,params);
                      }
                    

                     

                     

                    One more clue:

                    When I call the "cancelProcess" method, the PROCESSINSTANCELOG table is updated. I thik thath the log tables only are written where the ksession is invoked

                     

                    Thanks!

                    • 7. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                      Fer Gia Newbie

                      Hi!

                      I tried replacing the runtimeEngine.getTaskService() by injecting:

                      @Inject

                      private TaskInstanceService taskInstanceService;

                       

                      But the results are exactly the same

                      • 8. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                        Maciej Swiderski Master

                        that is entirely correct, information are written into ProcessInstanceLog only when process instance is changed and that is done over ksession operations. So if you only use TaskService that table won't be populated. Although when taskService.complete() is invoked it will (if properly configured) trigger an event that will cause process instance to move forward and thus update processinstancelog.

                         

                        btw, please use TaskService only and not TaskInstanceService as the TaskInstanceService is an internal implementation that is not intended to be used from client code.

                         

                        HTH

                        • 9. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                          Fer Gia Newbie

                          Endeed, the TaskInstanceService was only a test

                           

                          You say that "information are written into ProcessInstanceLog only when process instance is changed"

                          But if I call taskService.complete(), and that task is the last of the process, the log tables dont change neither with the process end.

                           

                          My problem is that I need to know the value of a process variable that change with every task end. While the process is alive, i can access thought the process instance variables. But when the process is finish the only way to get the variable value is using the log tables. If that log tables are'nt updated when the process finish, that process variable I need to read is out of date.

                          • 10. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                            Maciej Swiderski Master

                            oh, in that case it looks like the process instance is not triggered and actually not completed. Is that what you see? Or it is but it does not have the right listeners registered when you complete the task. Do you use any custom implementation of RegisterableItemsFactory? That might not register the right listeners on process and handlers?

                             

                            HTH

                            • 11. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                              Fer Gia Newbie

                              Im using an InjectableRegisterableItemsFactory instance like that (I forget to include in the code above)


                              @Inject
                              private InjectableRegisterableItemsFactory factory;
                              
                              @Produces
                              @PerProcessInstance
                                public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf) {
                                RuntimeEnvironment environment = RuntimeEnvironmentBuilder
                                .getDefault()
                                .entityManagerFactory(emf)
                                .userGroupCallback(usergroupCallback)
                                .registerableItemsFactory(factory)
                                .addAsset(ResourceFactory.newClassPathResource("process.bpmn").get();
                                return environment;
                                }
                              


                              When the last task is completed the ProcessIntanceInfo and the other process tables are cleaned normally, so the process is finished correctly. Also in the process life (when each task is completed) I dont see any changes in the VARIABLEINSTANCELOG table.

                              Im sure that i miss setting something but I don't know what...

                              • 12. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                                Maciej Swiderski Master

                                Alright, when using InjectableRegisterableItemsFactory it's better to make use of the factory methods of that class instead of injecting it as by that you can provide the audit logger implementation to be used:

                                 

                                https://github.com/droolsjbpm/jbpm/blob/master/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/cdi/InjectableRegisterableItemsFactory.java#L220

                                 

                                To get the logger implementation you this factory and you're most likely interested in the JPA based one so just pass the emf into the factory and you should have ready to use audit logger that should be given to the getFactory method of InjectableRegisterableItemsFactory.

                                 

                                HTH

                                • 13. Re: Update ProcessInstanceLog using TaskService in JBPM6?
                                  Fer Gia Newbie

                                  Cool! It works very nice.

                                  Thank you very much. It clean a lot all my hardcoded code taking the values of the process variables instead class variables!

                                   

                                  Thanks!