1 Reply Latest reply on Sep 7, 2011 3:27 AM by Esteban Aliverti

    user task or script task ?

    joachyt Newbie

      hi ,

      I am new to workflow. Appreciate any pointers on this design question.

       

      1. is it normal or best practice to design workflows such that they can be run with UI input supplementing the data and also the workflow can be run as a batch job with data supplied to the workflow by non UI means ?

         If so, should I have script tasks which will undertake UI handling when run in the UI context and pull the data by some other means [xml, db etc] when run in batch mode ?

       

        In general when you design a workflow, is it the case that you almost always know at design time whether you are going to have certain action hnalded by user or some other script ?

       

      2. In my problem, I have some backend java objects that do the actual work. I need to call a specific method on them as part of my workflow actions. When I use "script task" and java as the script option, the designer takes the java code snippet. can I do something like this :

           Service service = ServiceLocator.getService("some identifier");

           // access some state data from the workflow

           service.invoke("data retrieved from workflow");

          Is this the correct usage ?

          Is there a standard interface that jbpm would recognise that my service objects can implement , thereby , my service objects are first class workflow handlers.

       

      appreciate any help.

      thanks

      Joe

        • 1. Re: user task or script task ?
          Esteban Aliverti Master

          Good questions, I will try to shed some light here:

           

          First advise: DO NOT USE SCRIPT TASKS! Most of the times, during design time you already have the information if a particular task is going to be handled by a Human User or an external Service. Here, "external" can be: external of the process, i.e. a Java class, or external of the application, like a web-service or similar.

          JBPM5 (and BPMN2) has 2 different ways to interact with Human and Services. User Tasks and Tasks (You also have Service Tasks, but I don't like them. You can do a research about them too if you want to ). When you design your process, you need to choose one or the other.

          In runtime, when you want to execute the process, you need to register a handler for each of the Tasks (whether Human or not) present in the process definition. When the execution reaches a Task node, the handler gets executed.

          These handlers must implement:

           

          org.drools.runtime.process.WorkItemHandler

           

          and they must be registered before the process is executed using:

           

          ksession.getWorkItemManager().registerWorkItemHandler("NAME_OF_WI_NODE", new MyParticularHandler());

           

          In the case of Human Tasks, jBPM already comes with a default handler that you use for all the Human Tasks nodes of your process. The name of this handler is WSHumanTaskHandler. This handler will communicate with the Human Task Server implementation provided by jBPM5 and create a task there every time it is executed. The subclass WSHumanTaskHandler that you need to use will depend in the communication protocol you want to use between the handler and the Human Task Server (AFAIK, at the moment 2 protocols are supported: Mina and JMS).

           

          In your particular situation where you want to run the same process and in some of the executions the Human Tasks nodes can be performed by Services and in some other real Users must take care of them, I would say that you can achieve this using different Handlers implementation for the Human Tasks Nodes.

          So, when the process needs to run with real Users, you can register the defautl Human Task Handler provided by jBPM5. When you want to mock these users using Services, you can provide you own handler that will get the parameters from the process, execute whatever logic they need and return what the original Human Task handler returned.  So, basically, you will be emulating a Human Task using a custom Handler.

           

          Best Regards,