Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bda390708 | ||
|
|
b3c7dd67e8 | ||
|
|
59c5d4be5a | ||
|
|
035f5d7fcd | ||
|
|
4d2057d0df | ||
|
|
ccaff13df3 | ||
|
|
c9baf4dfb1 | ||
|
|
45035e565c | ||
|
|
00be979863 | ||
|
|
86386d8a91 | ||
|
|
c7b23335b5 | ||
|
|
7c015d78f4 | ||
|
|
d119fd1331 |
@@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung;
|
|||||||
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||||
|
import ch.zhaw.gartenverwaltung.io.TaskList;
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||||
@@ -129,7 +130,14 @@ public class CropDetailController {
|
|||||||
}
|
}
|
||||||
area_label.setText(String.valueOf(crop.getArea()));
|
area_label.setText(String.valueOf(crop.getArea()));
|
||||||
|
|
||||||
setTaskListProperty(crop);
|
initializeTaskListProperty(crop);
|
||||||
|
|
||||||
|
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
||||||
|
taskListProperty.clear();
|
||||||
|
taskListProperty.addAll(gardenSchedule.getTaskListForCrop(crop.getCropId().get()));
|
||||||
|
};
|
||||||
|
gardenSchedule.setTaskListObserver(taskListObserver);
|
||||||
|
|
||||||
taskList_listView.itemsProperty().bind(taskListProperty);
|
taskList_listView.itemsProperty().bind(taskListProperty);
|
||||||
|
|
||||||
pestListProperty.addAll(plant.pests());
|
pestListProperty.addAll(plant.pests());
|
||||||
@@ -186,10 +194,10 @@ public class CropDetailController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update task list
|
* initialize task list
|
||||||
* @param crop {@link Crop} that is selected
|
* @param crop {@link Crop} that is selected
|
||||||
*/
|
*/
|
||||||
private void setTaskListProperty(Crop crop) {
|
private void initializeTaskListProperty(Crop crop) {
|
||||||
crop.getCropId().ifPresent(id -> {
|
crop.getCropId().ifPresent(id -> {
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
try {
|
try {
|
||||||
@@ -333,13 +341,15 @@ public class CropDetailController {
|
|||||||
if (newTask) {
|
if (newTask) {
|
||||||
try {
|
try {
|
||||||
gardenSchedule.addTask(task);
|
gardenSchedule.addTask(task);
|
||||||
setTaskListProperty(this.crop);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//ToDo method to edit task
|
try {
|
||||||
setTaskListProperty(this.crop);
|
gardenSchedule.addTask(givenTask.updateTask(task));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -404,7 +414,7 @@ public class CropDetailController {
|
|||||||
if (buttonType == ButtonType.OK) {
|
if (buttonType == ButtonType.OK) {
|
||||||
try {
|
try {
|
||||||
gardenSchedule.removeTask(task);
|
gardenSchedule.removeTask(task);
|
||||||
setTaskListProperty(this.crop);
|
//setTaskListProperty(this.crop);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: Show error alert
|
// TODO: Show error alert
|
||||||
LOG.log(Level.SEVERE, "Could not remove crop.", e);
|
LOG.log(Level.SEVERE, "Could not remove crop.", e);
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class MyScheduleController {
|
public class MyScheduleController {
|
||||||
private static final Logger LOG = Logger.getLogger(MyScheduleController.class.getName());
|
private static final Logger LOG = Logger.getLogger(MyScheduleController.class.getName());
|
||||||
private final ListProperty<List<Task>> taskListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
|
||||||
|
|
||||||
private Crop selectedCrop = null;
|
private Crop selectedCrop = null;
|
||||||
|
|
||||||
@@ -58,14 +57,10 @@ public class MyScheduleController {
|
|||||||
setCellFactoryCropListView();
|
setCellFactoryCropListView();
|
||||||
setCellFactoryTaskListView();
|
setCellFactoryTaskListView();
|
||||||
scheduledPlants_listview.itemsProperty().bind(garden.getPlantedCrops());
|
scheduledPlants_listview.itemsProperty().bind(garden.getPlantedCrops());
|
||||||
|
ListProperty<List<Task>> taskListProperty = gardenSchedule.getWeeklyTaskListProperty();
|
||||||
week_listView.itemsProperty().bind(taskListProperty);
|
week_listView.itemsProperty().bind(taskListProperty);
|
||||||
lookForSelectedListEntries();
|
lookForSelectedListEntries();
|
||||||
information_label.setText("");
|
information_label.setText("");
|
||||||
try {
|
|
||||||
loadTaskList();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,8 +112,8 @@ public class MyScheduleController {
|
|||||||
super.updateItem(taskList, empty);
|
super.updateItem(taskList, empty);
|
||||||
|
|
||||||
if (empty || taskList == null) {
|
if (empty || taskList == null) {
|
||||||
setGraphic(null);
|
|
||||||
setText(null);
|
setText(null);
|
||||||
|
setGraphic(null);
|
||||||
} else {
|
} else {
|
||||||
setText("");
|
setText("");
|
||||||
setGraphic(weekTaskVBox(taskList, this.getIndex()));
|
setGraphic(weekTaskVBox(taskList, this.getIndex()));
|
||||||
@@ -134,12 +129,12 @@ public class MyScheduleController {
|
|||||||
private void loadTaskList() throws IOException {
|
private void loadTaskList() throws IOException {
|
||||||
List<List<Task>> taskLists;
|
List<List<Task>> taskLists;
|
||||||
if (selectedCrop != null) {
|
if (selectedCrop != null) {
|
||||||
taskLists = gardenSchedule.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
|
gardenSchedule.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
|
||||||
} else {
|
} else {
|
||||||
taskLists = gardenSchedule.getTasksUpcomingWeek();
|
gardenSchedule.getTasksUpcomingWeek();
|
||||||
}
|
}
|
||||||
taskListProperty.clear();
|
//taskListProperty.clear();
|
||||||
taskListProperty.addAll(taskLists);
|
//taskListProperty.addAll(taskLists);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
*/
|
*/
|
||||||
public Task returnResult(Crop crop) {
|
public Task returnResult(Crop crop) {
|
||||||
int interval = 0;
|
int interval = 0;
|
||||||
if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) {
|
if (interval_field.getText() != null && !(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) {
|
||||||
interval = Integer.parseInt(interval_field.getText());
|
interval = Integer.parseInt(interval_field.getText());
|
||||||
}
|
}
|
||||||
Task task = new Task(taskName_field.getText(), description_area.getText(),
|
Task task = new Task(taskName_field.getText(), description_area.getText(),
|
||||||
@@ -159,7 +159,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
*/
|
*/
|
||||||
public void initSaveButton(Button button) {
|
public void initSaveButton(Button button) {
|
||||||
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
|
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (!newValue.matches("\\d*")) {
|
if (newValue != null && !newValue.matches("\\d*")) {
|
||||||
interval_field.setText(newValue.replaceAll("[^\\d]", ""));
|
interval_field.setText(newValue.replaceAll("[^\\d]", ""));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ public class BackgroundTasks extends TimerTask {
|
|||||||
|
|
||||||
private void movePastTasks() throws IOException {
|
private void movePastTasks() throws IOException {
|
||||||
List<Task> taskList = this.taskList.getTaskList(LocalDate.MIN, LocalDate.now().minusDays(1));
|
List<Task> taskList = this.taskList.getTaskList(LocalDate.MIN, LocalDate.now().minusDays(1));
|
||||||
taskList.forEach(task -> {
|
for (Task task : taskList) {
|
||||||
if (!task.isDone()) {
|
if (!task.isDone()) {
|
||||||
task.setNextExecution(LocalDate.now());
|
task.setNextExecution(LocalDate.now());
|
||||||
|
this.taskList.saveTask(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
|
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
|
||||||
|
|||||||
+58
-8
@@ -9,8 +9,12 @@ import ch.zhaw.gartenverwaltung.types.*;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WeatherGardenTaskPlanner creates Tasks based on weather events and the rain amount from the last days
|
* The WeatherGardenTaskPlanner creates Tasks based on weather events and the rain amount from the last days
|
||||||
*
|
*
|
||||||
@@ -20,7 +24,7 @@ public class WeatherGradenTaskPlanner {
|
|||||||
private final PlantList plantList;
|
private final PlantList plantList;
|
||||||
private final CropList cropList;
|
private final CropList cropList;
|
||||||
WeatherService weatherService;
|
WeatherService weatherService;
|
||||||
private final LocalDate dateSevereWeather = LocalDate.of(2022,12,15);
|
private final LocalDate dateSevereWeather = LocalDate.now();
|
||||||
|
|
||||||
public WeatherGradenTaskPlanner(TaskList taskList, PlantList plantList, CropList cropList) {
|
public WeatherGradenTaskPlanner(TaskList taskList, PlantList plantList, CropList cropList) {
|
||||||
this.taskList = taskList;
|
this.taskList = taskList;
|
||||||
@@ -62,11 +66,27 @@ public class WeatherGradenTaskPlanner {
|
|||||||
*/
|
*/
|
||||||
private void createPreHailTask() throws IOException {
|
private void createPreHailTask() throws IOException {
|
||||||
|
|
||||||
|
List<Crop> actualCrops = cropList.getCrops();
|
||||||
|
|
||||||
|
for (Crop crop : actualCrops) {
|
||||||
Task preHailTask = new Task("Hail",
|
Task preHailTask = new Task("Hail",
|
||||||
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
|
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
|
||||||
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
|
dateSevereWeather,dateSevereWeather.plusDays(1L),crop.getCropId().orElse(-1L));
|
||||||
taskList.saveTask(preHailTask);
|
|
||||||
|
|
||||||
|
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||||
|
List<Task> hailTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Hail")).toList();
|
||||||
|
|
||||||
|
List<Task> hailTaskListAtDate = new ArrayList<>();
|
||||||
|
for (Task task : hailTasklist) {
|
||||||
|
if (task.getStartDate() == (preHailTask.getStartDate())) {
|
||||||
|
hailTaskListAtDate.add(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hailTaskListAtDate.isEmpty() && hailTasklist.isEmpty()){
|
||||||
|
taskList.saveTask(preHailTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,23 +94,56 @@ public class WeatherGradenTaskPlanner {
|
|||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
private void createPreFrostTask() throws IOException {
|
private void createPreFrostTask() throws IOException {
|
||||||
|
List<Crop> actualCrops = cropList.getCrops();
|
||||||
|
for (Crop crop : actualCrops) {
|
||||||
|
|
||||||
Task preFrostTask = new Task("Frost",
|
Task preFrostTask = new Task("Frost",
|
||||||
"The temperatur falls below zero degrees, cover especially the root with wool",
|
"The temperatur falls below zero degrees, cover especially the root with wool",
|
||||||
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
|
dateSevereWeather,dateSevereWeather.plusDays(1L),crop.getCropId().orElse(-1L));
|
||||||
|
|
||||||
|
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||||
|
List<Task> frostTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Frost")).toList();
|
||||||
|
|
||||||
|
List<Task> frostTaskListAtDate = new ArrayList<>();
|
||||||
|
for (Task task : frostTasklist) {
|
||||||
|
if (task.getStartDate() == preFrostTask.getStartDate()) {
|
||||||
|
frostTaskListAtDate.add(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(frostTaskListAtDate.isEmpty() && frostTasklist.isEmpty()){
|
||||||
taskList.saveTask(preFrostTask);
|
taskList.saveTask(preFrostTask);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to create a PreSnowTask
|
* Method to create a PreSnowTask
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
private void createPreSnowTask() throws IOException {
|
private void createPreSnowTask() throws IOException {
|
||||||
|
List<Crop> actualCrops = cropList.getCrops();
|
||||||
|
for (Crop crop : actualCrops) {
|
||||||
|
|
||||||
Task preSnowTask = new Task("Snow",
|
Task preSnowTask = new Task("Snow",
|
||||||
"The weather brings little snowfall. Cover your crops",
|
"The weather brings little snowfall. Cover your crops",
|
||||||
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
|
dateSevereWeather, dateSevereWeather.plusDays(1L), crop.getCropId().orElse(-1L));
|
||||||
|
|
||||||
|
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||||
|
List<Task> snowTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Snow")).toList();
|
||||||
|
|
||||||
|
List<Task> snowTaskListAtDate = new ArrayList<>();
|
||||||
|
for (Task task : snowTasklist) {
|
||||||
|
if (task.getStartDate() == preSnowTask.getStartDate()) {
|
||||||
|
snowTaskListAtDate.add(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(snowTaskListAtDate .isEmpty() && snowTasklist.isEmpty()){
|
||||||
taskList.saveTask(preSnowTask);
|
taskList.saveTask(preSnowTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to adjust the water plant tasks
|
* Method to adjust the water plant tasks
|
||||||
* @param rainAmount Amount of rain from the last 7 days
|
* @param rainAmount Amount of rain from the last 7 days
|
||||||
@@ -113,9 +166,6 @@ public class WeatherGradenTaskPlanner {
|
|||||||
/**
|
/**
|
||||||
* Method to set next execution date of the water plant tasks
|
* Method to set next execution date of the water plant tasks
|
||||||
* @param cropTaskList List with tasks from crops
|
* @param cropTaskList List with tasks from crops
|
||||||
* @throws IOException If the database cannot be accessed
|
|
||||||
* @throws HardinessZoneNotSetException If the hardiness zone is not available
|
|
||||||
* @throws PlantNotFoundException if the plant is not available for the watering task
|
|
||||||
*/
|
*/
|
||||||
private void adjustNextExecutionOfWateringTasks(List<Task> cropTaskList){
|
private void adjustNextExecutionOfWateringTasks(List<Task> cropTaskList){
|
||||||
for(Task task : cropTaskList){
|
for(Task task : cropTaskList){
|
||||||
|
|||||||
@@ -67,11 +67,11 @@ 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();
|
||||||
}
|
}
|
||||||
return taskMap.values().stream().filter(task -> task.isInTimePeriode(start, end)).toList();
|
return taskMap.values().stream().filter(task -> task.isInTimePeriod(start, end)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ public class JsonTaskList implements TaskList {
|
|||||||
/**
|
/**
|
||||||
* Calls the change handler method on all registered observers.
|
* Calls the change handler method on all registered observers.
|
||||||
*/
|
*/
|
||||||
private void notifySubscribers() {
|
private void notifySubscribers() throws IOException {
|
||||||
for (TaskListObserver subscriber : subscribers) {
|
for (TaskListObserver subscriber : subscribers) {
|
||||||
subscriber.onChange(taskMap.values().stream().toList());
|
subscriber.onChange(taskMap.values().stream().toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,6 @@ public interface TaskList {
|
|||||||
* Method which will be called when changes occur.
|
* Method which will be called when changes occur.
|
||||||
* @param newTaskList The new values
|
* @param newTaskList The new values
|
||||||
*/
|
*/
|
||||||
void onChange(List<Task> newTaskList);
|
void onChange(List<Task> newTaskList) throws IOException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ 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.SimpleListProperty;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -20,13 +24,36 @@ public class GardenSchedule {
|
|||||||
*/
|
*/
|
||||||
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
||||||
static final Comparator<Task> sortByNextExecution = Comparator.comparing(Task::getNextExecution);
|
static final Comparator<Task> sortByNextExecution = Comparator.comparing(Task::getNextExecution);
|
||||||
|
private final ListProperty<List<Task>> weeklyTaskListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to create Database Objects.
|
* Constructor to create Database Objects.
|
||||||
*/
|
*/
|
||||||
public GardenSchedule(TaskList taskList, PlantList plantList) {
|
public GardenSchedule(TaskList taskList, PlantList plantList) throws IOException {
|
||||||
this.taskList = taskList;
|
this.taskList = taskList;
|
||||||
this.plantList = plantList;
|
this.plantList = plantList;
|
||||||
|
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
try {
|
||||||
|
getTasksUpcomingWeek();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
setTaskListObserver(taskListObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListProperty<List<Task>> getWeeklyTaskListProperty() {
|
||||||
|
return weeklyTaskListProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subscribe task list observer to get notifications
|
||||||
|
* @param observer the task list which will be ovserved
|
||||||
|
*/
|
||||||
|
public void setTaskListObserver(TaskList.TaskListObserver observer) {
|
||||||
|
taskList.subscribe(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,18 +190,20 @@ public class GardenSchedule {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
weeklyTaskListProperty.clear();
|
||||||
|
weeklyTaskListProperty.addAll(dayTaskList);
|
||||||
return dayTaskList;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get an List of 7 Tasklists for the next 7 days. (Filtered Index 0 is Tasklist for Today.
|
* Method to get an List of 7 Tasklists for the next 7 days. (Filtered Index 0 is Tasklist for Today.
|
||||||
* @return List with length 7 (List<List<Task>>)
|
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
public void getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
||||||
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
|
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
|
||||||
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
|
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
|
||||||
return dayTaskList;
|
weeklyTaskListProperty.clear();
|
||||||
|
weeklyTaskListProperty.addAll(dayTaskList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a crop, meaning a specific plant growing at a specific time.
|
||||||
|
*/
|
||||||
public class Crop {
|
public class Crop {
|
||||||
private Long cropId = null;
|
private Long cropId = null;
|
||||||
private final long plantId;
|
private final long plantId;
|
||||||
|
|||||||
@@ -7,7 +7,19 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|||||||
import java.time.MonthDay;
|
import java.time.MonthDay;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a growth phase of a plant.
|
||||||
|
* Plants go through several phases during their life (sowing, germinating, growing, ..., harvest).
|
||||||
|
* These phases are characterized by what kinds of tasks need to be executed by the gardener to stay alive.
|
||||||
|
* This class represents one such phase.
|
||||||
|
*
|
||||||
|
* @param startDate The earliest date on which this phase can start
|
||||||
|
* @param endDate The latest date on which this phase can start
|
||||||
|
* @param group Which group this phase belongs to (if the growth phase can occur multiple times a year, default: 0)
|
||||||
|
* @param type What {@link GrowthPhaseType} this represents
|
||||||
|
* @param zone The hardiness zone for which this growth phase is valid
|
||||||
|
* @param taskTemplates The (undated) tasks required to be performed by the gardener
|
||||||
|
*/
|
||||||
public record GrowthPhase(
|
public record GrowthPhase(
|
||||||
MonthDay startDate,
|
MonthDay startDate,
|
||||||
MonthDay endDate,
|
MonthDay endDate,
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumerates the different possible types of {@link GrowthPhase}.
|
||||||
|
* (Subject to later expansion)
|
||||||
|
*/
|
||||||
public enum GrowthPhaseType {
|
public enum GrowthPhaseType {
|
||||||
SOW, PLANT, REPLANT, HARVEST
|
SOW, PLANT, REPLANT, HARVEST
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a pest or pathogen which may afflict a plant.
|
||||||
|
*
|
||||||
|
* @param name The name of the pest
|
||||||
|
* @param description A description of the pest
|
||||||
|
* @param measures Measures that can be taken against the pest.
|
||||||
|
*/
|
||||||
public record Pest(String name, String description, String measures) {
|
public record Pest(String name, String description, String measures) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,20 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static java.time.temporal.ChronoUnit.DAYS;
|
import static java.time.temporal.ChronoUnit.DAYS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a plant
|
||||||
|
*
|
||||||
|
* @param id A unique identifier
|
||||||
|
* @param name The name of the plant
|
||||||
|
* @param description A description of the plant
|
||||||
|
* @param image An image representing the plant
|
||||||
|
* @param spacing The amount of space needed between individual plants of this type
|
||||||
|
* @param light The amount of light preferred by the plant (h/d)
|
||||||
|
* @param soil The type of soil required for the plant
|
||||||
|
* @param pests {@link Pest}s that may afflict the plant
|
||||||
|
* @param wateringCycle The {@link WateringCycle} required by the plant
|
||||||
|
* @param lifecycle A list of {@link GrowthPhase}s constituting the plants lifecycle
|
||||||
|
*/
|
||||||
public record Plant(
|
public record Plant(
|
||||||
long id,
|
long id,
|
||||||
String name,
|
String name,
|
||||||
@@ -30,9 +44,10 @@ public record Plant(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get all growthPhases of lifecycle group
|
* Get all {@link GrowthPhase}s of a lifecycle group
|
||||||
* @param group lifecycle group
|
*
|
||||||
* @return list of growthPhases
|
* @param group The lifecycle group
|
||||||
|
* @return A list of {@link GrowthPhase}s
|
||||||
*/
|
*/
|
||||||
public List<GrowthPhase> lifecycleForGroup(int group) {
|
public List<GrowthPhase> lifecycleForGroup(int group) {
|
||||||
return lifecycle.stream()
|
return lifecycle.stream()
|
||||||
@@ -40,6 +55,12 @@ public record Plant(
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a {@link LocalDate}, determines which lifecycle group contains it.
|
||||||
|
*
|
||||||
|
* @param date The date to look for
|
||||||
|
* @return Which lifecycle group the date is in
|
||||||
|
*/
|
||||||
public int getGrowphaseGroupForDate(LocalDate date) {
|
public int getGrowphaseGroupForDate(LocalDate date) {
|
||||||
for(GrowthPhase growthPhase : lifecycle){
|
for(GrowthPhase growthPhase : lifecycle){
|
||||||
MonthDay plantingDate = MonthDay.of(date.getMonth().getValue(), date.getDayOfMonth());
|
MonthDay plantingDate = MonthDay.of(date.getMonth().getValue(), date.getDayOfMonth());
|
||||||
@@ -51,16 +72,18 @@ public record Plant(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get sow date from given harvest day from lifecycle group
|
* Get sow date from given harvest date from lifecycle group
|
||||||
|
*
|
||||||
* @param harvestDate date of the harvest
|
* @param harvestDate date of the harvest
|
||||||
* @return LocaleDate of sow date
|
* @return {@link LocalDate} of sow date
|
||||||
*/
|
*/
|
||||||
public LocalDate sowDateFromHarvestDate(LocalDate harvestDate) {
|
public LocalDate sowDateFromHarvestDate(LocalDate harvestDate) {
|
||||||
return harvestDate.minusDays(timeToHarvest(lifecycleGroupFromHarvestDate(harvestDate)));
|
return harvestDate.minusDays(timeToHarvest(lifecycleGroupFromHarvestDate(harvestDate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculate the days between sow and harvest day for lifecycle group
|
* Calculate the number of days between sow and harvest date for lifecycle group
|
||||||
|
*
|
||||||
* @param group the lifecycle group
|
* @param group the lifecycle group
|
||||||
* @return Integer number of dates between sow and harvest day
|
* @return Integer number of dates between sow and harvest day
|
||||||
*/
|
*/
|
||||||
@@ -79,6 +102,12 @@ public record Plant(
|
|||||||
return (int) DAYS.between(sow.startDate().atYear(currentYear),harvest.startDate().atYear(currentYear));
|
return (int) DAYS.between(sow.startDate().atYear(currentYear),harvest.startDate().atYear(currentYear));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a harvest date, determines which lifecycle group it belongs to.
|
||||||
|
*
|
||||||
|
* @param harvestDate The harvest date
|
||||||
|
* @return Which lifecycle group the harvest date is in
|
||||||
|
*/
|
||||||
public int lifecycleGroupFromHarvestDate(LocalDate harvestDate) {
|
public int lifecycleGroupFromHarvestDate(LocalDate harvestDate) {
|
||||||
return lifecycle.stream()
|
return lifecycle.stream()
|
||||||
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.HARVEST) &&
|
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.HARVEST) &&
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package ch.zhaw.gartenverwaltung.types;
|
|||||||
|
|
||||||
import java.time.MonthDay;
|
import java.time.MonthDay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the 4 Seasons in terms of {@link java.time.LocalDate}s
|
||||||
|
* Also describes "All Seasons" as the full year.
|
||||||
|
*/
|
||||||
public enum Seasons {
|
public enum Seasons {
|
||||||
ALLSEASONS("--01-01", "--12-31", "All Seasons"),
|
ALLSEASONS("--01-01", "--12-31", "All Seasons"),
|
||||||
SPRING("--03-01", "--05-30", "Spring"),
|
SPRING("--03-01", "--05-30", "Spring"),
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a Task
|
* Represents a Task
|
||||||
* May be created using the builder pattern.
|
* May be created using the builder pattern.
|
||||||
*/
|
*/
|
||||||
public class Task {
|
public class Task {
|
||||||
@@ -18,10 +19,9 @@ public class Task {
|
|||||||
private LocalDate nextExecution;
|
private LocalDate nextExecution;
|
||||||
private LocalDate nextNotification;
|
private LocalDate nextNotification;
|
||||||
private long cropId;
|
private long cropId;
|
||||||
private boolean done;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* Default constructor
|
||||||
* (used by Json deserializer)
|
* (used by Json deserializer)
|
||||||
*/
|
*/
|
||||||
public Task(){
|
public Task(){
|
||||||
@@ -32,6 +32,14 @@ public class Task {
|
|||||||
nextExecution = startDate;
|
nextExecution = startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for a non-repeating task related to a {@link Crop}
|
||||||
|
*
|
||||||
|
* @param name The name of the task
|
||||||
|
* @param description A description of the task
|
||||||
|
* @param startDate The start date of the task
|
||||||
|
* @param cropId The id of the crop to which the task belongs
|
||||||
|
*/
|
||||||
public Task(String name, String description, LocalDate startDate, long cropId) {
|
public Task(String name, String description, LocalDate startDate, long cropId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -43,14 +51,31 @@ public class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for weather events
|
* Constructor for weather events
|
||||||
|
*
|
||||||
|
* @param name The name of the task
|
||||||
|
* @param description A description of the task
|
||||||
|
* @param startDate The start date of the task
|
||||||
|
* @param endDate The maximum date on which the task should be executed
|
||||||
*/
|
*/
|
||||||
public Task(String name, String description, LocalDate startDate, LocalDate endDate) {
|
public Task(String name, String description, LocalDate startDate, LocalDate endDate, long cropId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
|
nextExecution = startDate;
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
|
this.cropId = cropId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full constructor (without id)
|
||||||
|
*
|
||||||
|
* @param name The name of the task
|
||||||
|
* @param description A description of the task
|
||||||
|
* @param startDate The start date of the task
|
||||||
|
* @param endDate The maximum date on which the task should be executed
|
||||||
|
* @param interval The number of days between executions
|
||||||
|
* @param cropId The id of the crop to which the task belongs
|
||||||
|
*/
|
||||||
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval, long cropId) {
|
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval, long cropId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -75,10 +100,20 @@ public class Task {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
/**
|
||||||
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
* Checks if the Task is within a specific date range.
|
||||||
|
*
|
||||||
|
* @param searchStartDate The minimum date
|
||||||
|
* @param searchEndDate The maximum date
|
||||||
|
* @return Whether the Task is within the given range
|
||||||
|
*/
|
||||||
|
public boolean isInTimePeriod(LocalDate searchStartDate, LocalDate searchEndDate) {
|
||||||
|
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate) || (nextExecution != null && nextExecution.isBefore(searchEndDate) && nextExecution.isAfter(searchStartDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a specific execution of a Task as done.
|
||||||
|
*/
|
||||||
public void done(){
|
public void done(){
|
||||||
if(interval != null && interval != 0 && !nextExecution.plusDays(interval).isAfter(endDate)){
|
if(interval != null && interval != 0 && !nextExecution.plusDays(interval).isAfter(endDate)){
|
||||||
nextExecution = nextExecution.plusDays(interval);
|
nextExecution = nextExecution.plusDays(interval);
|
||||||
@@ -89,6 +124,7 @@ public class Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
public boolean isDone(){
|
public boolean isDone(){
|
||||||
return nextExecution == null;
|
return nextExecution == null;
|
||||||
}
|
}
|
||||||
@@ -117,6 +153,12 @@ public class Task {
|
|||||||
return Optional.ofNullable(endDate);
|
return Optional.ofNullable(endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the fields of this Task using the values of the given Task
|
||||||
|
*
|
||||||
|
* @param task The task whose fields to copy
|
||||||
|
* @return This task with the fields already updated
|
||||||
|
*/
|
||||||
public Task updateTask(Task task) {
|
public Task updateTask(Task task) {
|
||||||
this.name = task.getName();
|
this.name = task.getName();
|
||||||
this.description = task.getDescription();
|
this.description = task.getDescription();
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ public class TaskTemplate {
|
|||||||
this.relativeStartDate = relativeStartDate;
|
this.relativeStartDate = relativeStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a concrete {@link Task} given a concrete start date
|
||||||
|
*
|
||||||
|
* @param realStartDate The start date of the {@link GrowthPhase} to which the {@link #relativeStartDate} is relative.
|
||||||
|
* @param cropId The crop for which the task should be generated.
|
||||||
|
* @return The created {@link Task}
|
||||||
|
*/
|
||||||
public Task generateTask(LocalDate realStartDate, long cropId) {
|
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate;
|
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the cycle in which a {@link Plant} should be watered
|
||||||
|
*
|
||||||
|
* @param litersPerSqM How many litres of water per square metre of ground
|
||||||
|
* @param interval The interval (days)
|
||||||
|
* @param notes Notes on the cycle
|
||||||
|
*/
|
||||||
public record WateringCycle(
|
public record WateringCycle(
|
||||||
int litersPerSqM,
|
int litersPerSqM,
|
||||||
int interval,
|
int interval,
|
||||||
|
|||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package ch.zhaw.gartenverwaltung.backgroundtasks.weather;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.io.*;
|
||||||
|
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||||
|
import ch.zhaw.gartenverwaltung.types.*;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.MonthDay;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class WeatherGardenTaskPlannerTest {
|
||||||
|
private final URL testFile = JsonCropListTest.class.getResource("test-taskdb.json");
|
||||||
|
Plant examplePlantOnion;
|
||||||
|
Crop exampleCropOnion;
|
||||||
|
Task exampleTask;
|
||||||
|
Task exampleWeatherTask;
|
||||||
|
List<Crop> cropList;
|
||||||
|
List<Plant> plantList;
|
||||||
|
TaskList taskList;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
examplePlantOnion = new Plant(
|
||||||
|
20,
|
||||||
|
"summertime onion",
|
||||||
|
"Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.",
|
||||||
|
null,
|
||||||
|
"15,30,2",
|
||||||
|
0,
|
||||||
|
"sandy to loamy, loose soil, free of stones",
|
||||||
|
new ArrayList<>(),
|
||||||
|
new WateringCycle(15, 3, null),
|
||||||
|
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
|
||||||
|
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
|
||||||
|
new GrowthPhase(MonthDay.of(8, 5), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
|
||||||
|
new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
|
||||||
|
new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
|
||||||
|
|
||||||
|
exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.of(2022, 12, 5))
|
||||||
|
.withId(3L);
|
||||||
|
exampleTask = new Task("water plant","water the plant until the ground is wet enough",LocalDate.now(), LocalDate.now().plusDays(2L),3L);
|
||||||
|
exampleTask.setNextExecution(LocalDate.now().plusDays(1L));
|
||||||
|
exampleWeatherTask = new Task("Hail",
|
||||||
|
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
|
||||||
|
LocalDate.now(),LocalDate.now().plusDays(1L),3L);
|
||||||
|
|
||||||
|
taskList = new JsonTaskList(testFile);
|
||||||
|
|
||||||
|
plantList = new ArrayList<>();
|
||||||
|
plantList.add(examplePlantOnion);
|
||||||
|
|
||||||
|
cropList = new ArrayList<>();
|
||||||
|
cropList.add(exampleCropOnion);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CropList mockCropList(List<Crop> cropList) throws IOException {
|
||||||
|
CropList croplist = mock(CropList.class);
|
||||||
|
when(croplist.getCrops()).thenReturn(cropList);
|
||||||
|
when(croplist.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
||||||
|
return croplist;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlantList mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||||
|
PlantList plantDatabase = mock(JsonPlantList.class);
|
||||||
|
when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList);
|
||||||
|
when(plantDatabase.getPlantById(HardinessZone.ZONE_8A,20)).thenReturn(Optional.of(plantList.get(0)));
|
||||||
|
return plantDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void refreshtasks() throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
||||||
|
WeatherGradenTaskPlanner weatherGradenTaskPlanner = new WeatherGradenTaskPlanner(taskList, mockPlantDatabase(plantList), mockCropList(cropList));
|
||||||
|
taskList.saveTask(exampleTask);
|
||||||
|
weatherGradenTaskPlanner.refreshTasks();
|
||||||
|
assertEquals(exampleTask.getName(),taskList.getTaskList(LocalDate.now(),LocalDate.now().plusDays(7)).get(0).getName());
|
||||||
|
assertEquals(LocalDate.now().plusDays(2L),taskList.getTaskList(LocalDate.now(),LocalDate.now().plusDays(7)).get(0).getNextExecution());
|
||||||
|
assertEquals(exampleWeatherTask.getName(),taskList.getTaskList(LocalDate.now(),LocalDate.now().plusDays(7)).get(1).getName());
|
||||||
|
assertEquals(exampleWeatherTask.getStartDate(),taskList.getTaskList(LocalDate.now(),LocalDate.now().plusDays(7)).get(1).getStartDate());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 {
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user