[jboss-user] [jBPM] - Handle Human Task with custom HumanTaskHandler

Laura delli Paoli do-not-reply at jboss.com
Tue Nov 27 05:47:09 EST 2012


Laura delli Paoli [https://community.jboss.org/people/lauradp] created the discussion

"Handle Human Task with custom HumanTaskHandler"

To view the discussion, visit: https://community.jboss.org/message/778526#778526

--------------------------------------------------------------
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....");
          }


}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/778526#778526]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20121127/7290a06f/attachment-0001.html 


More information about the jboss-user mailing list