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();
|
AppLoader appLoader = new AppLoader();
|
||||||
|
|
||||||
backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class));
|
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);
|
appLoader.loadSceneToStage("MainFXML.fxml", stage);
|
||||||
|
|
||||||
stage.setTitle("Gartenverwaltung");
|
stage.setTitle("Gartenverwaltung");
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|
||||||
|
backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 60000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class JsonTaskList implements TaskList {
|
||||||
* @see TaskList#getTaskList(LocalDate, LocalDate)
|
* @see TaskList#getTaskList(LocalDate, LocalDate)
|
||||||
*/
|
*/
|
||||||
@Override
|
@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()) {
|
if(taskMap.isEmpty()) {
|
||||||
loadTaskListFromFile();
|
loadTaskListFromFile();
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public class JsonTaskList implements TaskList {
|
||||||
* @return List of Tasks for given Crop
|
* @return List of Tasks for given Crop
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Task> getTaskForCrop(long cropId) throws IOException {
|
public synchronized List<Task> getTaskForCrop(long cropId) throws IOException {
|
||||||
if(taskMap.isEmpty()) {
|
if(taskMap.isEmpty()) {
|
||||||
loadTaskListFromFile();
|
loadTaskListFromFile();
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public class JsonTaskList implements TaskList {
|
||||||
* @see TaskList#saveTask(Task)
|
* @see TaskList#saveTask(Task)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void saveTask(Task task) throws IOException {
|
public synchronized void saveTask(Task task) throws IOException {
|
||||||
if(taskMap.isEmpty()) {
|
if(taskMap.isEmpty()) {
|
||||||
loadTaskListFromFile();
|
loadTaskListFromFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung.models;
|
||||||
import ch.zhaw.gartenverwaltung.Settings;
|
import ch.zhaw.gartenverwaltung.Settings;
|
||||||
import ch.zhaw.gartenverwaltung.io.*;
|
import ch.zhaw.gartenverwaltung.io.*;
|
||||||
import ch.zhaw.gartenverwaltung.types.*;
|
import ch.zhaw.gartenverwaltung.types.*;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.ListProperty;
|
import javafx.beans.property.ListProperty;
|
||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleListProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
@ -32,7 +33,13 @@ public class GardenSchedule {
|
||||||
this.taskList = taskList;
|
this.taskList = taskList;
|
||||||
this.plantList = plantList;
|
this.plantList = plantList;
|
||||||
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
try {
|
||||||
getTasksUpcomingWeek();
|
getTasksUpcomingWeek();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
setTaskListObserver(taskListObserver);
|
setTaskListObserver(taskListObserver);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class Task {
|
||||||
* @return Whether the Task is within the given range
|
* @return Whether the Task is within the given range
|
||||||
*/
|
*/
|
||||||
public boolean isInTimePeriod(LocalDate searchStartDate, LocalDate searchEndDate) {
|
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
|
@Test
|
||||||
void testSubscription() {
|
void testSubscription() throws IOException {
|
||||||
TaskList.TaskListObserver mockObs = Mockito.mock(TaskList.TaskListObserver.class);
|
TaskList.TaskListObserver mockObs = Mockito.mock(TaskList.TaskListObserver.class);
|
||||||
testDatabase.subscribe(mockObs);
|
testDatabase.subscribe(mockObs);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue