13 Replies Latest reply on Jul 17, 2010 3:29 AM by felixkjose

    Creating tasks in a loop with JBPM 4.3

      We have a requirement to create tasks in a loop and the graph should not be completed untill all the tasks are complete. Can someone give an example how can this be done with 4.3.
        • 1. Re: Creating tasks in a loop with JBPM 4.3
          Any thoughts?
          • 2. Re: Creating tasks in a loop with JBPM 4.3
            ustone

            Hmmm....i have the same problem...i tried an fork decision join solution but this only works for an constant value of iterations because the multiplicity of the join attribute must be an integer constant.

             

            Now i thinking about an event based mechanism with forking and starting subprocesses explicite in a java class....

             

            I think this is a common problem so it would be nice to see any suggestions....

             

            Thanx for advance

            uli

            • 3. Re: Creating tasks in a loop with JBPM 4.3
              swiderski.maciej

              Hi,

               

              Have you tried with decision point that will check if all tasks are completed and if not will move back to the task node again?

               

              it could look like this (the simplest case):

               

                               ---------

                              /             \

              start -> task -> decision -> end

               

              Cheers,

              Maciej

              • 4. Re: Creating tasks in a loop with JBPM 4.3
                ustone

                Yes, but this is not the original reqiurement....

                 

                We had following scenario:

                 

                A person create a basket of positions and put this basket into an workflow for checking issues reagarding the whole basket. Then in a further step tasks for every postions have to generated, because different people has to check different things on every position depend on the kind of position.

                 

                With your suggestion all the positions would checked sequentially but i need a parallel way to complete the basket-wf in shorter time...

                 

                I can implement a java task that start manually the correct position-wf but i feel uncomfortable with this solution....

                 

                hope somebody had a same problem, because i can't believe that i'm the first with this one ;-)

                 

                thanx in advance

                • 5. Re: Creating tasks in a loop with JBPM 4.3
                  swiderski.maciej

                  Yes, I agree with you but my reply was to TT since I did not know your use case.

                   

                  What you are saying is that you would like to create unlimited/unknown number of tasks that are not modeled as part of the process definition - did I understand you correctly?

                  • 6. Re: Creating tasks in a loop with JBPM 4.3
                    ustone

                    Yes ...

                     

                    I would say that's exacltly the problem that i have: a unknown number of tasks, depending on the content of the basket and so i don't have any chance to model it in the process definition....

                    • 7. Re: Creating tasks in a loop with JBPM 4.3
                      swiderski.maciej

                      ok, now we are on the same page

                       

                      Inthat case I don't think there is a generic way to do it. Since it isnot on model level then it does not have support from jpdl. According to dev guide loops can be achieved either by transitions or by node composition.

                      In your case any of them is not applicable, so it seem like doing it programatically is the only way.

                       

                      Cheers,

                      Maciej

                      • 8. Re: Creating tasks in a loop with JBPM 4.3
                        ustone

                        hmmm..ok...that's not the thing i want to hear ;-)

                         

                        so i played around and tried something...

                         

                        Here is my xml ..(java classes are omitted because calls are selfdescribing):

                         

                        ------------------------------------------------------

                         

                        <?xml version="1.0" encoding="UTF-8"?>

                         

                        <process key="LOOP" name="Loop" xmlns="http://jbpm.org/4.0/jpdl">
                            <start g="274,7,48,48" name="startNode">
                                <transition g="-45,-18" name="to initialdecideForkAgain" to="decideForkAgain"/>
                            </start>
                            <end g="281,755,48,48" name="endNode"/>

                         


                            <java class="my.jbpm.loop.TestActivity" g="63,316,92,52" method="sayHello" name="sayHello">
                                <transition g="-61,-18" name="to joinHello" to="joinHello"/>
                            </java>
                            <java class="my.jbpm.loop.TestActivity" g="78,155,92,52" method="decreaseForkCounter" name="decreaseForkCounter" var="request">
                                <arg>
                                    <object expr="#{request}"/>
                                </arg>
                                <transition g="-43,-18" name="to forkHello" to="forkHello"/>
                            </java>
                            <decision g="279,118,48,48" name="decideForkAgain">
                                <handler class="my.jbpm.loop.ForkAgainHandler" />

                         

                                <transition g="-37,-18" name="FORK_AGAIN" to="decreaseForkCounter"/>
                                <transition g="746,372:-58,-18" name="FORK_NOT_AGAIN" to="decideJoinAgain"/>

                         


                            </decision>
                            <fork g="280,213,48,48" name="forkHello">
                                <transition g="-45,-18" name="to sayHello" to="sayHello"/>
                                <transition g="-77,-18" name="to decideForkAgain" to="decideForkAgain"/>
                            </fork>
                            <join g="278,399,48,48" name="joinHello">
                                <transition g="-61,-18" name="to increaseJoinCounter" to="increaseJoinCounter"/>
                            </join>

                         


                            <java class="my.jbpm.loop.TestActivity" g="66,474,92,52" method="increaseJoinCounter" name="increaseJoinCounter" var="request">
                                <arg>
                                    <object expr="#{request}"/>
                                </arg>
                                <transition g="-68,-18" name="to decideJoinAgain" to="decideJoinAgain"/>
                            </java>

                         


                            <decision g="277,606,48,48" name="decideJoinAgain">
                                <handler class="my.jbpm.loop.JoinAgainHandler" />
                                <transition g="-61,-18" name="JOIN_NOT_AGAIN" to="endNode"/>
                                <transition g="-58,-18" name="JOIN_AGAIN" to="joinHello"/>
                            </decision>
                        </process>

                        ------------------------------------------------------

                         

                        The main idea behind this is to count the number of forks and joins to know how often i have to fork and i have to join. Values are saved in the workflow object itself.....

                         

                        [Join|Fork]AgainHandler do evaluate the values to decide if antother fork/join has to do....

                        TestAactivity only in/decrease the counter and do some "Hello" output....

                         

                        I can attach a little zip with the whole project if somebody is interested...

                         

                        What do you think? Are there any problems with this kind of problem solution.....

                        • 9. Re: Creating tasks in a loop with JBPM 4.3
                          swiderski.maciej

                           

                          hmmm..ok...that's not the thing i want to hear ;-)      

                          Just don't take my opinion as final word, it is just that is what I think/know at the moment. Perhaps someone else can give another hints.

                           

                          It would be good if you attach the project, it is much easier to take a look at diagram than read xml...

                           

                          /Maciej

                          • 10. Re: Creating tasks in a loop with JBPM 4.3
                            ustone

                            Ok here is it.....you can run it with

                             

                            ant Starter

                            • 11. Re: Creating tasks in a loop with JBPM 4.3
                              swiderski.maciej

                              Thanks for the attachment, much easier to follow

                               

                              I think it should work quite well, it's a bit confusing (at least at first look) but that should cover your use case.

                               

                              Perhaps you could try to make it more business focused, meaning create some groups of activities per position types or so - if possible and reasonable.This should give you some feeling that the process is modeled, visible forks and joins and not only looping

                               

                              To me your process seems to be very technical that business experts can have problems to follow...but it could be only me...

                              • 12. Re: Creating tasks in a loop with JBPM 4.3
                                ustone

                                Thanx for your efforts...

                                 

                                i further developed this sample so that the sayHello Activity is an custom Java Task which start different random subprocesses depending on the type of position....

                                • 13. Re: Creating tasks in a loop with JBPM 4.3
                                  felixkjose

                                  Hi,

                                   

                                  Can you please share the same as I am facing a problem with dynamic forking. If you share the same

                                   

                                  "

                                  i further developed this sample so that the sayHello Activity is an custom Java Task which start different random subprocesses depending on the type of position...."

                                   

                                  It will be very helpful for me to solve my issue. Please send me the same.

                                   

                                  Thank you and Regards,

                                  Felix K Jose