issue-77 #105

Merged
sebastian merged 17 commits from issue-77 into master 2024-03-16 10:12:35 +01:00
4 changed files with 50 additions and 4 deletions
Showing only changes of commit e58e6addb9 - Show all commits

View File

@ -124,4 +124,8 @@ public abstract class AbstractSchedule {
return (int) duration.toMinutes(); return (int) duration.toMinutes();
} }
} }
public abstract AbstractSchedule cloneSchedule();
public abstract void shiftSchedule(long numberDays);
} }

View File

@ -71,4 +71,15 @@ public class AdvancedTaskSchedule extends AbstractSchedule {
public boolean isMissed(LocalDateTime timeReference) { public boolean isMissed(LocalDateTime timeReference) {
return startTime == null && scheduleEnd.toLocalDate().isBefore(timeReference.toLocalDate()); return startTime == null && scheduleEnd.toLocalDate().isBefore(timeReference.toLocalDate());
} }
@Override
public AbstractSchedule cloneSchedule() {
return new AdvancedTaskSchedule(this.task, this.scheduleStart, this.scheduleEnd);
}
@Override
public void shiftSchedule(long numberDays) {
this.scheduleStart = this.scheduleStart.plusDays(numberDays);
this.scheduleEnd = this.scheduleEnd.plusDays(numberDays);
}
} }

View File

@ -52,4 +52,14 @@ public class BasicTaskSchedule extends AbstractSchedule{
public boolean isMissed(LocalDateTime timeReference) { public boolean isMissed(LocalDateTime timeReference) {
return startTime == null && scheduleDate.isBefore(timeReference.toLocalDate()); return startTime == null && scheduleDate.isBefore(timeReference.toLocalDate());
} }
@Override
public AbstractSchedule cloneSchedule() {
return new BasicTaskSchedule(this.task, this.scheduleDate);
}
@Override
public void shiftSchedule(long numberDays) {
this.scheduleDate = this.scheduleDate.plusDays(numberDays);
}
} }

View File

@ -4,10 +4,8 @@ import core.api.models.timemanager.tasks.repeatinginfo.DeadlineStrategy;
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatDayInfo; import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatDayInfo;
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekDayInfo; import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekDayInfo;
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo; import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo;
import core.entities.timemanager.Task; import core.entities.timemanager.*;
import core.entities.timemanager.TaskSerie; import core.repositories.timemanager.ScheduleRepository;
import core.entities.timemanager.TaskSerieItem;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository; import core.repositories.timemanager.TaskRepository;
import core.repositories.timemanager.TaskSerieItemRepository; import core.repositories.timemanager.TaskSerieItemRepository;
import core.repositories.timemanager.TaskSeriesRepository; import core.repositories.timemanager.TaskSeriesRepository;
@ -16,6 +14,7 @@ import org.springframework.stereotype.Service;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -27,11 +26,14 @@ public class TaskSeriesService {
@Autowired private TaskRepository taskRepository; @Autowired private TaskRepository taskRepository;
@Autowired private TaskSeriesRepository taskSeriesRepository; @Autowired private TaskSeriesRepository taskSeriesRepository;
@Autowired private TaskSerieItemRepository taskSerieItemRepository; @Autowired private TaskSerieItemRepository taskSerieItemRepository;
@Autowired private ScheduleRepository scheduleRepository;
public ServiceExitCode createTaskSeries(TaskRepeatWeekInfo taskRepeatInfo) { public ServiceExitCode createTaskSeries(TaskRepeatWeekInfo taskRepeatInfo) {
List<Task> createdTasks = new ArrayList<>(); List<Task> createdTasks = new ArrayList<>();
TaskSerie taskSerie = new TaskSerie(); TaskSerie taskSerie = new TaskSerie();
List<AbstractSchedule> abstractSchedules = new ArrayList<>();
for(TaskRepeatWeekDayInfo taskRepeatDayInfo : taskRepeatInfo.getWeekDayInfos()) { for(TaskRepeatWeekDayInfo taskRepeatDayInfo : taskRepeatInfo.getWeekDayInfos()) {
Optional<Task> task = taskRepository.findById(taskRepeatDayInfo.getTaskID()); Optional<Task> task = taskRepository.findById(taskRepeatDayInfo.getTaskID());
if(task.isEmpty()) return ServiceExitCode.MISSING_ENTITY; if(task.isEmpty()) return ServiceExitCode.MISSING_ENTITY;
@ -48,6 +50,7 @@ public class TaskSeriesService {
clonedTask.setTaskSerieItem(taskSerieItem); clonedTask.setTaskSerieItem(taskSerieItem);
createdTasks.add(clonedTask); createdTasks.add(clonedTask);
abstractSchedules.addAll(cloneSchedules(task.get(), clonedTask));
currentTaskDate = currentTaskDate.plusDays(taskRepeatDayInfo.getOffset()); currentTaskDate = currentTaskDate.plusDays(taskRepeatDayInfo.getOffset());
} }
} }
@ -75,6 +78,7 @@ public class TaskSeriesService {
taskSeriesRepository.save(taskSerie); taskSeriesRepository.save(taskSerie);
taskRepository.saveAll(createdTasks); taskRepository.saveAll(createdTasks);
taskSerieItemRepository.saveAll(taskSerie.getTasks()); taskSerieItemRepository.saveAll(taskSerie.getTasks());
scheduleRepository.saveAll(abstractSchedules);
return ServiceExitCode.OK; return ServiceExitCode.OK;
} }
@ -85,6 +89,7 @@ public class TaskSeriesService {
} }
List<Task> taskList = new ArrayList<>(); List<Task> taskList = new ArrayList<>();
List<AbstractSchedule> abstractSchedules = new ArrayList<>();
TaskSerie taskSerie = new TaskSerie(); TaskSerie taskSerie = new TaskSerie();
TaskSerieItem rootItem = taskSerie.addTask(rootTask); TaskSerieItem rootItem = taskSerie.addTask(rootTask);
rootTask.setTaskSerieItem(rootItem); rootTask.setTaskSerieItem(rootItem);
@ -101,16 +106,32 @@ public class TaskSeriesService {
TaskSerieItem taskSerieItem = taskSerie.addTask(task); TaskSerieItem taskSerieItem = taskSerie.addTask(task);
taskList.add(task); taskList.add(task);
task.setTaskSerieItem(taskSerieItem); task.setTaskSerieItem(taskSerieItem);
abstractSchedules.addAll(cloneSchedules(rootTask, task));
currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset()); currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset());
} }
taskSeriesRepository.save(taskSerie); taskSeriesRepository.save(taskSerie);
taskRepository.saveAll(taskList); taskRepository.saveAll(taskList);
taskSerieItemRepository.saveAll(taskSerie.getTasks()); taskSerieItemRepository.saveAll(taskSerie.getTasks());
scheduleRepository.saveAll(abstractSchedules);
return ServiceExitCode.OK; return ServiceExitCode.OK;
} }
public List<AbstractSchedule> cloneSchedules(Task previousTask, Task nextTask) {
long numberDays = ChronoUnit.DAYS.between(previousTask.getStartDate(), nextTask.getStartDate());
List<AbstractSchedule> clonedSchedules = new ArrayList<>();
for(AbstractSchedule abstractSchedule : previousTask.getBasicTaskSchedules()) {
AbstractSchedule clonedSchedule = abstractSchedule.cloneSchedule();
clonedSchedule.shiftSchedule(numberDays);
clonedSchedules.add(clonedSchedule);
}
return clonedSchedules;
}
public void deleteTaskSeriesItem(Task task) { public void deleteTaskSeriesItem(Task task) {
TaskSerieItem item = task.getTaskSerieItem(); TaskSerieItem item = task.getTaskSerieItem();
TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie(); TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie();