3 Replies Latest reply on Jun 23, 2010 1:08 AM by mwohlf

    Calling TaskService.CompleteTask from inside a Java callback

    joegottman

      After a task is assigned, I would like to use a Java callback to run some code and then call TaskService.CompleteTask() on the task.  I tried calling CompleteTask from both an AssignmentHandler class and an EventListener that listended for the Task's assign event.  In both cases, an exception was thrown. 

       

      When I called it from the AssignmentHandler, CompleteTask() threw an IllegalArguementException with the message "id to load is required for loading".

       

      When I called it form the assign EventListener, CompleteTask() and my EventListener's notify() method complete without an error, but later a NullPointerException is thrown because the following code at lines 116 and 117 of the org.jbpm.jpdl.internal.activity.TaskActivity class's signal method:

       

      TaskImpl task = (TaskImpl) taskDbSession.findTaskByExecution(execution);

      task.setSignalling(false);

       

       

      In the first line, an null task is returned, and so the second line causes the NullPointerException.

       

      I would appreciate any advice on how to safely call TaskService.CompleteTask from an AssignmentHandler, an EventListener, or any other Java callback accessable from a Task.

        • 1. Re: Calling TaskService.CompleteTask from inside a Java callback
          mwohlf

          I am not sure what you try to do, but an AssignmentHandler or an EventListener is not the right place to complete a task or send any signals to the process instance.

          Maybe what you try to do can be implemented with the <custom /> tag.

          Basically you implement a ExternalActivityBehaviour and use execution.waitForSignal() or execution.take(transition) if you want the process instance to stop or take a certain transition.

          • 2. Re: Calling TaskService.CompleteTask from inside a Java callback
            joegottman

            I'm sorry if my question was not clear enough.  I have some business logic I need to perform for a task, and I have two requirements:

             

               1) I need to automatically start performing the code for the business logic when the task is assigned.

               2) I need to automatically alert jbpm when the business logic code finishes so it can mark the task as complete.

             

             

            For requirement 1, it seemed like either an AssignmentHandler or an EventWatcher that was watching for the assign event would work to know when the task was assigned, but neither one seems capable of handling the second requirement.

            • 3. Re: Calling TaskService.CompleteTask from inside a Java callback
              mwohlf

              Hi Joe,

              Can you please explain what kind of task are you talking about?

              If it's a human task why do you want to mark it as "complete" by your business logic and if it is business logic that is performed within the task why do you assign it and to whom?

               

              Did you check out

              http://docs.jboss.com/jbpm/v4/userguide/html_single/#custom ?