Search in sources :

Example 1 with ProjectTaskService

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);
}
Also used : ProjectTaskService(com.axelor.apps.project.service.ProjectTaskService) ArrayList(java.util.ArrayList) PersistenceException(javax.persistence.PersistenceException) Frequency(com.axelor.apps.base.db.Frequency)

Aggregations

Frequency (com.axelor.apps.base.db.Frequency)1 ProjectTaskService (com.axelor.apps.project.service.ProjectTaskService)1 ArrayList (java.util.ArrayList)1 PersistenceException (javax.persistence.PersistenceException)1