11 Replies Latest reply on Oct 3, 2008 6:02 PM by brittm

    Process/task search based on variables

    fero kocun Newbie

      Hi,
      i would like to search for tasks and processes the same way I search for business objects. Our client has a library for defining filter, and it sends the filter to server. On server hibernate query is constructed from filter and the results are sent back to client.

      I would like to use the same mechanism for searching for business task. But tasks + variable instances don't have such a simple structure. E.g. "friend link" example in book Seam in Action, chapter 14. I would program, that the process has two variables one is friend1 which create the request and the second is friend2 which can either accept or reject request. On one page I would like to show a table of all requests, so I would like to create a filter for all tasks where logged user is in variable friend2. Maybe you think it is better to assign task to some user. In this case maybe yes, but many times we offer editation of business objects(not users) and we need to search for tasks based on this object and assigned to logged user. Now I support searching for tasks with some criteria on business objects. E.g. friend1.age>30 searches for all the tasks where the age of friend in variable friend1 is older than 30. (Of course it makes few selects instead of one, because of any mapping of object variablesand you need to specify process and task name in the method you are calling).

      Except business objects I support String attributes, but to support all other attributes I need open api of JbpmType.
      I need these public methods:
      public boolean matches(Class variableClass) ;
      public JbpmTypeMatcher getJbpmTypeMatcher();
      public Class getVariableInstanceClass ();


      Do you think it is possible/reasonable? If it helps somebody I can ask my colleagues if I can post our filter solution. And if you like it you can pack it in jbpm library. It was developed for searching business objects and we want to make a simple api for searching for tasks (our filter doesn't know that there are some VariableInstances and value conversions..). Or do you prepare any solution for this in the future?

      Thanks

      Fero

        • 1. Re: Process/task search based on variables
          Ronald van Kuijk Master

          Fero,

          Most of the time when this is needed, to many domain data is put in the process engine. You should put as many data as possible in your own domain model and have a reference to the corresponding processdefinition by using a business key (e.g. licenceplate, ssn, or something). You filter in your domain model then any way you like and use businesskeys then to retrieve tasks for the corresponding processinstances. Maybe a method like getTasksForUserInProcessInstance(String actorid, Long[] processInstanceIds) would help then.

          hth and shoot if you disagree

          • 2. Re: Process/task search based on variables
            Ronald van Kuijk Master

            oh and besides this, you probably want it to perform as well, that would probably mean an explosion of indeces and hence lesser performance...

            • 3. Re: Process/task search based on variables
              fero kocun Newbie

              Hi Roland,
              maybe you are right. For sure performance is a issue and there should be a lot of indices. I'm only evaluating jBPM for future use a I thought this would be more general than business key. I have not found a process yet where you need to search for a task with more than one criteria (on one page tasks will be listed with one criteria, on another with another criteria). So from this perspective business key is ok.

              But I have found this use case:
              You start business process on page where business object BO1 is present, business object creates another business object BO2 some tasks are present on the page where you edit BO1, some on the page where you edit BO2. Does it mean that I should store some kind of ssn and save the same in both objects? I thought that to search for tasks will make from this the same issue as if searching for business object.

              And this one (only fictive not form business) case where business key is not enough:
              Imagine "friend link" example. On the page of first user sees all requests he requested and he can cancel some of them -> key should be friend. User2 sees all the requests he can accept/reject -> key should be friend2 They can't have the same key. So solution for this is to have business key in TaskInstance not in ProcessInstance. And this will be the solution for first case as well and I can left out ssn form business object:) I think that it is better to refence object form process and not vice versa. Now we use this solution and I call it business object as "task owner" and the id of business task is stored in task variable. It is not the same as assigning task to user because authorization is there as well so it is assigning task to combination of showed business object and logged user. What do you think about this?

              • 4. Re: Process/task search based on variables
                fero kocun Newbie

                Btw. Is somewhere example of using OO application with process engine. I am not interested in technologies but in principles. Only interesting articel I found is this http://devhawk.net/2004/01/30/SOA+Vs+OO+In+Business+Process.aspx . When I look for SOA everyone is describing integration and WS:( When I look on jBPM.. tutorials I find only not OO examples. Application knows only tasks and processes..

                I like this form the article. Think programming without processes all logic in business object is horrible. But I have no experience with proper use of business objects with the process engine.
                This is what I like form article:

                Typically, the developer sees these processes as methods: Order.Place(), Order.Fulfill(), Order.ProcessPayment(). However, these business processes don't represent things the business object is doing, rather things being done to the business object. It's a subtle difference, but it's very important.

                In Ivar Jacobson's Object-Oriented Software Engineering, he talks about how over time objects tend to evolve to have methods that are only used in a single use case. He separated the concepts of the "entity" object - which represents a business object that has persistent state - and the "control" object - which represents a process that modifies the state of one or more entities. In my experience, mapping use cases to control objects is a good first order approximation of your final system design.

                • 5. Re: Process/task search based on variables
                  Ronald van Kuijk Master

                   

                  "frantisek.kocun@gmail.com" wrote:

                  But I have found this use case:
                  You start business process on page where business object BO1 is present, business object creates another business object BO2 some tasks are present on the page where you edit BO1, some on the page where you edit BO2. Does it mean that I should store some kind of ssn and save the same in both objects? I thought that to search for tasks will make from this the same issue as if searching for business object.
                  I do not follow the last 2 sentences, sorry...

                  "frantisek.kocun@gmail.com" wrote:

                  And this one (only fictive not form business) case where business key is not enough:
                  Imagine "friend link" example. On the page of first user sees all requests he requested and he can cancel some of them -> key should be friend. User2 sees all the requests he can accept/reject -> key should be friend2 They can't have the same key. So solution for this is to have business key in TaskInstance not in ProcessInstance. And this will be the solution for first case as well and I can left out ssn form business object:) I think that it is better to refence object form process and not vice versa. Now we use this solution and I call it business object as "task owner" and the id of business task is stored in task variable. It is not the same as assigning task to user because authorization is there as well so it is assigning task to combination of showed business object and logged user. What do you think about this?

                  Actor-id's can be any strings, so also a combination of businessobject and userid. Then it is very easy if you know the user-id and the businessobject to only retrieve the correct tasks, but yes, kind of businesskey like functionality on task is going to be included in jBPM 4 afaik

                  • 6. Re: Process/task search based on variables
                    Ronald van Kuijk Master

                     

                    "frantisek.kocun@gmail.com" wrote:
                    When I look on jBPM.. tutorials I find only not OO examples. Application knows only tasks and processes..
                    maybe look at the seam dvd order example....


                    • 7. Re: Process/task search based on variables
                      fero kocun Newbie

                       

                      "kukeltje" wrote:
                      "frantisek.kocun@gmail.com" wrote:

                      But I have found this use case:
                      You start business process on page where business object BO1 is present, business object creates another business object BO2 some tasks are present on the page where you edit BO1, some on the page where you edit BO2. Does it mean that I should store some kind of ssn and save the same in both objects? I thought that to search for tasks will make from this the same issue as if searching for business object.
                      I do not follow the last 2 sentences, sorry...


                      I don't understand 2nd sentence neither:) My mistake. I thought if the solution for this case would be to have an String attribute in both of objects with the same value representing business key. Another solution is to reference taskinstance from object directly (what i don't like).

                      "kukeltje" wrote:

                      Actor-id's can be any strings, so also a combination of businessobject and userid. Then it is very easy if you know the user-id and the businessobject to only retrieve the correct tasks, but yes, kind of businesskey like functionality on task is going to be included in jBPM 4 afaik


                      That's great! I think it will solve all my problems. When it is going out?

                      • 8. Re: Process/task search based on variables
                        Ronald van Kuijk Master

                        this actor id stuff can be used *now*, just implement it that way

                        'businesskey's ' on task is under discussion, so do not count on it yet, btw, the target for an alpa1 release is 1 nov, so a full GA release is still way off

                        • 9. Re: Process/task search based on variables
                          brittm Novice

                          I would second what Ronald mentioned earlier about not trying too hard to store business keys in JBPM. We have a need to be able to look up processes (and tasks) very quickly by any one of various business keys: account number, order number, product number, etc. We created a "Business Keys" table that contains a row for each process instance and records any of the appropriate business key data in the appropriate column. All columns are indexed.

                          This solution is very performant. Because JBPM has some very direct relationships between processInstance, token, and taskInstance, returning the right tasks based on those business keys is performant as well.

                          To populate the table, the act of starting each processInstance calls an ActionHandler that looks up all the pertinent business keys based on our business logic and domain model.

                          • 10. Re: Process/task search based on variables
                            fero kocun Newbie

                             

                            "brittm" wrote:
                            I would second what Ronald mentioned earlier about not trying too hard to store business keys in JBPM. We have a need to be able to look up processes (and tasks) very quickly by any one of various business keys: account number, order number, product number, etc. We created a "Business Keys" table that contains a row for each process instance and records any of the appropriate business key data in the appropriate column. All columns are indexed.


                            Good idea, I will try it out.

                            "brittm" wrote:
                            This solution is very performant. Because JBPM has some very direct relationships between processInstance, token, and taskInstance, returning the right tasks based on those business keys is performant as well.


                            Performant? How performat? Can you be concrete? (Total number of process instances/task instances/new task instances per day/number of concurrent users...)I am really interested in this,cos I have never seen jBPM in a big application.

                            • 11. Re: Process/task search based on variables
                              brittm Novice

                               

                              Performant? How performat? Can you be concrete? (Total number of process instances/task instances/new task instances per day/number of concurrent users...)I

                              Well, certainly performant enough for anything that I would consider a typical task management system. Look at the simple query:
                              --TASK AGING
                              select distinct
                               pd.name_ AS process,
                               ti.id_ AS task_id,
                               tsk.name_ AS task,
                               ti.actorid_ as assignee,
                               ti.create_ as create_date,
                               ti.duedate_ as due_date
                              from
                               jbpm_taskinstance ti,
                               jbpm_task tsk,
                               jbpm_token t,
                               jbpm_processinstance pi,
                               jbpm_processdefinition pd
                              where
                               ti.end_ is null
                               and ti.task_ = tsk.id_
                               and ti.token_ = t.id_
                               and pi.id_ = t.processinstance_
                               and pd.id_ = pi.processdefinition_
                              ;

                              This is a very simply query, and limiting results to those tasks assigned to a particular actor or to tasks from a particular processInstance is obviously trivial. There are only four inner joins on columns that can (or should) be indexed. Add in one more inner join to a "Business Keys" table, and you can return all tasks based on any of your business keys.

                              If a query this simple is a performance concern, it is because you're truly dealing with many millions of rows or you're returning too many rows at once. I haven't seen a use case for a task management system that would really have many millions of rows, and data returned to a UI from the database should be paginated as part of the query (a user can't visually process more than 20 or 30 rows at a time, so don't force the user or the UI to handle much more than that.)

                              I don't know really how many "transactions" we've got going on in the course of a day, but I do know that with the simple data relationships in jBPM and our business key table and with the relatively small data sets we're consuming, any performance degradation will be the fault of our own business/UI tier design. For a modern data base, stored row count won't be a practical impact.

                              Our current application is a Seam/JPA app. We have about 70 group queues with maybe 300 users. We have a particular view in which users can see a series of tabs representing each group queue to which they belong or manage. They can select one of the tabs and will see the tasks in that queue. When a manager selects a group queue to view, in the body of the tab they are presented with two lists of the first 10 assigned tasks and the first 10 unassigned tasks in that queue (each listing is sorted by task priority and due date). If necessary, they can page through the tasks 10 at a time (going back to the data base each time). Each row communicates relevant task data from the task table in addition to customer name, account number, order number, and any associated jeopardy data.

                              For myself, when I look at this screen (being a universal manager in the system) I see all 70 group queues listed in 70 tabs down the left, each displaying how many unassigned tasks are in that queue. Clicking on a queue to view its tasks (the two tables of assigned and unassigned tasks) seems to take just at 2 seconds regardless of how many underlying tasks there are in the queue.

                              The view of an individual's personal queue (all tasks assigned to that actor) takes just at a second to present.

                              Of course any "report view" of the data is exactly that--a report--and the user can be expected to wait several seconds.