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]