issue-106 #107

Merged
sebastian merged 18 commits from issue-106 into master 2024-03-17 09:17:11 +01:00
4 changed files with 23 additions and 93 deletions
Showing only changes of commit 9b995baa75 - Show all commits

View File

@ -7,7 +7,6 @@ import java.time.LocalDate;
public class TaskRepeatDayInfo {
private int offset;
private DeadlineStrategy deadlineStrategy;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
private LocalDate endingDate;
@ -20,14 +19,6 @@ public class TaskRepeatDayInfo {
this.offset = offset;
}
public DeadlineStrategy getDeadlineStrategy() {
return deadlineStrategy;
}
public void setDeadlineStrategy(DeadlineStrategy deadlineStrategy) {
this.deadlineStrategy = deadlineStrategy;
}
public LocalDate getEndingDate() {
return endingDate;
}

View File

@ -15,7 +15,6 @@ public class TaskRepeatWeekInfo {
@Size(min = 1, max = 7)
private List<TaskRepeatWeekDayInfo> weekDayInfos;
private DeadlineStrategy deadlineStrategy;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
private LocalDate endDate;
@ -26,15 +25,6 @@ public class TaskRepeatWeekInfo {
public void setWeekDayInfos(List<TaskRepeatWeekDayInfo> weekDayInfos) {
this.weekDayInfos = weekDayInfos;
}
public DeadlineStrategy getDeadlineStrategy() {
return deadlineStrategy;
}
public void setDeadlineStrategy(DeadlineStrategy deadlineStrategy) {
this.deadlineStrategy = deadlineStrategy;
}
public LocalDate getEndDate() {
return endDate;
}

View File

@ -88,28 +88,19 @@ public class Task {
return new Tripel<>(clonedTask, clonedTasks, clonedSchedules);
}
public void shiftTask(long startingDayDifference, long endingDayDifference) {
this.setStartDate(this.getStartDate().plusDays(startingDayDifference));
this.setDeadline(this.getDeadline().plusDays(endingDayDifference));
public void shiftTask(long offset) {
this.setStartDate(this.getStartDate().plusDays(offset));
this.setDeadline(this.getDeadline().plusDays(offset));
for(AbstractSchedule abstractSchedule : this.basicTaskSchedules) {
abstractSchedule.shiftSchedule(startingDayDifference);
abstractSchedule.shiftSchedule(offset);
}
for(Task subtask: this.subtasks) {
subtask.shiftTask(startingDayDifference, endingDayDifference);
subtask.shiftTask(offset);
}
}
public void shiftTask(long startingDayDifference) {
this.setStartDate(this.getStartDate().plusDays(startingDayDifference));
this.setDeadline(this.getStartDate());
for(Task subtask: this.subtasks) {
subtask.shiftTask(startingDayDifference);
}
}
public long getTaskID() {
return taskID;
@ -299,11 +290,4 @@ public class Task {
public void increaseWorkTime(long minutes) {
this.workTime += (int) minutes;
}
public void shiftStartingTask(long dayDifference) {
this.setStartDate(this.getStartDate().plusDays(dayDifference));
for (Task subtask : this.subtasks) {
subtask.shiftTask(dayDifference);
}
}
}

View File

@ -29,13 +29,13 @@ public class TaskSeriesService {
public ServiceExitCode createTaskSeries(TaskRepeatWeekInfo taskRepeatInfo) {
HashMap<Task, Tupel<Integer, Integer>> offsetMap = calcWeeklyOffsetMap(taskRepeatInfo);
HashMap<Task, Integer> offsetMap = calcWeeklyOffsetMap(taskRepeatInfo);
TaskSerie taskSerie = new TaskSerie();
List<Task> clonedTasks = new ArrayList<>();
List<AbstractSchedule> clonedSchedules = new ArrayList<>();
int weekDayIndex = 0;
for(Map.Entry<Task, Tupel<Integer, Integer>> repeatingTaskInfo: offsetMap.entrySet()) {
for(Map.Entry<Task, Integer> repeatingTaskInfo: offsetMap.entrySet()) {
Task rootTask = repeatingTaskInfo.getKey();
TaskSerieItem rootItem = new TaskSerieItem(rootTask, weekDayIndex);
taskSerie.addItem(rootItem);
@ -58,11 +58,11 @@ public class TaskSeriesService {
return ServiceExitCode.OK;
}
private Tupel<Collection<Task>, Collection<AbstractSchedule>> repeatTask(Task rootTask, LocalDate endingDate, HashMap<Task, Tupel<Integer, Integer>> offsetMap,TaskSerie taskSerie, int itemIndex) {
private Tupel<Collection<Task>, Collection<AbstractSchedule>> repeatTask(Task rootTask, LocalDate endingDate, HashMap<Task, Integer> offsetMap,TaskSerie taskSerie, int itemIndex) {
List<Task> clonedTasks = new ArrayList<>();
List<AbstractSchedule> clonedSchedules = new ArrayList<>();
LocalDate currentDate = rootTask.getStartDate().plusDays(offsetMap.get(rootTask).getValue00());
LocalDate currentDate = rootTask.getStartDate().plusDays(offsetMap.get(rootTask));
while(currentDate.isBefore(endingDate)) {
var cloneResult = rootTask.cloneTask();
Task clonedRootTask = cloneResult.getValue00();
@ -74,87 +74,52 @@ public class TaskSeriesService {
taskSerie.addItem(item);
}
Tupel<Integer, Integer> offsetEntry = offsetMap.get(rootTask);
clonedRootTask.shiftTask(offsetEntry.getValue00(), offsetEntry.getValue01());
clonedRootTask.shiftTask(offsetMap.get(rootTask));
currentDate = currentDate.plusDays(offsetEntry.getValue00());
currentDate = currentDate.plusDays(offsetMap.get(rootTask));
itemIndex += offsetMap.size();
}
return new Tupel<>(clonedTasks, clonedSchedules);
}
private HashMap<Task, Tupel<Integer, Integer>> calcWeeklyOffsetMap(TaskRepeatWeekInfo weekInfo) throws NoSuchElementException {
HashMap<Task, Tupel<Integer, Integer>> offsetMap = new HashMap<>();
private HashMap<Task, Integer> calcWeeklyOffsetMap(TaskRepeatWeekInfo weekInfo) throws NoSuchElementException {
HashMap<Task,Integer> offsetMap = new HashMap<>();
weekInfo.getWeekDayInfos().sort(Comparator.comparing(TaskRepeatWeekDayInfo::getDayOfWeek));
for(int i=0; i<weekInfo.getWeekDayInfos().size(); i++) {
Optional<Task> requestedTask = taskRepository.findById(weekInfo.getWeekDayInfos().get(i).getTaskID());
if(requestedTask.isEmpty()) {
throw new NoSuchElementException();
} else {
if(weekInfo.getDeadlineStrategy() == DeadlineStrategy.DEADLINE_EQUAL_START) {
int offset = weekInfo.getWeekDayInfos().get(i).getOffset()-1;
offsetMap.put(requestedTask.get(), new Tupel<>(offset, offset));
} else {
int startingOffset = weekInfo.getWeekDayInfos().get(i).getOffset() -1;
int endingOffset = getEndingOffset(weekInfo, i, startingOffset);
offsetMap.put(requestedTask.get(), new Tupel<>(startingOffset, endingOffset));
}
int offset = weekInfo.getWeekDayInfos().get(i).getOffset()-1;
offsetMap.put(requestedTask.get(), offset);
}
}
return offsetMap;
}
private static int getEndingOffset(TaskRepeatWeekInfo weekInfo, int i, int startingOffset) {
DayOfWeek nextWeekday;
if(i == weekInfo.getWeekDayInfos().size()-1) {
nextWeekday = weekInfo.getWeekDayInfos().get(0).getDayOfWeek();
} else {
nextWeekday = weekInfo.getWeekDayInfos().get(i +1).getDayOfWeek();
}
DayOfWeek currentWeekDay = weekInfo.getWeekDayInfos().get(i).getDayOfWeek();
int endingOffset = startingOffset + Math.abs(nextWeekday.getValue() - currentWeekDay.getValue());
return endingOffset;
}
public ServiceExitCode createTaskSeries(Task rootTask, TaskRepeatDayInfo taskRepeatInfo) {
if(taskRepeatInfo.getDeadlineStrategy() == DeadlineStrategy.FIX_DEADLINE) {
return ServiceExitCode.INVALID_PARAMETER;
}
List<Task> taskList = new ArrayList<>();
List<AbstractSchedule> abstractSchedules = new ArrayList<>();
TaskSerie taskSerie = new TaskSerie();
TaskSerieItem rootItem = taskSerie.addTask(rootTask);
rootTask.setTaskSerieItem(rootItem);
HashMap<Task, Integer> offsetMap = new HashMap<>();
offsetMap.put(rootTask, taskRepeatInfo.getOffset());
var repeatingResult = repeatTask(rootTask, taskRepeatInfo.getEndingDate(), offsetMap, taskSerie, 0);
List<Task> clonedTasks = new ArrayList<>(repeatingResult.getValue00());
List<AbstractSchedule> clonedSchedules = new ArrayList<>(repeatingResult.getValue01());
taskSeriesRepository.save(taskSerie);
taskRepository.saveAll(taskList);
taskRepository.saveAll(clonedTasks);
taskSerieItemRepository.saveAll(taskSerie.getTasks());
scheduleRepository.saveAll(abstractSchedules);
scheduleRepository.saveAll(clonedSchedules);
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) {
TaskSerieItem item = task.getTaskSerieItem();
TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie();