How to Add a Task with the jBPM Human Task API

import static java.lang.System.out;

import java.util.ArrayList;
import java.util.List;

import org.drools.SystemEventListenerFactory;
import org.jbpm.task.OrganizationalEntity;
import org.jbpm.task.PeopleAssignments;
import org.jbpm.task.Task;
import org.jbpm.task.TaskData;
import org.jbpm.task.User;
import org.jbpm.task.service.TaskClient;
import org.jbpm.task.service.mina.MinaTaskClientConnector;
import org.jbpm.task.service.mina.MinaTaskClientHandler;
import org.jbpm.task.service.responsehandlers.BlockingAddTaskResponseHandler;

public final class JbpmSample {

  public static void main(final String[] args) throws Exception {
    final TaskClient client = new TaskClient(new MinaTaskClientConnector("SampleClient", new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));

    if (client.connect("localhost", 9123)) {
      final BlockingAddTaskResponseHandler handler = new BlockingAddTaskResponseHandler();

      final Task task = new Task();

      final PeopleAssignments peopleAssignments = new PeopleAssignments();

      final List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();

      potentialOwners.add(new User("userId"));

      peopleAssignments.setPotentialOwners(potentialOwners);

      task.setPeopleAssignments(peopleAssignments); // optional

      task.setTaskData(new TaskData()); // required

      client.addTask(task, null, handler);

      out.println(handler.getTaskId());

      client.disconnect();
    }

  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s