7 Replies Latest reply on Dec 23, 2011 5:10 AM by Maciej Swiderski

    How to query tasks

    Tommer Wizansky Newbie

      Here's the situation I have.  I want to write a simple user registration flow which should look something like this:


      1) user requests registration

      2) system sends an email with a confirmation link and pauses the process until the user confirms the registration.

      3) user follows the link and clicks "confirm" (or something like that)

      4) the system continues the process and creates a new user in the system.


      3 Is implemented with a human task. My problem lies with the transition from 3 to 4.  The new user is not an actor in the jBPM environment so I can't assign the human task to him.  I have to assign it to some general "registration-manager" actor.  In that case, in step 4, how do I retrieve the correct task and continue the process?  The only way I can see is to retrieve all the tasks assigned to "registration-manager" and search them in code but that involves a lot of overhead since we may have many new users.


      I would like to retrieve only the task associated with the specific new user that is registering but I don't see any way to do this.  Is there any way to query tasks with more granularity than just the actor they are assigned to? 



        • 1. Re: How to query tasks
          Maciej Swiderski Master

          One of possible solution to that would be to use following method from TaskClient:


          public void getTaskByWorkItemId(long workItemId, GetTaskResponseHandler responseHandler) 


          if you can include work item id while sending the link. You could get work item id with onExit-script of the human task - set it as process variable.


          Then use that work item id to query for task.


          If that is not good for your case you can always use the generic query method from TaskClient.



          1 of 1 people found this helpful
          • 2. Re: How to query tasks
            Tommer Wizansky Newbie

            Thanks for the response. 


            I would prefer to use the task client's query method so that I could avoid exposing jBPM specific information like work item IDs.  The problem is, what do I query?   As far as I can tell, jBPM stores all custom data as BLOBs which are not easily accessible by queries.   How do I associate work items with a new user name in a way that I can later query.



            • 3. Re: How to query tasks
              Maciej Swiderski Master

              Note that we are talking about Task Server and there are more data you can access in regular queries on data base.


              If it comes to the exposing jBPM specific information, I don't think you can completely avoid that. One thing you could query on is processInstanceId that is stored in the task server. Depending on your process definition it could be that at a given point in time only one task will be created for process instance id.

              In addition to that, you could use task comments to place some meaningful information that would help you to find the right tasks.





              Here is a nice overview of the data base schemas for the engine and task server:http://community.jboss.org/message/627783

              • 4. Re: How to query tasks
                Mauricio Salatino Master

                Some Times you need to expose the WorkItemID or wrap that information using a Business Object that will maintain the information about the process execution and its external interactions to keep track of what is happening


                • 5. Re: How to query tasks
                  Tommer Wizansky Newbie

                  We decided to include the work item id in the email link.  Not perfect but not really that bad either.  One remaining problem involves the determination of the work item id when sending the email.  Ideally the process would look something like this:


                  1) user initiates the registration

                  2) system sends a verification email

                  3) the process transitions to the human task, waiting for the user to follow the link, confirm the registration, etc.





                  The problem is that we need to know the work item id for the human task in step 2, in order to include it in the email.  But, the task is only created in step 3.  The solution we found was to combine steps 2 and 3.  We subclassed CommandBasedWSHumanTaskHandler and overrode the executeItem method to send the email right before proceeding with the human task.  At that point the work item id is known and we can include it in the email.   It works fine but feels a little awkward.  If anyone has a more elegant solution, I'd love to hear it.


                  In any case, thanks for all the replies.



                  • 6. Re: How to query tasks
                    Mauricio Salatino Master

                    Yes, it's sounds a little bit awkward. You can also do something similar without extending anything and is using the onEntry/onExit extensions that allows you to execute a piece of code when the process is entering or leaving an activity.


                    But.... that makes me think and wonder, why do you need the workItemId?

                    If the session is alive, instead of completing the work item you should be completing the human task, and the human task server will be in charge of notifying the process to continue right?



                    • 7. Re: How to query tasks
                      Maciej Swiderski Master

                      Tommer, for what you describe human task notifications sound like perfect fit. They are part of deadlines configuration of a task. To be more precise start deadline. In general, start deadline is reached when task is not started before the given time expires. There are two options for deadline escalation:

                      • notification
                      • reassignment

                      Both can be used at the same time, but in your case notification is more interesting.


                      Notification (email notification) can be sent to some recipients that are not assigned directly to a task, which could be what you are looking for since there is no user registered at the moment.


                      Unfortunately there is no out of the box support to define deadlines in BPMN2, at least I do not know it. So extension of *HumanTaskHandler class will be required to setup deadlines on the task. Some additional configuration is needed on Task Server side as well, for details about task server please have a look at: https://github.com/droolsjbpm/jbpm/blob/master/jbpm-human-task/src/test/java/org/jbpm/task/service/TaskServiceDeadlinesBaseTest.java