Search in sources :

Example 1 with TaskNameAlreadyExistsException

use of org.motechproject.tasks.exception.TaskNameAlreadyExistsException in project motech by motech.

the class TaskServiceImpl method validateName.

private void validateName(Task task) {
    Long taskId = task.getId();
    List<Task> tasksWithName = tasksDataService.findTasksByName(task.getName());
    if (taskId == null && tasksWithName.size() > 0) {
        throw new TaskNameAlreadyExistsException(task.getName());
    } else if (taskId != null && tasksWithName.size() > 0 && !tasksWithName.get(0).getId().equals(taskId)) {
        throw new TaskNameAlreadyExistsException(task.getName());
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TaskNameAlreadyExistsException(org.motechproject.tasks.exception.TaskNameAlreadyExistsException)

Aggregations

Task (org.motechproject.tasks.domain.mds.task.Task)1 TaskNameAlreadyExistsException (org.motechproject.tasks.exception.TaskNameAlreadyExistsException)1