I am using jBPM 4.1 and tried to write a unit test that queries the history 
service using the task assignee and name. 
First i looked at the sources of jBPM and searched for tests that are 
performing a similar query. Unfortunately the only test related to history task 
assignee was org.jbpm.test.history.HistoryTaskAssigneeTest shown below and the 
test didn't use the assignee information to perform the query:

/*
  |  * JBoss, Home of Professional Open Source
  |  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  |  * by the @authors tag. See the copyright.txt in the distribution for a
  |  * full listing of individual contributors.
  |  *
  |  * This is free software; you can redistribute it and/or modify it
  |  * under the terms of the GNU Lesser General Public License as
  |  * published by the Free Software Foundation; either version 2.1 of
  |  * the License, or (at your option) any later version.
  |  *
  |  * This software is distributed in the hope that it will be useful,
  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  |  * Lesser General Public License for more details.
  |  *
  |  * You should have received a copy of the GNU Lesser General Public
  |  * License along with this software; if not, write to the Free
  |  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  |  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  |  */
  | package org.jbpm.test.history;
  | 
  | import org.jbpm.api.Execution;
  | import org.jbpm.api.history.HistoryActivityInstance;
  | import org.jbpm.test.JbpmTestCase;
  | 
  | 
  | /**
  |  * @author Tom Baeyens
  |  */
  | public class HistoryTaskAssigneeTest extends JbpmTestCase {
  | 
  |   public void testHistoryTaskAssignee() {
  |     deployJpdlXmlString(
  |       "<process name='TaskAssignee'>" +
  |       "  <start>" +
  |       "    <transition to='review' />" +
  |       "  </start>" +
  |       "  <task name='review' " +
  |       "        assignee='johndoe'>" +
  |       "    <transition to='wait' />" +
  |       "  </task>" +
  |       "  <state name='wait'/>" +
  |       "</process>"
  |     );
  |     
  |     executionService.startProcessInstanceByKey("TaskAssignee");
  | 
  |     HistoryActivityInstance historyActivityInstance = historyService
  |       .createHistoryActivityInstanceQuery()
  |       .uniqueResult();
  |     
  |   }
  | 
  | }
  | 

The current implementation of the HistoryTaskQuery allows querying using the 
assignee but not the name of the task. To find out the name for the task i 
decided to make a HistoryActivityInstanceQuery using the executiondid that will 
be delivered by the HistoryTaskQuery. To my surprise this didn't work. The 
HistoryActivityInstanceQuery delivered 3 HistoryActivityInstances instead of 1. 
So it is not possible to figure out the name of the task that was performed by 
the assignee. The unit test is shown below:

package com.cg.wfl.jbpm.examples.wfl_examples.history;
  | 
  | import java.util.List;
  | 
  | import org.jbpm.api.Execution;
  | import org.jbpm.api.history.HistoryActivityInstance;
  | import org.jbpm.api.history.HistoryTask;
  | import org.jbpm.test.JbpmTestCase;
  | 
  | public class HistoryTaskAssigneeTest extends JbpmTestCase {
  |     public void testHistoryTaskAssignee() {
  |             deployJpdlXmlString(
  |                   "<process name='TaskAssigneeTest'>" +
  |                   "  <start>" +
  |                   "    <transition to='a' />" +
  |                   "  </start>" +
  |                   "  <task name='a' assignee='mary'>" +
  |                   "    <transition name='toB' to ='b' />" +
  |                   "  </task>" +
  |                   "  <task name='b' assignee='alex'>" +
  |                   "    <transition name='toC' to ='c' />" +
  |                   "  </task>" +
  |                   "  <task name='c' assignee='mary'>" +
  |                   "    <transition name='toEnd' to ='end' />" +
  |                   "  </task>" +
  |                   "  <end name='end' />" +
  |                   "</process>"
  |                 );
  |             Execution execution = 
executionService.startProcessInstanceByKey("TaskAssigneeTest");
  |             
  |             String taskId = 
taskService.createTaskQuery().uniqueResult().getId();
  |         taskService.completeTask(taskId);
  |         taskId = taskService.createTaskQuery().uniqueResult().getId();
  |         taskService.completeTask(taskId);
  |         taskId = taskService.createTaskQuery().uniqueResult().getId();
  |         taskService.completeTask(taskId);
  | 
  |         assertNull("execution "+execution.getId()+" should not exist", 
  |                     executionService.findExecutionById(execution.getId()));
  |             
  |         List<HistoryTask> historyTasks = 
historyService.createHistoryTaskQuery().
  |             assignee("mary").list();
  |             assertEquals(2, historyTasks.size());
  | 
  |         historyTasks = historyService.createHistoryTaskQuery().
  |             assignee("alex").list();
  |             assertEquals(1, historyTasks.size());
  |             
  |             // Try to find out the name of the task for the first task with 
assignee mary
  |             String executionId = historyTasks.get(0).getExecutionId();
  |             List<HistoryActivityInstance> historyActivities = 
historyService.createHistoryActivityInstanceQuery().
  |                     executionId(executionId).list();
  |             // The expectation is 1 entry in the list, but the list 
contains 3 entries
  |             // It is not possible to link the HistoryTask to the 
HistoryActivityInstance
  |             // using the executionId!
  |             assertEquals(1, historyActivities.size());
  |     }
  | }
  |  

I found also the following jira issues that references task history details and 
hope that the problem with the task name will be also considered.

https://jira.jboss.org/jira/browse/JBPM-2442

Any help or comments are welcomed.


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255107#4255107

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255107
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to