5 Replies Latest reply on Dec 20, 2012 2:02 AM by Maciej Swiderski

    How can i get the task id ?

    pichunhan pi Newbie

      in my project , i used the jbpm 5.2.

      when i excute the

                     ksession.startProcess("com.sample.evaluation", params);

      the task is persisted in the DB, i aslo want to get the task id from this method return.

       

      how can i do to get this task id .

       

      thanks for u help , and very sorry for my english .

        • 1. Re: How can i get the task id ?
          pichunhan pi Newbie

          could any one help me ?

          • 2. Re: How can i get the task id ?
            Maciej Swiderski Master

            to achieve this you would need to extend existing HT work item handler and pass an AddTaskResponseHandler implementation when invoking addTask on taskClient. That way task service will emit and event when task was successfully created. Take a look at the sample code here

             

            HTH

            • 3. Re: How can i get the task id ?
              pichunhan pi Newbie

              Hi ! could you help me for some questions ?

              How can i get the task id when started a process

               

              in my project i use  this code to do the job.

               

               

               

              package com.sample;

               

               

              import java.util.HashMap;

              import java.util.Map;

               

               

              import org.drools.KnowledgeBase;

              import org.drools.builder.KnowledgeBuilder;

              import org.drools.builder.KnowledgeBuilderFactory;

              import org.drools.builder.ResourceType;

              import org.drools.io.ResourceFactory;

              import org.drools.logger.KnowledgeRuntimeLogger;

              import org.drools.logger.KnowledgeRuntimeLoggerFactory;

              import org.drools.runtime.StatefulKnowledgeSession;

              import org.jbpm.process.workitem.wsht.BlockingGetTaskResponseHandler;

              import org.jbpm.process.workitem.wsht.HornetQHTWorkItemHandler;

              import org.jbpm.task.service.SyncTaskServiceWrapper;

              import org.jbpm.task.service.hornetq.AsyncHornetQTaskClient;

              import org.jbpm.task.service.responsehandlers.BlockingTaskOperationResponseHandler;

              import org.jbpm.task.service.responsehandlers.BlockingTaskSummaryResponseHandler;

               

               

              /**

              * This is a sample file to launch a process.

              */

              public class ProcessTest {

               

               

                        public static final void main(String[] args) {

                                  try {

                                            // load up the knowledge base

                                            KnowledgeBase kbase = readKnowledgeBase();

                                            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                                            HornetQHTWorkItemHandler sHumanTaskHandler = new HornetQHTWorkItemHandler(ksession);

                                            ksession.getWorkItemManager().registerWorkItemHandler("Human Task",

                                                                sHumanTaskHandler);

                                            SyncTaskServiceWrapper sTaskService = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient(

                                                                "HumanTaskExample-testClient"));

                                            sTaskService = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient(

                                                                "HumanTaskExample-testClient"));

                                            sTaskService.connect("127.0.0.1", 5445);

                                            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);

                                            // start a new process instance

                                            BlockingTaskSummaryResponseHandler taskSummaryResponseHandler =

                                                                new BlockingTaskSummaryResponseHandler();

                                            BlockingTaskOperationResponseHandler responseHandler =

                                                                new BlockingTaskOperationResponseHandler();

                                            BlockingGetTaskResponseHandler getTaskResponseHandler = new BlockingGetTaskResponseHandler();

                                            Map<String, Object> params = new HashMap<String, Object>();

                                            params.put("employee", "111");

                                            params.put("reason", "Yearly performance evaluation");

                                            ksession.startProcess("com.sample.evaluation", params);

                                            System.out.println("Process started ...");

                                            logger.close();

                                  } catch (Throwable t) {

                                            t.printStackTrace();

                                  }

                        }

               

               

                        private static KnowledgeBase readKnowledgeBase() throws Exception {

                                  KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                                  kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);

                                  return kbuilder.newKnowledgeBase();

                        }

               

               

              }

               

               

               

              when i user the ksession.startProcess("com.sample.evaluation", params); to start a process, the task is persisted in the DB , for this ,i also want to get the task id ,but these nothing return to get it.

              how can i do ?

              • 4. Re: How can i get the task id ?
                pichunhan pi Newbie

                I know that ,when i used the mina to client the server , i can use the AddTaskResponseHandler to get the task id ,but when i use the AsyncHornetQTaskClient, how can i do to get the task id ?

                • 5. Re: How can i get the task id ?
                  Maciej Swiderski Master

                  you need to register for events using taskService.registerForEvent method. So in your case it should be something like this

                   

                          TaskAddedHandler eventResponseHandler = new TaskAddedHandler (...);

                          TaskEventKey key = new TaskEventKey(TaskCreatedEvent.class, -1);

                          sTaskService.registerForEvent(key, false, eventResponseHandler);

                   

                  please note this is pseudo code so needs to be slightly adjusted

                   

                  HTH