diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Main.java b/src/main/java/ch/zhaw/gartenverwaltung/Main.java index d31860d..f757926 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Main.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Main.java @@ -22,13 +22,14 @@ public class Main extends Application { AppLoader appLoader = new AppLoader(); backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class)); - // TODO reduce period - backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 1000); appLoader.loadSceneToStage("MainFXML.fxml", stage); stage.setTitle("Gartenverwaltung"); stage.show(); + + backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 60000); + } @Override diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java index 4092330..869783c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java @@ -67,7 +67,7 @@ public class JsonTaskList implements TaskList { * @see TaskList#getTaskList(LocalDate, LocalDate) */ @Override - public List getTaskList(LocalDate start, LocalDate end) throws IOException{ + public synchronized List getTaskList(LocalDate start, LocalDate end) throws IOException{ if(taskMap.isEmpty()) { loadTaskListFromFile(); } @@ -80,7 +80,7 @@ public class JsonTaskList implements TaskList { * @return List of Tasks for given Crop */ @Override - public List getTaskForCrop(long cropId) throws IOException { + public synchronized List getTaskForCrop(long cropId) throws IOException { if(taskMap.isEmpty()) { loadTaskListFromFile(); } @@ -111,7 +111,7 @@ public class JsonTaskList implements TaskList { * @see TaskList#saveTask(Task) */ @Override - public void saveTask(Task task) throws IOException { + public synchronized void saveTask(Task task) throws IOException { if(taskMap.isEmpty()) { loadTaskListFromFile(); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index 932d6b5..2e3eb3d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung.models; import ch.zhaw.gartenverwaltung.Settings; import ch.zhaw.gartenverwaltung.io.*; import ch.zhaw.gartenverwaltung.types.*; +import javafx.application.Platform; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; @@ -32,7 +33,13 @@ public class GardenSchedule { this.taskList = taskList; this.plantList = plantList; TaskList.TaskListObserver taskListObserver = newTaskList -> { - getTasksUpcomingWeek(); + Platform.runLater(() -> { + try { + getTasksUpcomingWeek(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); }; setTaskListObserver(taskListObserver); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index 017b18f..4136d1d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -104,7 +104,7 @@ public class Task { * @return Whether the Task is within the given range */ public boolean isInTimePeriod(LocalDate searchStartDate, LocalDate searchEndDate) { - return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate); + return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate) || (nextExecution != null && nextExecution.isBefore(searchEndDate) && nextExecution.isAfter(searchStartDate)); } /** diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java index 00e21e3..2a515d7 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java @@ -130,7 +130,7 @@ public class JsonTaskListTest { } @Test - void testSubscription() { + void testSubscription() throws IOException { TaskList.TaskListObserver mockObs = Mockito.mock(TaskList.TaskListObserver.class); testDatabase.subscribe(mockObs); try {