13 Replies Latest reply on Oct 11, 2006 4:10 PM by cpob

    Task Nodes - conditionally create tasks?

    cpob

      (I'm using jBPM 3.1.2)

      We have task nodes, and are creating a number of tasks on each task node.

      There will always be one mandatory task per task node, and then a number of optional tasks per task node.

      We would only like to create the optional task instances when the user wants, not automatically by jBPM.

      However, we want the mandatory task instance to be automatically created by jBPM, so we can't use the create-tasks="false" ability of the task node.

      I suggest an enhancement, and if people think its worthy, I'll add it to JIRA. I think task definitions should have another Y/N column "AUTOCREATE" (or something along those lines). The default would be yes, and then the task node would create only those which are set to be automatically created.

      I searched the forum and JIRA, didn't find any reference to this matter, but sorry if its been talked about.

        • 1. Re: Task Nodes - conditionally create tasks?
          kukeltje

          then why not have the task created by jbpm and ADD additional tasks runtime.... afaik that is a normal supported option.

          • 2. Re: Task Nodes - conditionally create tasks?
            cpob

            To add additional tasks during runtime, you'd have to create new task definitions. These tasks are already defined and created, we just don't want instances automatically started for every task def when the task node enters.

            • 3. Re: Task Nodes - conditionally create tasks?
              olivier_debels

              I think you can do something like:

              Adding a task definition directly under the process definition (and not in the task node) and play with this:

              * Then you can create a task instance of the mandatory task in the task node:
              + By using an event if you want to use the task definition under the process definition
              + By putting another task definition in the task node and setting "create-task" true

              * You can create the other task instances using event handlers for example.

              If you look at the test cases under org.jbpm.jpdl.patterns you can find some examples.

              Hope this helps,

              Olivier.

              • 4. Re: Task Nodes - conditionally create tasks?
                cpob

                 

                Then you can create a task instance of the mandatory task in the task node


                There's no way to tie a task instance to a task node. It's only through the task def that there's a link between task/tasknode.

                I'm already creating the other task instances using event handlers, but its important we have the task/tasknode relationship, and important not all are created at node entry.

                We could just have NO tasks created at node entry, and then we manually create a task instance ourselves, but allowing the tasks to be created conditionally seems more elegant.

                • 5. Re: Task Nodes - conditionally create tasks?
                  olivier_debels

                   

                  There's no way to tie a task instance to a task node. It's only through the task def that there's a link between task/tasknode.


                  AFAIK you don't need the link task/tasknode. You can just have a task def tied to the process definition and create task instances in the task node (using event handlers f.e.). You can actually create task instances in any node.

                  but it's important we have the task/tasknode relationship


                  Why?

                  We could just have NO tasks created at node entry, and manually create a task instance ourselves, but allowing the tasks to be created conditionally seems more elegant


                  You can also create the tasks defined in the task node (mandatory ones), and create the ones defined at process definition level optionally.




                  • 6. Re: Task Nodes - conditionally create tasks?
                    cpob

                     

                    Olivier_Debels wrote:
                    AFAIK you don't need the link task/tasknode. You can just have a task def tied to the process definition and create task instances in the task node (using event handlers f.e.). You can actually create task instances in any node.


                    We're already doing this. We have optional process tasks being created along the flow with various task nodes. We are creating them, tied to the process, not the task node, and they just need to be completed anytime during the process.

                    However....

                    Olivier_Debels wrote:
                    but it's important we have the task/tasknode relationship


                    Why?


                    It is very important that we have some optional node tasks created with a task node relationship, because we want some optional node tasks to block the task node. If 1 mandatory and 3 optional node task instances are associated with a given node, we want the node to be blocking until all 4 tasks are completed.


                    • 7. Re: Task Nodes - conditionally create tasks?
                      olivier_debels


                      Well I guess you can create your own custom task instance which can deal with this. It just requires overriding of the end() function and keeping a TaskNode reference. Haven't tried it but I guess this would work.


                      • 8. Re: Task Nodes - conditionally create tasks?
                        cpob

                         

                        "Olivier_Debels" wrote:

                        Well I guess you can create your own custom task instance which can deal with this. It just requires overriding of the end() function and keeping a TaskNode reference. Haven't tried it but I guess this would work.


                        I don't think that would change my issue of creating optional task instances only when we want.

                        Making the change to support the AUTOCREATE column is far simpler than creating an optional task node. All that is needed is the if..statement in TaskNode's execute method and then support for the new column in the mapping/etc.

                        • 9. Re: Task Nodes - conditionally create tasks?
                          olivier_debels

                           

                          "cpob" wrote:

                          Making the change to support the AUTOCREATE column is far simpler than creating an optional task node. All that is needed is the if..statement in TaskNode's execute method and then support for the new column in the mapping/etc.


                          Yep, I agree.

                          I this also useable if you want to create 2 mandatory and 3 optional instances of the same task def?

                          And what if the task def is not defined in a task node? I don't think a ref to task defs is possible.

                          Just wandering if the task/task node link as it exists now can' t be extended.

                          Anyway, I think your solution indeed gives an added value.

                          Thx,

                          Olivier.

                          • 10. Re: Task Nodes - conditionally create tasks?
                            cpob

                             

                            "Olivier_Debels" wrote:
                            "cpob" wrote:

                            Making the change to support the AUTOCREATE column is far simpler than creating an optional task node. All that is needed is the if..statement in TaskNode's execute method and then support for the new column in the mapping/etc.


                            Yep, I agree.

                            I this also useable if you want to create 2 mandatory and 3 optional instances of the same task def?


                            Yes, that is what we would be using it for. It would allow the task to control it's fate for creation.

                            "Olivier_Debels" wrote:
                            And what if the task def is not defined in a task node? I don't think a ref to task defs is possible.

                            Just wandering if the task/task node link as it exists now can' t be extended.


                            Not sure if I follow you with this one. If a task def is not linked to a task node, it would just be the process task like we talked about. It would still be created (if using our flag idea) conditionally, depending on if the user creates the instances, or a task event, etc.

                            • 11. Re: Task Nodes - conditionally create tasks?
                              olivier_debels

                               

                              "Olivier_Debels" wrote:
                              And what if the task def is not defined in a task node? I don't think a ref to task defs is possible.

                              Just wandering if the task/task node link as it exists now can' t be extended.


                              Not sure if I follow you with this one. If a task def is not linked to a task node, it would just be the process task like we talked about. It would still be created (if using our flag idea) conditionally, depending on if the user creates the instances, or a task event, etc.


                              Never mind, I was just thinking about splitting definition of a task and linkage to a node (task node). Anyway at some point you need to define the link.

                              Greetz,

                              Olivier.



                              • 12. Re: Task Nodes - conditionally create tasks?
                                tom.baeyens

                                didn't read the whole thread. sorry if i duplicate an answer.

                                ...but did you consider defining the tasks in the task-node and specify

                                create-tasks="false"
                                on the task node ? that way, can still fetch the task definitions and create instances at runtime and you have the
                                link to the task-node.

                                • 13. Re: Task Nodes - conditionally create tasks?
                                  cpob

                                   

                                  "tom.baeyens@jboss.com" wrote:
                                  didn't read the whole thread. sorry if i duplicate an answer.

                                  ...but did you consider defining the tasks in the task-node and specify
                                  create-tasks="false"
                                  on the task node ? that way, can still fetch the task definitions and create instances at runtime and you have the
                                  link to the task-node.


                                  I mentioned this as an alternative in one of my earlier posts. However, the problem with this, is that it puts the burden of creating the mandatory tasks on us. Something we'd much rather let jBPM handle, since it does it already.

                                  Sure, it's not hard to make our code create the mandatory task instances, as we are already creating optional task instances, but I'm a big fan of configurability :)