9 Replies Latest reply on Jan 7, 2013 9:52 AM by Gareth Edwards

    jbpm-examples with jBPM 5.4

    Gareth Edwards Newbie



      Is there an updated HumanTaskExample that works with jBPM 5.4?

      The following lines either contain reomved of depricated methods.


      There must be a new way of doing this that I'm not aware of. (These lines are not together in the source code)


      contentData = ContentMarshallerHelper.marshal(results, hornetQHTWorkItemHandler.getMarshallerContext(), null);

      TaskSummary task3 = taskClient.getTasksAssignedAsPotentialOwner("john", groups, "en-UK").get(0);

      taskClient.claim(task3.getId(), "john", groups);

      contentData = ContentMarshallerHelper.marshal(results, hornetQHTWorkItemHandler.getMarshallerContext(), null);

      Object result = ContentMarshallerHelper.unmarshall("org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy",

                          content.getContent(), hornetQHTWorkItemHandler.getMarshallerContext(), null);


      Any help would be greatlt appreciated.





        • 1. Re: jbpm-examples with jBPM 5.4
          Esteban Aliverti Master

          Since jBPM5.4 the UserGroupCallback mechanism (http://docs.jboss.org/jbpm/v5.4/userguide/ch.human-tasks.html#d0e5419) is used behind the scenes to get the groups of a user. There is no need to specify the group/s in the client call anymore since you are already specifying the actor.

          It is still an open question how do you retrieve the tasks belonging to a list of groups without caring about any particular actor. 

          • 2. Re: jbpm-examples with jBPM 5.4
            Thomas Setiabudi Expert

            Hi Esteban,


            If we call the deprecated method like taskClient.getTasksAssignedAsPotentialOwner("john", groups, "en-UK")

            in JBPM5.4


            will the task server skip getting user role from UserGroupCallback?


            I kind of prefer the old way where we feed the user group list to task server since the way we get user group is not so simple.




            Thomas Setiabudi

            • 3. Re: jbpm-examples with jBPM 5.4
              Esteban Aliverti Master

              I took a brief look to the source code and it seems that the UserGroupCallback is still being called even if you specify the groups in the client call. Maybe this is the reason why jBPM team decided to remove it from the api.

              You could confirm this by debugging your UserGroupCallback implementation.


              Best Regards,

              • 4. Re: jbpm-examples with jBPM 5.4
                Thomas Setiabudi Expert

                Thanks Esteban


                I just does not understand what are the value for second and third parameter in get group for user inside UserGroupCallback.



                Thomas Setiabudi

                • 5. Re: jbpm-examples with jBPM 5.4
                  Gareth Edwards Newbie

                  Thanks Esteban. Simple case of RTFM.



                  • 6. Re: jbpm-examples with jBPM 5.4
                    doboss Newbie

                    @Gareth, is it the case for you also that the HumanTaskExample.java is showing as a compilation error in Eclipse because there is no method getMarshallerContext()?  Did you do anything to fix it or did you just ignore it?



                    • 7. Re: jbpm-examples with jBPM 5.4
                      Gareth Edwards Newbie

                      This should work:


                      package org.jbpm.examples.humantask;



                      import java.util.ArrayList;

                      import java.util.HashMap;

                      import java.util.List;

                      import java.util.Map;



                      import org.drools.KnowledgeBase;

                      import org.drools.SystemEventListenerFactory;

                      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.HornetQHTWorkItemHandler;

                      import org.jbpm.task.AccessType;

                      import org.jbpm.task.Content;

                      import org.jbpm.task.Task;

                      import org.jbpm.task.TaskService;

                      import org.jbpm.task.query.TaskSummary;

                      import org.jbpm.task.service.ContentData;

                      import org.jbpm.task.service.SyncTaskServiceWrapper;

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

                      import org.jbpm.task.utils.ContentMarshallerHelper;



                      public class HumanTaskExample {



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

                              try {

                                  // load up the knowledge base

                                  KnowledgeBase kbase = readKnowledgeBase();

                                  StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                                  KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 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", "krisv");

                                  params.put("description", "Need a new laptop computer");

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



                                  SystemEventListenerFactory.setSystemEventListener(new SystemEventListener());

                                  // we can reuse the client used by the Work Item Hander.

                                  TaskService taskClient = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient("HumanTaskExample-testClient"));



                                  taskClient.connect("", 5153);



                                  // "sales-rep" reviews request

                                  List<String> groups = new ArrayList<String>();




                                  TaskSummary task1 = taskClient.getTasksAssignedAsPotentialOwner("sales-rep", groups, "en-UK").get(0);

                                  System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");

                                  taskClient.claim(task1.getId(), "sales-rep", groups);




                                  taskClient.start(task1.getId(), "sales-rep");



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

                                  results.put("comment", "Agreed, existing laptop needs replacing");

                                  results.put("outcome", "Accept");

                                  ContentData contentData = ContentMarshallerHelper.marshal(results,  null);



                                  taskClient.complete(task1.getId(), "sales-rep", contentData);






                                  // "krisv" approves result

                                  TaskSummary task2 = taskClient.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0);

                                  System.out.println("krisv executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");

                                  taskClient.start(task2.getId(), "krisv");





                                  results = new HashMap<String, Object>();

                                  results.put("outcome", "Agree");

                                  contentData = ContentMarshallerHelper.marshal(results, null);





                                  taskClient.complete(task2.getId(), "krisv", contentData);




                                  // "john" as manager reviews request



                                  groups = new ArrayList<String>();




                                  TaskSummary task3 = taskClient.getTasksAssignedAsPotentialOwner("john", groups, "en-UK").get(0);

                                  System.out.println("john executing task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ")");




                                  taskClient.claim(task3.getId(), "john", groups);


                                  taskClient.start(task3.getId(), "john");



                                  results = new HashMap<String, Object>();

                                  results.put("outcome", "Agree");

                                  contentData = ContentMarshallerHelper.marshal(results, null);



                                  taskClient.complete(task3.getId(), "john", contentData);




                                  // "sales-rep" gets notification

                                  TaskSummary task4 = taskClient.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK").get(0);

                                  System.out.println("sales-rep executing task " + task4.getName() + "(" + task4.getId() + ": " + task4.getDescription() + ")");



                                  taskClient.start(task4.getId(), "sales-rep");





                                  Task task = taskClient.getTask(task4.getId());





                                  Content content = taskClient.getContent(task.getTaskData().getDocumentContentId());



                                  Object result = ContentMarshallerHelper.unmarshall(content.getContent(), null);



                                  Map<?, ?> map = (Map<?, ?>) result;

                                  for (Map.Entry<?, ?> entry : map.entrySet()) {

                                      System.out.println(entry.getKey() + " = " + entry.getValue());






                                  taskClient.complete(task4.getId(), "sales-rep", null);









                              } catch (Throwable t) {






                          private static KnowledgeBase readKnowledgeBase() throws Exception {

                              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                              kbuilder.add(ResourceFactory.newClassPathResource("humantask/HumanTask.bpmn"), ResourceType.BPMN2);

                              return kbuilder.newKnowledgeBase();




                          private static class SystemEventListener implements org.drools.SystemEventListener {



                              public void debug(String arg0) {




                              public void debug(String arg0, Object arg1) {




                              public void exception(Throwable arg0) {




                              public void exception(String arg0, Throwable arg1) {




                              public void info(String arg0) {




                              public void info(String arg0, Object arg1) {




                              public void warning(String arg0) {




                              public void warning(String arg0, Object arg1) {




                      • 8. Re: jbpm-examples with jBPM 5.4
                        doboss Newbie

                        Okay, cool, so you just ripped it out.



                        • 9. Re: jbpm-examples with jBPM 5.4
                          Gareth Edwards Newbie

                          I just received a copy of your book so hopefully that will answer all of my questions from now on