JBoss Community

Re: How can i get the task id ?

created by pichunhan pi in jBPM - View the full discussion

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 ?

Reply to this message by going to Community

Start a new discussion in jBPM at Community