Search in sources :

Example 1 with TaskAlreadyClaimedException

use of org.camunda.bpm.engine.TaskAlreadyClaimedException in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testClaimAlreadyClaimedTaskByOtherUser.

@Test
public void testClaimAlreadyClaimedTaskByOtherUser() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    User user = identityService.newUser("user");
    identityService.saveUser(user);
    User secondUser = identityService.newUser("seconduser");
    identityService.saveUser(secondUser);
    // Claim task the first time
    taskService.claim(task.getId(), user.getId());
    try {
        taskService.claim(task.getId(), secondUser.getId());
        fail("ProcessEngineException expected");
    } catch (TaskAlreadyClaimedException ae) {
        testRule.assertTextPresent("Task '" + task.getId() + "' is already claimed by someone else.", ae.getMessage());
    }
    taskService.deleteTask(task.getId(), true);
    identityService.deleteUser(user.getId());
    identityService.deleteUser(secondUser.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) User(org.camunda.bpm.engine.identity.User) TaskAlreadyClaimedException(org.camunda.bpm.engine.TaskAlreadyClaimedException) Test(org.junit.Test)

Example 2 with TaskAlreadyClaimedException

use of org.camunda.bpm.engine.TaskAlreadyClaimedException in project camunda-bpm-platform by camunda.

the class ClaimTaskCmd method execute.

public Void execute(CommandContext commandContext) {
    ensureNotNull("taskId", taskId);
    TaskManager taskManager = commandContext.getTaskManager();
    TaskEntity task = taskManager.findTaskById(taskId);
    ensureNotNull("Cannot find task with id " + taskId, "task", task);
    checkClaimTask(task, commandContext);
    if (userId != null) {
        if (task.getAssignee() != null) {
            if (!task.getAssignee().equals(userId)) {
                // this, post-conditions of method already met.
                throw new TaskAlreadyClaimedException(task.getId(), task.getAssignee());
            }
        } else {
            task.setAssignee(userId);
        }
    } else {
        // Task should be assigned to no one
        task.setAssignee(null);
    }
    task.createHistoricTaskDetails(UserOperationLogEntry.OPERATION_TYPE_CLAIM);
    return null;
}
Also used : TaskManager(org.camunda.bpm.engine.impl.persistence.entity.TaskManager) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) TaskAlreadyClaimedException(org.camunda.bpm.engine.TaskAlreadyClaimedException)

Aggregations

TaskAlreadyClaimedException (org.camunda.bpm.engine.TaskAlreadyClaimedException)2 User (org.camunda.bpm.engine.identity.User)1 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)1 TaskManager (org.camunda.bpm.engine.impl.persistence.entity.TaskManager)1 Task (org.camunda.bpm.engine.task.Task)1 Test (org.junit.Test)1