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());
}
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;
}
Aggregations