fix update scheduler
This commit is contained in:
parent
45035e565c
commit
4d2057d0df
|
@ -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
|
||||
|
|
|
@ -67,7 +67,7 @@ public class JsonTaskList implements TaskList {
|
|||
* @see TaskList#getTaskList(LocalDate, LocalDate)
|
||||
*/
|
||||
@Override
|
||||
public List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException{
|
||||
public synchronized List<Task> 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<Task> getTaskForCrop(long cropId) throws IOException {
|
||||
public synchronized List<Task> 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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue