11 Replies Latest reply on May 5, 2015 11:44 AM by awizenm

    Services: Second Task not created

    jimmy001

      Hi,

       

      yesterday I realized, that after completion of the first task in a process instance the second task in the process model is never created.

      Attaching a task lifecycle listener showed, that it is never started. Some posts at stackoverflow mention, that the human task handler got lost causing the problem.

      java - Workflow not forwarding after user task in jbpm5 - Stack Overflow

       

      I am using the service api and the docs state "If you use this approach, there is no need to register the Task Service with the Process Engine".

      @Stateless
      public class TaskService {
         
          @Inject
          CommandBasedTaskService taskServiceJbpm;
      
      
           public Task complete(long taskId, String userId, Map<String, Object> details) {
                taskServiceJbpm.complete(taskId, userId, details);
           }
      }
      

       

      My question:

      When using the service API (CDI), what could be a possible cause for this problem?

      Thx

        • 1. Re: Services: Second Task not created
          awizenm

          Hi Jimmy,

           

          how do you execute your process?

          Have you tried to execute and validate your process step by step in a JUnit test? 

           

          Michael

          • 2. Re: Services: Second Task not created
            jimmy001

            I have debugged the code but couldn't find any code, that would trigger a new task.

            So I have taken a second look at the user guide. A problem might have been , that I injected TaskService and not UserTaskService.

            I changed that, but now I have the problem, that no data is written to "AuditTaskImpl" and consequently "getTaskInstanceById" fails.

            • 3. Re: Services: Second Task not created
              jimmy001

              Well it is solved. I missed to add the follwing lines in the enviroment Producer:

               

               
              @Named("Logs")
              public TaskLifeCycleEventListener produceTaskAuditListener() {
              return new JPATaskLifeCycleEventListener(true);
              


              • 4. Re: Services: Second Task not created
                franco80

                Hi Jimmy

                 

                I checked that solution (adding @Produces ofcourse) and with @Inject UserTaskService us and yes, now I can see new rows in database but still next task is not created, in your environment it is working ?

                • 5. Re: Services: Second Task not created
                  jimmy001

                  What do you mean by "next task is not created" ? There are rows in the database in table "Task". (I am using the "evaluation" process from kie workbench, so I get two rows).

                  So I would say "Yes, it works". Or do you mean that the rows are not in your query result when fetching it from the database?

                  • 6. Re: Services: Second Task not created
                    franco80

                    I mean in database I don't have second task, it's not created after finishing first task. (First task have status Completed), but second is missing.

                    • 7. Re: Services: Second Task not created
                      awizenm

                      It took me a while to get to this point.... When executing my process in the test there were no problems with the creation of subsequent task.

                       

                      When executing in the application code NO subsequent task is created!

                       

                      What I do is just to complete the task using the task service:

                       

                      Map<String, Object> results = new HashMap<String, Object>();
                      results.put("nextUser", "userB");
                      results.put("userAction", "goAhead");
                      taskService.complete(taskSummary.getId(), "userA", results);
                      

                       

                       

                      As I said: the same thing is working in the test!

                       

                      Adding the TaskLifeCycleEventListener producer does not help in my case.

                       

                       

                      Are there new insights regarding this issue?

                       

                      jimmy001

                      Could you please publish your environment producer?

                      • 8. Re: Services: Second Task not created
                        jimmy001

                        Hi,

                         

                        it might be necessary to use the class "UserTaskService" and NOT "TaskService".

                        A working producer  in one of my test projects is:

                         

                        /**
                         * CDI Bean acting as producer for jbpm.
                         * 
                         *
                         */
                        @ApplicationScoped
                        public class EnvironmentProducer {
                         
                         /** Default-Logger */
                         private static final Logger LOG = LoggerFactory.getLogger(EnvironmentProducer.class);
                         /** JBPM Persistence */
                         @PersistenceUnit(unitName = "org.jbpm.domain")
                         private EntityManagerFactory emf; 
                         @Inject
                            @Selectable
                            private UserGroupInfoProducer userGroupInfoProducer;
                          
                         @Inject
                         @Kjar
                         private DeploymentService deploymentService;
                         
                         @Inject
                         private InjectableRegisterableItemsFactory  factory;
                         /** Initializes runtime enviroment and manager for injection */
                         @PostConstruct
                         public void init() {      
                          LOG.debug("Init Enviroment");        
                         }
                         /** CDI Producer */
                         @Produces
                         public EntityManagerFactory getEntityManagerFactory() {
                          return this.emf;
                         } 
                         
                         @Produces
                         public DeploymentService getDeploymentService()
                         {
                          return deploymentService;
                         }
                         
                         @Produces
                            public UserInfo produceUserInfo() {
                                return userGroupInfoProducer.produceUserInfo();
                            }   
                         /** CDI Producer */
                         @Produces
                         public IdentityProvider produceIdentityProvider() {
                          LOG.debug("Produce IdentityProvider");
                          return new IdentityProvider() {
                           @Override
                           public String getName() {
                            // TODO Auto-generated method stub
                            LOG.debug("Identprovider.getname");
                            return "schuster";
                           }
                           @Override
                           public List<String> getRoles() {
                            LOG.debug("Identprovider.roles");
                            return new ArrayList<String>();
                           }
                           @Override
                           public boolean hasRole(String role) {
                            LOG.debug("Identprovider.hasRole");
                            return true;
                           }
                           // implement IdentityProvider
                          };
                         }
                         
                         @Produces
                         @Selectable
                         public UserGroupInfoProducer getUserGroupInfoProducer(){
                          return new DemoUserGroupInfoProducer();
                         }
                         
                         @Produces
                            @Named("Logs")
                            public TaskLifeCycleEventListener produceTaskAuditListener() {
                                return new JPATaskLifeCycleEventListener(true);
                            }
                         /** CDI Producer  not used by services so.. not relevant at the moment*/
                        // @Produces
                        // @Singleton
                        // @PerRequest
                        // @PerProcessInstance
                         public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf) {  
                          LOG.debug("Produce Environment");
                          RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
                            .newDefaultBuilder()      
                            .entityManagerFactory(emf)
                            .registerableItemsFactory(factory)          
                            .get();
                          LOG.error("Drools process instance manager Factory value => ");
                          LOG.error(environment.getConfiguration().getProperty("drools.processInstanceManagerFactory"));  
                          return environment;
                         }
                        }
                        
                        • 9. Re: Services: Second Task not created
                          awizenm

                          Thank you Jimmy for your quick response.

                           

                          I followed your suggestion and have injected UserTaskService into my service.

                           

                          Unfortunately it doesn't help immediately. Now when executing

                           

                          userTaskService.complete(taskSummary.getId(), "userA", results);
                          

                           

                          happens .... nothing

                           

                          After taking a deeper look into the code I have discovered that the injected UserTaskServiceCDIImpl can not find the RuntimeManager....

                           

                          And this is probably a problem of wrongly configured deployment service...

                           

                           

                          I will open a new discussion for this...

                           

                           

                          By the way this is my current RuntimeEnvironment producer.

                           

                          @Produces
                          @Singleton
                          @PerRequest
                          @PerProcessInstance
                          public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf) {
                          
                              Environment env = EnvironmentFactory.newEnvironment();
                              env.set(EnvironmentName.TRANSACTION_MANAGER, new ContainerManagedTransactionManager());
                              env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
                          
                              JpaProcessPersistenceContextManager jpaProcessPersistenceContextManager = new JpaProcessPersistenceContextManager(env);
                              JPATaskPersistenceContextManager jpaTaskPersistenceContextManager = new JPATaskPersistenceContextManager(env);
                          
                              env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, jpaProcessPersistenceContextManager);
                              env.set(EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER, jpaTaskPersistenceContextManager);
                          
                              RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback())
                                      .addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, new ContainerManagedTransactionManager())
                                      .addEnvironmentEntry(EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER, jpaTaskPersistenceContextManager)
                                      .addEnvironmentEntry(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, jpaProcessPersistenceContextManager).entityManagerFactory(emf).registerableItemsFactory(factory)
                                      .addAsset(ResourceFactory.newClassPathResource("myProcess.bpmn"), ResourceType.BPMN2).get();
                          
                              return environment;
                          }
                          
                          • 10. Re: Services: Second Task not created
                            jimmy001

                            Hi,

                             

                            you are going a different approach. I am solely relying on the service api. I never call a runtime manger directly.I just use deploymentservice etc. . In this case the runtimeenviroment is created in "deployment services" and never from a CDI Producer (that is the reason, why I completly removed the annotations in the code above.. just to make sure I am not missing something).

                            • 11. Re: Services: Second Task not created
                              awizenm

                              Hi, this is what I slowly begin to understand That mixing of the two approaches does not work.

                               

                              Have you seen my latest two discussions I have opened? Could help me with those?

                               

                              Do the service api always rely on maven? Have you discovered a way for starting a process developed in the BPMN2 Modeler?