use of com.axelor.apps.project.service.ProjectTaskService in project axelor-open-suite by axelor.
the class ProjectTaskProjectRepository method save.
@Override
public ProjectTask save(ProjectTask projectTask) {
List<String> composedNames = new ArrayList<>();
if (projectTask.getId() != null) {
composedNames.add("#" + projectTask.getId());
}
composedNames.add(projectTask.getName());
projectTask.setFullName(String.join(" ", composedNames));
ProjectTaskService projectTaskService = Beans.get(ProjectTaskService.class);
if (projectTask.getDoApplyToAllNextTasks() && projectTask.getNextProjectTask() != null && projectTask.getHasDateOrFrequencyChanged()) {
// remove next tasks
projectTaskService.removeNextTasks(projectTask);
// regenerate new tasks
projectTask.setIsFirst(true);
}
Frequency frequency = projectTask.getFrequency();
if (frequency != null && projectTask.getIsFirst() && projectTask.getNextProjectTask() == null) {
if (projectTask.getTaskDate() != null) {
if (frequency.getEndDate().isBefore(projectTask.getTaskDate())) {
throw new PersistenceException(I18n.get(IExceptionMessage.PROJECT_TASK_FREQUENCY_END_DATE_CAN_NOT_BE_BEFORE_TASK_DATE));
}
} else {
throw new PersistenceException(I18n.get(IExceptionMessage.PROJECT_TASK_FILL_TASK_DATE));
}
projectTaskService.generateTasks(projectTask, frequency);
}
if (projectTask.getDoApplyToAllNextTasks()) {
projectTaskService.updateNextTask(projectTask);
}
projectTask.setDoApplyToAllNextTasks(false);
projectTask.setHasDateOrFrequencyChanged(false);
return super.save(projectTask);
}
Aggregations