Search in sources :

Example 1 with PermissionDeniedException

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

the class HumanTasksLifecycleAPITest 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 : ContentData(org.jbpm.task.service.ContentData) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary) PermissionDeniedException(org.jbpm.task.service.PermissionDeniedException)

Aggregations

ArrayList (java.util.ArrayList)1 TaskSummary (org.jbpm.task.query.TaskSummary)1 ContentData (org.jbpm.task.service.ContentData)1 PermissionDeniedException (org.jbpm.task.service.PermissionDeniedException)1 LocalTaskService (org.jbpm.task.service.local.LocalTaskService)1