Discussion:
[jboss-user] [jBPM] - jbpm-examples with jBPM 5.4
Gareth Edwards
2012-11-27 19:27:32 UTC
Permalink
Gareth Edwards [https://community.jboss.org/people/garethed] created the discussion

"jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
Hello,

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.

Regards,

Gareth.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Esteban Aliverti
2012-11-28 09:05:31 UTC
Permalink
Esteban Aliverti [https://community.jboss.org/people/eaa] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
Since jBPM5.4 the UserGroupCallback mechanism ( http://docs.jboss.org/jbpm/v5.4/userguide/ch.human-tasks.html#d0e5419 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. 
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2012-11-28 09:35:57 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

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


Regards,
Thomas Setiabudi

--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Esteban Aliverti
2012-11-28 09:41:53 UTC
Permalink
Esteban Aliverti [https://community.jboss.org/people/eaa] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
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,
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2012-11-28 09:44:07 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
Thanks Esteban

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

Regards,
Thomas Setiabudi
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2012-12-03 09:20:59 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
Thanks Esteban

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

Regards,
Thomas Setiabudi
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Gareth Edwards
2013-01-07 14:52:21 UTC
Permalink
Gareth Edwards [https://community.jboss.org/people/garethed] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

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

Gareth.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Gareth Edwards
2012-11-28 12:43:12 UTC
Permalink
Gareth Edwards [https://community.jboss.org/people/garethed] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
Thanks Esteban. Simple case of RTFM.

Gareth.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
doboss
2012-12-04 19:19:56 UTC
Permalink
doboss [https://community.jboss.org/people/doboss] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
@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?

Thanks!
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Gareth Edwards
2012-12-04 19:28:35 UTC
Permalink
Gareth Edwards [https://community.jboss.org/people/garethed] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
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("127.0.0.1", 5153);

            Thread.sleep(1000);
            // "sales-rep" reviews request
            List<String> groups = new ArrayList<String>();
            groups.add("sales");


            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);

            Thread.sleep(1000);

            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);


            Thread.sleep(2000);


            // "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);


            Thread.sleep(2000);
            // "john" as manager reviews request


            groups = new ArrayList<String>();
            groups.add("PM");


            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);


            Thread.sleep(2000);
            // "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);



            Thread.sleep(2000);
            taskClient.disconnect();
            hornetQHTWorkItemHandler.dispose();
            logger.close();
            System.exit(0);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }


    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) {
        }
    }
}
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
doboss
2012-12-04 19:35:02 UTC
Permalink
doboss [https://community.jboss.org/people/doboss] created the discussion

"Re: jbpm-examples with jBPM 5.4"

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

--------------------------------------------------------------
Okay, cool, so you just ripped it out.

Thanks!
--------------------------------------------------------------

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

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