Discussion:
[jboss-user] [jBPM] - JBPM 5.4.0-Final: Human Task variable mapping is not working
vchmakov
2013-01-07 13:43:48 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi,

I’m not sure as to what is going on

I have an SE application with JBPM 5.2.0 successfully running in production.
Now I’m trying to switch to JBPM 5.4.0 and from SE to EE. To be honest not everything went smoothly, but I was able to sort out most of the issues and started testing of my workflows. Variable mapping/assignment when Human Task is finished is not working. For some reason all variables which are supposed to be assigned from the task output map are getting null-ed. There is no exception thrown. Am I missing something?

Any help is appreciated.

Thanks,

Vladimir
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-09 12:21:37 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
description that you provided makes me believe that your human task work item is not completed but aborted which causes that the variables are not set based on the outcome. Do you use LocalTaskService?

HTH
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vchmakov
2013-01-09 13:29:24 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

Yes, I’m using LocalTaskService. What makes you believe that the task is aborted -the transaction completed but not aborted and the task is marked/persisted as Completed?

Thanks,

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-09 14:03:04 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Vladimir, the issue with local task service that you could experience is when you have different instances of it used for creating the task (via LocalHTWorkItemHandler) and completing it. If they are two different instances their persistence context is not shared and thus when task is completed it sends an completed event to the engine which is received by LocalHTWorkItemHandler and it checks if the task is in state Completed - which in case of not shared persistence context it won't be and thus proceeding to abort work item instead of completing it.
So on the task service side everything is ok but engine gets outdated values so it proceeds but not in the way you expect.

HTH
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vchmakov
2013-01-09 16:47:25 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

That is exactly what is going on. However, as far as I understand and according to the examples coming with the JBPM deployment:
1)      The instance of the LocalHTWorkItemHandler is attached to the session and is purposed for the HT engine’s event handling. As far as I can see it does not possess the persistence context but rather shares it with the Drools’s one when rule’s RHS starts the process and the process reaches the wait/persisted state.

    *private* *void* registerHumanTaskHandler(StatefulKnowledgeSession session) {
        *if* (taskServer != *null*) {
            +logger+.info("Registering Human Task Handler...");
            LocalHTWorkItemHandler humanTaskHandler = *new* LocalHTWorkItemHandler(createTaskService(), session);
            humanTaskHandler.setLocal(*true*);
            humanTaskHandler.connect();
            session.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);
            +logger+.info("OK.");
        }
    }


2)      When user completes a task from the Web form the event is delivered to the engine. In my case it is a Message Queue event which I process in MDB. Then I create a fresh instance of the LocalTaskService and complete the task. According to the examples provided with the JBPM installation and the source code of the LocalTaskService it is a recommended way to avoid reusing of the Entity Manager.


    *private* *void* registerHumanTaskHandler(StatefulKnowledgeSession session) {
        *if* (taskServer != *null*) {
            +logger+.info("Registering Human Task Handler...");
            LocalHTWorkItemHandler humanTaskHandler = *new* LocalHTWorkItemHandler(createTaskService(), session);
            humanTaskHandler.setLocal(*true*);
            humanTaskHandler.connect();
            session.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);
            +logger+.info("OK.");
        }
    }

    *private* *void* createTaskServer() *throws* Exception {
        +logger+.info("Creating Task Server...");
        *if* (persistenceManager != *null*) {
            taskServer = *new* TaskService(persistenceManager.getTaskEntityManagerFactory(),
                    SystemEventListenerFactory.+getSystemEventListener+());
        }
        *else* {
            *throw* *new* IllegalArgumentException("createTaskServer() - Persistence Manager must be created for this operation");
        }
        +logger+.info("OK.");
    }

    *private* org.jbpm.task.TaskService createTaskService() {
        +logger+.debug("Creating Task Service...");
        *if* (taskServer != *null*) {
            *return* *new* LocalTaskService(taskServer);
        }
        *else* {
            *throw* *new* IllegalArgumentException("Task Server is not yet created");
        }
    }

    *private* *void* processCompleteTaskCommand(BvCompleteTaskCommand command) *throws* Exception {
        +logger+.trace("Processing TaskCompleteCommand()...");
        *final* String userId = command.getUserId();
        *final* String wf_userId = +WORKFLOW_USERID+;
        logger_processes.debug("Completing task id={}, userId={}", command.getTaskId(), userId);

        org.jbpm.task.TaskService taskService = createTaskService();

        taskService.start(command.getTaskId(), wf_userId);

        Object data = command.getData();
        *if* (data != *null*) {
            taskService.completeWithResults(command.getTaskId(), wf_userId, data);
        }
        *else* {
            logger_processes.debug("**** data is NULL");
            taskService.complete(command.getTaskId(), wf_userId, *null*);
       }
        logger_processes.debug("  - task id={}, userId={} completed.", command.getTaskId(), userId);
        +logger+.trace("Processing TaskCompleteCommand(). OK.");
    }


It seems to me that I’m misunderstanding something


Thanks,

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-09 18:11:50 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
The issue here is that LocalHTWorkItemHandler has single (always active) instance of LocalTaskService and unfortunately it is shared with TaskCompletedHandler (that is inherited from GenericHTHandler). Which puts us in situation where after some time task is about to be completed and to do so new LocalTaskService instance is created that does the complete operation on task service and sends an event to the runtime engine. That event is received by TaskCompletedHandler and uses LocalTaskService instance from LocalHTWorkItemHandler. That gives us:
1. new instance of LocalTaskService (LTS1) that is created to complete task with persistence context PC1
2. always active instance of LocalTaskService (LTS2) taken from LocalHTWorkItemHandler inside TaskCompletedHandler class which was persistence context PC2

when LTS2 checks task status by loading it from db (PC2) it has out of date information as the LTC1 has not yet committed it's changes (flushed from PC1) and thus proceeding with abort of work item handler.

A workaround for this would be to extend LocalHTWorkItemHandler and override registerForEvent method to register your own TaskCompletedHandler that will get new LocalTaskService for every event it is going to process. With that persistence contexts will be shared on hibernate session level since they run as part of the same JTA transaction and where created for that transaction.

HTH
--------------------------------------------------------------

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

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

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

Your proposed approach works fine in terms that the my process now sees the result values. However, when the time comes for the session to complete the tasks is fails. I suspect the reason for this is the same – different persistent context.

        *private* *void* handleCompletedTask(*long* taskId) {

// currentClient is a reference to my LocalTaskService instance I create for completeting the tasks

            Task task = currentClient.getTask(taskId);
            *long* workItemId = task.getTaskData().getWorkItemId();
            *if* (task.getTaskData().getStatus() == Status.+Completed+) {
                String userId = task.getTaskData().getActualOwner().getId();
                Map<String, Object> results = *new* HashMap<String, Object>();
                results.put("ActorId", userId);
                *long* contentId = task.getTaskData().getOutputContentId();
                *if* (contentId != -1) {
                    Content content = currentClient.getContent(contentId);
                    Object result = ContentMarshallerHelper.+unmarshall+(content.getContent(), session.getEnvironment());
                    results.put("Result", result);
                    *if* (result *instanceof* Map) {
                        Map<?, ?> map = (Map<?, ?>) result;
                        *for* (Map.Entry<?, ?> entry : map.entrySet()) {
                            *if* (entry.getKey() *instanceof* String) {
                                results.put((String) entry.getKey(), entry.getValue());
                            }
                        }
                    }
Ú  fails here
                    session.getWorkItemManager().completeWorkItem(task.getTaskData().getWorkItemId(), results);
                }
                *else* {
                    session.getWorkItemManager().completeWorkItem(workItemId, results);
                }
            }
            *else* {
                logger_processes.debug("session.getWorkItemManager().abortWorkItem()");
                session.getWorkItemManager().abortWorkItem(workItemId);
            }
        }

processTaskCommand() error:: com.thoughtworks.xstream.io.StreamException:  : only whitespace content allowed before start tag and not B (position: START_DOCUMENT seen B... @1:1)
                at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:124) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:58) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.XStream.fromXML(XStream.java:895) [xstream-1.4.1.jar:]
                at com.thoughtworks.xstream.XStream.fromXML(XStream.java:886) [xstream-1.4.1.jar:]
                at org.drools.process.core.datatype.impl.type.ObjectDataType.readValue(ObjectDataType.java:77) [drools-core-5.5.0.Final.jar:5.5.0.Final]
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.triggerCompleted(WorkItemNodeInstance.java:223) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                at org.jbpm.workflow.instance.node.HumanTaskNodeInstance.triggerCompleted(HumanTaskNodeInstance.java:90) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.workItemCompleted(WorkItemNodeInstance.java:309) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.signalEvent(WorkItemNodeInstance.java:285) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.signalEvent(WorkflowProcessInstanceImpl.java:342) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:121) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]
                at org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:69) [drools-core-5.5.0.Final.jar:5.5.0.Final]
                at org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:32) [drools-core-5.5.0.Final.jar:5.5.0.Final]
                at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36) [drools-core-5.5.0.Final.jar:5.5.0.Final]
                at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:373) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]
                at org.drools.command.impl.CommandBasedStatefulKnowledgeSession$1.completeWorkItem(CommandBasedStatefulKnowledgeSession.java:150) [drools-core-5.5.0.Final.jar:5.5.0.Final]
                at BvLocalHTWorkItemHandler$TaskCompletedHandler.handleCompletedTask(BvLocalHTWorkItemHandler.java:96)





It seems like either I need to put Drools and Task Service inside the same persistent context or split the transaction boundaries between Drools and Task Service. The second one is in fact a recommended way here which has been previously discussed in another posts, but I strongly disagree with the Task Service decoupling idea.

Any other thoughts/ideas?

Thanks,

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-10 10:36:21 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Looking at the stack trace I think it is failing due to missing data type definition and it assumes Object and that's why it tries to use xstram to build object out of string. So if you declare structureRef for all your itemDefinitions that are used as process variables this error should go away.

HTH
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vchmakov
2013-01-11 16:14:29 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

After some changes I think now I have both the runtime and the local Task Server working in the same transaction and sharing the same persistence context. I found that perhaps LocalHTWorkItemHandler.setClient() can be used instead of overriding of the TaskCompleteHandler to make Complete Task command working in the same persistence context. Please correct me if I’m wrong on this. All my process variables are objects – java.lang.String, java.lang.Integer etc. Is this what you mean in your reply above? The error did not go away. Any other ideas as to why this may be happening?

Thanks,

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-12 09:25:19 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Vladimir, using setClient can have side effects in concurrent cases e.g. when at the same time new task is created and another is completed. Two threads will use the same LocalTaskService instance which could lead to some unexpected results.

The error you are seeing could be caused by not declared type of you process variables, take a look https://github.com/droolsjbpm/jbpm/blob/master/jbpm-bpmn2/src/test/resources/BPMN2-StringStructureRef.bpmn2 here at line 14, you'll see it declares String as structureRef so that informs the engine how to deal with that variable.You can declare java.lang.String as FQN too. Once you have that it should proceed with setting variables properly.

HTH
--------------------------------------------------------------

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

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

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

1)     I’d agree with you on the first statement, but we are talking about an instance of the LocalTaskService which is linked to a knowledge session. Session is not thread safe according to the documentation and therefore I wouldn’t allow two threads working with a single instance of the session.
2)     I’ve converted all my workflow files from .rl format to .bpmn one and now everything is working fine. Have I missed an announcement that the .rl format is not supported anymore or it is a bug/regression?

Thanks,

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-14 17:27:16 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Post by vchmakov
1)     I’d agree with you on the first statement, but we are talking about an instance of the LocalTaskService which is linked to a knowledge session. Session is not thread safe according to the documentation and therefore I wouldn’t allow two threads working with a single instance of the session.
Just keep in mind that LocalTaskService register its events on the global TaskService instance so that means you can experience situation that many sessions can be informed about completion of a task.
Post by vchmakov
2)     I’ve converted all my workflow files from .rl format to .bpmn one and now everything is working fine. Have I missed an announcement that the .rl format is not supported anymore or it is a bug/regression?
Nothing that I am aware of, rule flow is still supported and there are quite few tests for it in the code base, especially for modules that are higher in the hierarchy than jbpm-bpmn2 module. So it should work without changes. What issues did you encounter?

HTH
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vchmakov
2013-01-14 19:29:33 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

1)      Thank you for the tip – I did not know that and can now see that this may really cause problems in production on a high level of load.
2)      The only issue described above – stream error when completing a task.

Thank you for your help!

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-15 11:29:18 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
could you attach a sample that fails with the stream error?

Cheers
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vchmakov
2013-01-15 19:14:00 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Maciej,

Attached is a .rf workflow file which was causing me some head ache. Hope this is enough for your investigation.

Thanks,

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-16 05:50:40 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Alright the problem seems to be in declaration of variables. As 5.4 is now aware of data types you need to specify correct data types. for instance you have variable:
     <variable name="isApproved" >
        <type name="org.drools.process.core.datatype.impl.type.ObjectDataType" className="java.lang.String" />
      </variable>

but as you can see data type (name attribute) refers to ObjectDataType and that's why xstream comes into play. if you define correct data type:

     <variable name="isApproved" >
        <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
      </variable>
it should work properly. Same should be done for boolean, integer and float data types.

When using droolsjbpm eclipse plugin to edit variables it should be enough to select String as type from dropdown.

HTH
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vchmakov
2013-01-16 13:54:51 UTC
Permalink
vchmakov [https://community.jboss.org/people/vchmakov] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
OK, I see
 Thanks you your help!

Vladimir


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Oleg Bondarenko
2013-03-01 19:47:48 UTC
Permalink
Oleg Bondarenko [https://community.jboss.org/people/obon] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Vladimir,

would it be possible to publish the source code of your LocalHTWorkItemHandler extention?

I am having the same problem, I have implemented the workaround, but the task status still not get tested as "completed" .


Here is my class:


import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManagerFactory;

import org.drools.SystemEventListenerFactory;
import org.drools.runtime.KnowledgeRuntime;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.eventmessaging.EventResponseHandler;
import org.jbpm.eventmessaging.Payload;
import org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler;
import org.jbpm.task.Content;
import org.jbpm.task.Status;
import org.jbpm.task.Task;
import org.jbpm.task.event.TaskEventKey;
import org.jbpm.task.event.entity.TaskCompletedEvent;
import org.jbpm.task.event.entity.TaskEvent;
import org.jbpm.task.event.entity.TaskFailedEvent;
import org.jbpm.task.event.entity.TaskSkippedEvent;
import org.jbpm.task.service.TaskService;
import org.jbpm.task.service.local.LocalTaskService;
import org.jbpm.task.service.responsehandlers.AbstractBaseResponseHandler;
import org.jbpm.task.utils.ContentMarshallerHelper;

public class MyLocalHTWorkItemHandler extends LocalHTWorkItemHandler {

    private EntityManagerFactory emf;

    public MyLocalHTWorkItemHandler(KnowledgeRuntime session) {
        super(session);
    }

    public MyLocalHTWorkItemHandler(LocalTaskService localTaskService,
            StatefulKnowledgeSession ksession) {
        super(localTaskService, ksession);
    }

    public MyLocalHTWorkItemHandler(LocalTaskService localTaskService,
            StatefulKnowledgeSession ksession, EntityManagerFactory emf) {
        super(localTaskService, ksession);
        this.emf = emf;
    }

    @Override
    protected void registerTaskEvents() {
        TaskCompletedHandler eventResponseHandler = new TaskCompletedHandler();
        TaskEventKey key = new TaskEventKey(TaskCompletedEvent.class, -1);
        getClient().registerForEvent(key, false, eventResponseHandler);
        eventHandlers.put(key, eventResponseHandler);
        key = new TaskEventKey(TaskFailedEvent.class, -1);
        getClient().registerForEvent(key, false, eventResponseHandler);
        eventHandlers.put(key, eventResponseHandler);
        key = new TaskEventKey(TaskSkippedEvent.class, -1);
        getClient().registerForEvent(key, false, eventResponseHandler);
        eventHandlers.put(key, eventResponseHandler);
    }

    private class TaskCompletedHandler extends AbstractBaseResponseHandler implements EventResponseHandler {

        public void execute(Payload payload) {
            TaskEvent event = (TaskEvent) payload.get();
            final long taskId = event.getTaskId();

            if (isOwningSessionOnly() && (session instanceof StatefulKnowledgeSession)) {
                if (((StatefulKnowledgeSession) session).getId() != event.getSessionId()) {
                    return;
                }
            }

            TaskService taskService = new org.jbpm.task.service.TaskService(
                    emf, SystemEventListenerFactory.getSystemEventListener());

            handleCompletedTask(taskId, new LocalTaskService(taskService));
        }

        public boolean isRemove() {
            return false;
        }

        public void handleCompletedTask(long taskId, LocalTaskService localTaskService) {
            Task task = localTaskService.getTask(taskId);
            long workItemId = task.getTaskData().getWorkItemId();
            if (task.getTaskData().getStatus() == Status.Completed) {
                String userId = task.getTaskData().getActualOwner().getId();
                Map<String, Object> results = new HashMap<String, Object>();
                results.put("ActorId", userId);
                long contentId = task.getTaskData().getOutputContentId();
                if (contentId != -1) {
                    Content content = localTaskService.getContent(contentId);
                    Object result = ContentMarshallerHelper.unmarshall( content.getContent(),
                            session.getEnvironment(), getClassLoader());
                    results.put("Result", result);
                    if (result instanceof Map) {
                        Map<?, ?> map = (Map<?, ?>) result;
                        for (Map.Entry<?, ?> entry : map.entrySet()) {
                            if (entry.getKey() instanceof String) {
                                results.put((String) entry.getKey(), entry.getValue());
                            }
                        }
                    }

                    session.getWorkItemManager().completeWorkItem(task.getTaskData().getWorkItemId(), results);
                } else {
                    session.getWorkItemManager().completeWorkItem(workItemId, results);
                }
            } else {
                session.getWorkItemManager().abortWorkItem(workItemId);
            }
        }
    }

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

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

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

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hi Oleg,

Well, unfortunately I do not have one. I use the standard one LocalHTWorkItemHandler  and do setClient(). I’m trying to utilize the container-scoped transactions, so to achieve that I’m implementing TaskTransactionManager and TaskSessionFactory interfaces.  Although, now I’m not so sure that the approach is 100% valid


Thanks,

Vladimir
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Oleg Bondarenko
2013-03-04 10:41:29 UTC
Permalink
Oleg Bondarenko [https://community.jboss.org/people/obon] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
ok, I got it to work, one should not wrap the complete method in a new transaction.

thanks, anyway.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
maq99
2013-01-18 11:04:48 UTC
Permalink
maq99 [https://community.jboss.org/people/maq99] created the discussion

"Re: JBPM 5.4.0-Final: Human Task variable mapping is not working"

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

--------------------------------------------------------------
Hallo,
I have simmilar problem and decide to add my post to this topic instead create new one. Something wrong is with saveing variables. I already spend some time on it and have not found sollution. All base on seam framework (web app) + EJB3 as jbpm managment layer. Persistence is made on Postgres.
Here is my diagram:
Loading Image... Loading Image...
As You can see there is two human tasks.. After process is started user:user1 pick object:wrapper (from external Wsdl) to edit, chenge its fields and confirm changes or reject it. Eddited object is about to be placed as HT result and stored as process variables.
First gateway check if object have been placed (not null - go to commit) or changes have been rejected (is null - cancel & end process)
At begininig next HT (approval) fallowing log script is called, then it calls my custom EscalatedDeadlineHandler and send email to user:approver that he has task assign. Approval base on object:wrapper from previous HT.
Approvel page display edited object:wrapper and shows changes made by user:user1
As a result Boolean value isApproved has to be added to proces variables. Next gateway check isApproved on true go to submit changes (send back to store edited object - external Wsdl) - else goes to end.

process variables:
Name: wrapper; Type: Object; ClassName: Object
Name: isApproved; Type: Object; ClassName: Object

1HT (edit object) Result mapping:
Parameter: result; Variable: wrapper

1Gateway:
commit: Type: code; Dialect: mvel; wrapper!=null
cancel:  Type: code; Dialect: mvel; wrapper==null

2HT (approval) Parameter mapping:
Parameter wrapper; Variable: wrapper;

2HT (approval) Result mapping:
Parameter isApproved; Variable: isApproved;

Starting process code:
@PersistenceUnit(unitName = "org.jbpm.persistence.jpa")
protected EntityManagerFactory jbpmPersistence;

@PersistenceUnit(unitName = "org.jbpm.task")
protected EntityManagerFactory jbpmTask;

(...)
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.TRANSACTION_MANAGER,TransactionManagerServices.getTransactionManager());
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,
          new ObjectMarshallingStrategy[] {
                    new JPAPlaceholderResolverStrategy(env),
                    new SerializablePlaceholderResolverStrategy(
                              ClassObjectMarshallingStrategyAcceptor.DEFAULT) });

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(bpmn),ResourceType.BPMN2);
// Check for errors
if (kbuilder.hasErrors()) {
          if (kbuilder.getErrors().size() > 0) {
                    for (KnowledgeBuilderError error : kbuilder.getErrors()) {
                              log.error(error.toString());
                    }
          }
}
KnowledgeBase kbase = kbuilder.newKnowledgeBase();

KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();

StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, env);
KnowledgeRuntimeLogger knowledgeRuntimeLogger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);

MyHtWorkItemHandler workItemHandler = new MyHtWorkItemHandler(
                    ksession);
workItemHandler.setLocal(true);
workItemHandler.setIpAddress(WUIConfiguration.getHumanTaskServiceIP());
workItemHandler.setPort(WUIConfiguration.getHumanTaskServicePort());
workItemHandler.setClient(getLocalTaskService());
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
                    workItemHandler);
workItemHandler.connect();

WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession
                                        .startProcess(processId);// variables will be added in HT.. .



protected TaskService getLocalTaskService() {
          if (taskService == null) {
                    taskService = new org.jbpm.task.service.TaskService(jbpmTask,
                                        SystemEventListenerFactory.getSystemEventListener());
//for PoC it can be singleton?
                    taskService
                                        .setEscalatedDeadlineHandler(MyEscalatedDeadlineHandler
                                                            .getInstance());
                    TaskServiceSession taskServiceSession = taskService.createSession();
                    // TODO create dynamic users list..
                    taskServiceSession.addUser(new User("approver"));
                    taskServiceSession.addUser(new User("user1"));
          }
          // taskservicesMap.put(processName, taskService);
          return new LocalTaskService(taskService);
}
--------------------------------------------------------------

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

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