1 Reply Latest reply on Oct 25, 2012 12:35 PM by tlucz

    Using TaskService directly

    tlucz Newbie

      Hi,

      I've started using jBPM 5.3.0.Final. I want to use HumanTasks embedded in my application. So basing on thread:

       

      https://community.jboss.org/thread/162963?start=15&tstart=1

       

      I created my own LocalHumanTaskHandler where in constructor TaskServiceSession is created:

       

              TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());

              taskSession = taskService.createSession();

              this.session=session;

       

      ExecuteWorkItem method is taken from GenericCommandBasedWSHumanTaskHandler. The only change is to invoke:

       

      taskSession.addTask(task, content);

       

      instead of:

       

      client.addTask(task, content, new TaskAddedHandler(workItem.getId()));

       

       

      I can work with HT in a way e.g.:

       

      List<TaskSummary> taskList = wrapper.taskServiceSession.getTasksAssignedAsPotentialOwner("john", "en-UK");

       

      wrapper.taskServiceSession.taskOperation(Operation.Complete, lastTask.getId(), "john", null, null, null);

       

       

      It almost works correctly, task data is stored in DB but process instance is not updated after complete task. The problem is how can I register TaskEventHandlers. In GenericCommandBasedWSHumanTaskHandler there is a method:

       

      private void registerTaskEventHandlers() {

              TaskEventKey key = new TaskEventKey(TaskCompletedEvent.class, -1);

              TaskCompletedHandler eventResponseHandler = new TaskCompletedHandler();

              client.registerForEvent(key, false, eventResponseHandler);

              key = new TaskEventKey(TaskFailedEvent.class, -1);

              client.registerForEvent(key, false, eventResponseHandler);

              key = new TaskEventKey(TaskSkippedEvent.class, -1);

              client.registerForEvent(key, false, eventResponseHandler);

          }

       

      but I have no client so I have no possibility to register these events. Also TaskServiceSession object has no method to register ResponseHandlers. How can I resolve it?

       

      I also read thread

      https://community.jboss.org/thread/204619?tstart=270

      but in this case I have no idea how to create TaskService which I need to pass to LocalHTWorkItemHandler.

       

      Thanks in advance for any help.

      kr,

      Tadeusz

        • 1. Re: Using TaskService directly
          tlucz Newbie

          I solved it. Instead of creation

           

          taskSession = taskService.createSession();

           

          in my own LocalHumanTaskHandler's constructor I needed instatiate LocalTaskService:

           

          TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());

          lts = new LocalTaskService(taskService);

           

          then it is possible to register events:

           

          private void registerTaskEventHandlers() {

                  TaskEventKey key = new TaskEventKey(TaskCompletedEvent.class, -1);

                  TaskCompletedHandler eventResponseHandler = new TaskCompletedHandler();

                  lts.registerForEvent(key, false, eventResponseHandler);

                  key = new TaskEventKey(TaskFailedEvent.class, -1);

                  lts.registerForEvent(key, false, eventResponseHandler);

                  key = new TaskEventKey(TaskSkippedEvent.class, -1);

                  lts.registerForEvent(key, false, eventResponseHandler);

              }

           

          Finally, my HT works correctly and can communicate with process instance.

           

           

          kr,

          Tadeusz

           

           

           

           


          1 of 1 people found this helpful