1 Reply Latest reply on Nov 9, 2012 8:30 AM by joploya

    Human task : assign the good task to the launcher of a processInstance

    joploya Newbie

      Hello,

       

      I have a confusion between the processInstance and the Task with Jbpm5.

       

      My scenario is as explain bellow :

      N_PL.png

      1/ A user enters in the application and starts a new processInstance of a jbpm process.

                                      ProcessInstance process = ksession.startProcess("com.st.ams.flow.npl", params);
                                      System.out.println("process = "+process.getProcessId()+" : "+process.getProcessName()+" : state("+process.getState()+")");
      

      2/ A new task is created in the database in the state Ready with the name "startNPLRequest_PM_PL", and with this code I am abble to see that my user can claim this task and complete it :

                                      //Now the PM_PL process his task (it is already complete in reality)
                                    List<String> groups = new ArrayList<String>();
                                    groups.add(requestor.getRole());
                                    System.out.println("Groups : ");
                                    for(String grp : groups){
                                              System.out.println(" - "+grp);
                                    }
        
                                    BlockingTaskSummaryResponseHandler taskSummaryResponseHandler = new BlockingTaskSummaryResponseHandler();
                                    amsKnowledgeSession.getClient().getTasksAssignedAsPotentialOwner(requestor.getName(), groups, "en-UK", taskSummaryResponseHandler);
                                    List<TaskSummary> potentialTasks = taskSummaryResponseHandler.getResults();
                                    for(TaskSummary task : potentialTasks){
                                              System.out.println("PM_PL can execute task " + task.getName() + " (" + task.getId() + " : " + task.getDescription() + ")");
                                    }
      
      

      3/ The problem is that several users with the role PM_PL will launch this process at the same time, so how can I assign the good task (of the good process but I know the processId) to my user?

           I have not find the link between processId and taskId. And I need the taskId to start the task :

                          amsKnowledgeSession.getClient().start( taskId, requestorId, taskSummaryResponseHandler );
      

       

      In the documentation we have this explanation but I don't really understand it :

      // adding a task

      BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();

      Task task = ...;

      client.addTask( task, null, addTaskResponseHandler );

      long taskId = addTaskResponseHandler.getTaskId();

      It must be a very simple question but I will be very happy if someone can explain me this concept.

       

      Regards,

        • 1. Re: Human task : assign the good task to the launcher of a processInstance
          joploya Newbie

          I think I find a way to retrieve the good task for my Requestor, but an upstream problem appears :

           

          First the way to start the good task :

           

                                         //Now the PM_PL process his task (it is already complete in reality)
                                        List<String> groups = new ArrayList<String>();
                                        groups.add(requestor.getRole());
                                        System.out.println("Groups : ");
                                        for(String grp : groups){
                                                  System.out.println(" - "+grp);
                                        }
            
                                        BlockingTaskSummaryResponseHandler taskSummaryResponseHandler = new BlockingTaskSummaryResponseHandler();
                                        amsKnowledgeSession.getClient()
                                                                                          .getTasksAssignedAsPotentialOwner(requestor.getName(), groups, "en-UK", taskSummaryResponseHandler);
                                        List<TaskSummary> potentialTasks = taskSummaryResponseHandler.getResults();
                                        TaskSummary requestorTask = null;
                                        for(TaskSummary task : potentialTasks){
                                                  System.out.println("PM_PL can execute task " + task.getName() + " (" + task.getId() + " : " + task.getDescription() + ")");
                                                  if(process.getId() == task.getProcessInstanceId()){
                                                            System.out.println("The task "+task.getId()+" "+task.getName()+" is the one the requestor have to take");
                                                            requestorTask = task;;
                                                  }
                                        }
                                        BlockingTaskOperationResponseHandler taskOperationResponseHandler = new BlockingTaskOperationResponseHandler();
                                        amsKnowledgeSession.getClient().start(requestorTask.getId(), requestor.getName(), taskOperationResponseHandler);
                                        Thread.sleep(60000);
                                        System.out.println("The PM_PL has well finish his task : call to complete");
                                        amsKnowledgeSession.getClient().complete(requestorTask.getId(), requestor.getName(), null, taskOperationResponseHandler);
          

           

          The problem now is that each task has the same processInstanceId, processSessionId and workItemId in the database. However I start a new KnowledgeSession and a new process each time :

           

                      KnowledgeBase kbase = readKnowledgeBase();
                      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
                      KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "/log/loggerFile.log", 1000);
                      HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession);
                      ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler);
                      
                      // start a new process instance
                      Map<String, Object> params = new HashMap<String, Object>();
                      params.put("userId", requestor.getName());
                      params.put("userGroup", requestor.getRole());
                      params.put("flowId", getFlowEntity().getFlowId());
            
                      ProcessInstance process = ksession.startProcess("com.st.ams.flow.npl", params);
                      System.out.println("process = "+process.getProcessId()+" : "+process.getProcessName()+" : state("+process.getState()+")");
                      SystemEventListenerFactory.setSystemEventListener(new SystemEventListener());
          

           

          If you have a little clue to help me progress...

           

          Thanks