3 Replies Latest reply on Feb 15, 2010 5:47 AM by Sebastian Schneider

    Question on TaskQuery

    ben d Newbie

      Hi there,

       

      I've just run the following code :

       

      taskService.createTaskQuery().processInstanceId(processId).activityName("xxx").list()
      

       

      I'd expect this code to return only tasks that are associated to the given processInstanceId and whose name are xxx. But I get all sorts of tasks; I mean tasks whose names differ from xxx. Is that the expected behaviour ?

       

      Cheers,

      Ben

        • 1. Re: Question on TaskQuery
          Sebastian Schneider Master
          I suppose it's not. Can you make a test case which demonstrates the problem? Then we can check and if necessary you can create a JIRA issue.
          • 2. Re: Question on TaskQuery
            ben d Newbie

            Hi there,

             

            I'm using the following jpdl file:

             

            <?xml version="1.0" encoding="UTF-8"?>
            <process name="TestTaskProcess" xmlns="http://jbpm.org/4.3/jpdl">
            
                 <start g="9,20,48,48">
                      <transition to="Task1" />
                 </start>
            
                 <task g="159,16,127,52" name="Task1">
                      <transition to="Task2" name="t" />
                 </task>
            
                 <task g="159,120,127,52" name="Task2">
                      <transition to="Task3" name="t" />
                 </task>
            
                 <task g="161,231,124,52" name="Task3">
                      <transition to="end" name="t" />
                 </task>
            
                 <end g="371,233,48,48" name="end" />
            
            </process>
            

             

            And my test case:

             

                      ProcessEngine processEngine = new Configuration().buildProcessEngine();
                      RepositoryService repositoryService = processEngine.getRepositoryService();
                      TaskService taskService = processEngine.getTaskService();
                      ExecutionService executionService = processEngine.getExecutionService();
            
                      NewDeployment deployment = repositoryService.createDeployment().addResourceFromClasspath(
                                "task-test.jpdl.xml");
                      deployment.deploy();
            
                      ProcessInstance processInstance = executionService
                                .startProcessInstanceByKey("TestTaskProcess");
            
                      // Move to Task2
                      String activeExecutionId = processInstance.findActiveExecutionIn("Task1").getId();
                      ProcessInstance instance = executionService.signalExecutionById(activeExecutionId, "t");
            
                      TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(
                                processInstance.getId()).activityName("Task2");
                      System.out.println(taskQuery.list());
                      // --> [Task(Task1), Task(Task2)]
            

             

            And the outcome is [Task(Task1), Task(Task2)]. Which means I get two tasks instances even though I restricted my query on the activity name.

             

            Maybe this is due to the way I "navigate" from one task to another.

             

            Thanks,

            Ben

            • 3. Re: Question on TaskQuery
              Sebastian Schneider Master

              It is due to your strange way of using tasks. What are you trying to achieve? Assign the tasks to somebody and complete them. After completion of a task the execution will move on to the next one. In this case the TaskQuery is working fine and as expected.

               

              Please note: Creating unit-tests extending JbpmTestcase is the preferred way of supplying test cases. It saves you a lot of code and makes testing easier.