Search in sources :

Example 6 with LocalTaskService

use of org.jbpm.task.service.local.LocalTaskService in project jBPM5-Developer-Guide by Salaboy.

the class HumanTasksLifecycleAPITest method claimNextAvailable.

@Test
public void claimNextAvailable() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    potentialOwners.add(users.get("watman"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // we don't need to query for our task to see what we will claim, just claim the next one available for us
    localTaskService.claimNextAvailable("watman", "en-UK");
    List<Status> status = new ArrayList<Status>();
    status.add(Status.Ready);
    List<TaskSummary> salaboyTasks = localTaskService.getTasksAssignedAsPotentialOwnerByStatus("salaboy", status, "en-UK");
    assertEquals(0, salaboyTasks.size());
}
Also used : ContentData(org.jbpm.task.service.ContentData) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary)

Example 7 with LocalTaskService

use of org.jbpm.task.service.local.LocalTaskService in project jBPM5-Developer-Guide by Salaboy.

the class HumanTasksLifecycleAPITest method regularFlowTest.

@Test
public void regularFlowTest() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> tasksAssignedAsPotentialOwner = localTaskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    // We know that there is just one task available so we get the first one
    Long taskId = tasksAssignedAsPotentialOwner.get(0).getId();
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task simpleTask = localTaskService.getTask(taskId);
    assertEquals(Status.Reserved, simpleTask.getTaskData().getStatus());
    // In order start working with this task we call the start() method
    localTaskService.start(simpleTask.getId(), "salaboy");
    // The task is now In Progress
    simpleTask = localTaskService.getTask(taskId);
    assertEquals(Status.InProgress, simpleTask.getTaskData().getStatus());
    // PERFORM THE TASK ACTIVITY HERE, the user need to perform the required activities here
    // Once the Task activity is performed the user can complete the task,
    // Notice that we are completing this task without results
    localTaskService.complete(simpleTask.getId(), "salaboy", null);
    // We can check the task status after completion
    simpleTask = localTaskService.getTask(taskId);
    assertEquals(Status.Completed, simpleTask.getTaskData().getStatus());
}
Also used : ContentData(org.jbpm.task.service.ContentData) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary)

Example 8 with LocalTaskService

use of org.jbpm.task.service.local.LocalTaskService in project jBPM5-Developer-Guide by Salaboy.

the class TaskServiceMinaSyncTest method claimNextAvailable.

@Test
public void claimNextAvailable() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    potentialOwners.add(users.get("watman"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // we don't need to query for our task to see what we will claim, just claim the next one available for us
    localTaskService.claimNextAvailable("watman", "en-UK");
    List<Status> status = new ArrayList<Status>();
    status.add(Status.Ready);
    List<TaskSummary> salaboyTasks = localTaskService.getTasksAssignedAsPotentialOwnerByStatus("salaboy", status, "en-UK");
    assertEquals(0, salaboyTasks.size());
}
Also used : LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary) Test(org.junit.Test)

Example 9 with LocalTaskService

use of org.jbpm.task.service.local.LocalTaskService in project jBPM5-Developer-Guide by Salaboy.

the class TaskServiceMinaSyncTest method claimConflictAndRetry.

@Test
public void claimConflictAndRetry() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    potentialOwners.add(users.get("watman"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> salaboyTasks = localTaskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    // We know that there is just one task available so we get the first one
    Long salaboyTaskId = salaboyTasks.get(0).getId();
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task salaboyTask = localTaskService.getTask(salaboyTaskId);
    assertEquals(Status.Ready, salaboyTask.getTaskData().getStatus());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> watmanTasks = localTaskService.getTasksAssignedAsPotentialOwner("watman", "en-UK");
    // We know that there is just one task available so we get the first one
    Long watmanTaskId = watmanTasks.get(0).getId();
    assertEquals(watmanTaskId, salaboyTaskId);
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task watmanTask = localTaskService.getTask(watmanTaskId);
    assertEquals(Status.Ready, watmanTask.getTaskData().getStatus());
    localTaskService.claim(watmanTask.getId(), "watman");
    try {
        localTaskService.claim(salaboyTask.getId(), "salaboy");
    } catch (PermissionDeniedException ex) {
        // The Task is gone.. salaboy needs to retry
        assertNotNull(ex);
    }
}
Also used : LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary) Test(org.junit.Test)

Aggregations

LocalTaskService (org.jbpm.task.service.local.LocalTaskService)9 ArrayList (java.util.ArrayList)5 TaskSummary (org.jbpm.task.query.TaskSummary)5 ContentData (org.jbpm.task.service.ContentData)3 TaskService (org.jbpm.task.service.TaskService)2 Test (org.junit.Test)2 DetailedTaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.DetailedTaskSummariesModel)1 SimpleTaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.SimpleTaskSummariesModel)1 TaskParametersTableModel (com.salaboy.jbpm5.dev.guide.tablemodel.TaskParametersTableModel)1 TaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.TaskSummariesModel)1 MySimpleTaskFormJPanel (com.salaboy.jbpm5.dev.guide.taskform.MySimpleTaskFormJPanel)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 JPanel (javax.swing.JPanel)1 LocalHTWorkItemHandler (org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler)1 Group (org.jbpm.task.Group)1 TaskService (org.jbpm.task.TaskService)1 User (org.jbpm.task.User)1 PermissionDeniedException (org.jbpm.task.service.PermissionDeniedException)1