9 Replies Latest reply on Nov 27, 2012 6:42 AM by Laura delli Paoli

    Handle Human Task with custom HumanTaskHandler

    Laura delli Paoli Master

      Hello everybody,

      I was trying to run a human task with a custom handler, but my handler doesn't work.

      Can anyone help me?

       

      Laura

       

       

      public class TestHumanTask {

       

       

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

                          startUp();

                          // load up the knowledge base

                          KnowledgeBase kbase = readKnowledgeBase();

                          StatefulKnowledgeSession ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);

                          //StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                          CommandHumanTaskHandler handler = new CommandHumanTaskHandler();

                          ksession.getWorkItemManager().registerWorkItemHandler("RunAction", handler);

                          //params

       

                          // start a new process instance

                          ksession.startProcess("com.sample.bpmn.hello");

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

                }

       

       

                private static KnowledgeBase readKnowledgeBase() throws Exception {

                          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

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

                          return kbuilder.newKnowledgeBase();

                }

       

                private static void startUp() {

                          JBPMHelper.startH2Server();

                          JBPMHelper.setupDataSource();

                          // please comment this line if you already have the task service running,

                          // for example when running the jbpm-installer

                          JBPMHelper.startTaskService();

                }

       

      }

       

      public class CommandHumanTaskHandler extends HumanTaskHandler{

       

       

                private static final long serialVersionUID = 1L;

       

                public CommandHumanTaskHandler () {

                          super();

                          System.out.println("NEW");

                }

       

                public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

                          //super.executeWorkItem(workItem, manager);

                          System.out.println("executing....");

                          manager.completeWorkItem(workItem.getId(), null);

                }

       

                public void complete(WorkItem workItem,  Map<String,Object> results){

                          System.out.println("Completing...");

       

                          //super.complete(workItem, results);

                }

       

       

                @Override

                public void abortWorkItem(WorkItem arg0, WorkItemManager arg1) {

                          // TODO Auto-generated method stub

                          System.out.println("Aborting....");

                }

       

       

      }