Map.Entry<Task, TaskFormData> checked = checkTask(taskId, username);
if (!adminUser.equals(username)) {
List<Task> tasksForUser = taskService.createTaskQuery().taskId(taskId).taskCandidateUser(username).list();
if (tasksForUser.isEmpty()) {
throw new WorkflowException(
new IllegalArgumentException(username + " is not candidate for task " + taskId));
}
}
Task task;
try {
taskService.setOwner(taskId, username);
task = taskService.createTaskQuery().taskId(taskId).singleResult();
} catch (ActivitiException e) {
throw new WorkflowException("While reading task " + taskId, e);
}
return getFormTO(task, checked.getValue());
}