Merge branch 'feature_taskList_m2' into feature_notification_m3

This commit is contained in:
schrom01
2022-11-25 11:14:47 +01:00
3 changed files with 31 additions and 15 deletions
@@ -9,6 +9,7 @@ import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class GardenSchedule {
@@ -136,10 +137,22 @@ public class GardenSchedule {
* @throws IOException If the database cannot be accessed
*/
public List<List<Task>> getTasksUpcomingWeek() throws IOException {
final int listLength = 7;
List<Task> weekTasks = taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(listLength - 1));
List<List<Task>> dayTaskList = new ArrayList<>();
for(int i = 0; i < 7; i++) {
for(int i = 0; i < listLength; i++) {
LocalDate date = LocalDate.now().plusDays(i);
dayTaskList.add(taskList.getTaskList(date, date));
dayTaskList.add(new ArrayList<>());
final int finalI = i;
weekTasks.forEach(task -> {
LocalDate checkDate = task.getNextExecution();
do {
if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) {
dayTaskList.get(finalI).add(task);
}
checkDate = checkDate.plusDays(task.getInterval().orElse(0));
} while (task.getInterval().isPresent() && checkDate.isBefore(LocalDate.now().plusDays(listLength)));
});
}
return dayTaskList;
}
@@ -150,11 +163,8 @@ public class GardenSchedule {
* @throws IOException If the database cannot be accessed
*/
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
List<List<Task>> dayTaskList = new ArrayList<>();
for(int i = 0; i < 7; i++) {
LocalDate date = LocalDate.now().plusDays(i);
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
}
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
return dayTaskList;
}
@@ -27,6 +27,7 @@ public class Task {
name= "";
description= "";
startDate = LocalDate.now();
endDate = startDate;
nextExecution = startDate;
}
@@ -34,6 +35,7 @@ public class Task {
this.name = name;
this.description = description;
this.startDate = startDate;
this.endDate = startDate;
nextExecution = startDate;
this.cropId = cropId;
}
@@ -63,7 +65,7 @@ public class Task {
}
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
}
public void done(){