Merge remote-tracking branch 'origin/feature_weather' into feature_weather

This commit is contained in:
Gian-Andrea Hutter 2022-11-29 12:13:01 +01:00
commit c16f99aabc
3 changed files with 16 additions and 12 deletions

View File

@ -2,9 +2,11 @@ package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
import ch.zhaw.gartenverwaltung.backgroundtasks.BackgroundTasks;
import ch.zhaw.gartenverwaltung.io.CropList;
import ch.zhaw.gartenverwaltung.io.PlantList;
import ch.zhaw.gartenverwaltung.io.TaskList;
import ch.zhaw.gartenverwaltung.models.Garden;
import ch.zhaw.gartenverwaltung.types.Crop;
import javafx.application.Application;
import javafx.stage.Stage;
@ -19,7 +21,7 @@ public class Main extends Application {
public void start(Stage stage) throws IOException {
AppLoader appLoader = new AppLoader();
backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(Garden) appLoader.getAppDependency(Garden.class), (PlantList) appLoader.getAppDependency(PlantList.class));
backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class));
backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 1000);
appLoader.loadSceneToStage("MainFXML.fxml", stage);

View File

@ -1,5 +1,7 @@
package ch.zhaw.gartenverwaltung.backgroundtasks;
import ch.zhaw.gartenverwaltung.backgroundtasks.weather.WeatherGradenTaskPlanner;
import ch.zhaw.gartenverwaltung.io.CropList;
import ch.zhaw.gartenverwaltung.io.PlantList;
import ch.zhaw.gartenverwaltung.io.TaskList;
import ch.zhaw.gartenverwaltung.models.Garden;
@ -9,12 +11,12 @@ import java.io.IOException;
import java.util.TimerTask;
public class BackgroundTasks extends TimerTask {
private final Notifier notifier;
//TODO uncomment: privat final WeatherGardenTaskPlaner weatherGardenTaskPlaner;
private final Notifier notifier;
private final WeatherGradenTaskPlanner weatherGardenTaskPlaner;
public BackgroundTasks(TaskList taskList, Garden garden, PlantList plantList) {
notifier = new Notifier(taskList, garden, plantList);
//TODO uncomment: weatherGardenTaskPlaner = new WeatherGardenTaskPlaner(taskList);
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
notifier = new Notifier(taskList, plantList, cropList);
weatherGardenTaskPlaner = new WeatherGradenTaskPlanner(taskList, plantList, cropList);
}
@Override

View File

@ -2,10 +2,10 @@ package ch.zhaw.gartenverwaltung.backgroundtasks;
import ch.zhaw.gartenverwaltung.Settings;
import ch.zhaw.gartenverwaltung.backgroundtasks.email.EMailSender;
import ch.zhaw.gartenverwaltung.io.CropList;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.io.PlantList;
import ch.zhaw.gartenverwaltung.io.TaskList;
import ch.zhaw.gartenverwaltung.models.Garden;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Task;
@ -15,21 +15,21 @@ import java.time.LocalDate;
public class Notifier {
private final TaskList taskList;
private final Garden garden;
private final CropList cropList;
private final PlantList plantList;
private final EMailSender eMailSender = new EMailSender();
public Notifier(TaskList taskList, Garden garden, PlantList plantList) {
public Notifier(TaskList taskList, PlantList plantList, CropList cropList) {
this.taskList = taskList;
this.garden = garden;
this.cropList = cropList;
this.plantList = plantList;
}
private void sendNotification(Task task) {
String plantName = "unkown plant";
try {
if(garden.getCrop(task.getCropId()).isPresent()){
Crop crop = garden.getCrop(task.getCropId()).get();
if(cropList.getCropById((task.getCropId())).isPresent()){
Crop crop = cropList.getCropById(task.getCropId()).get();
if(plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).isPresent()) {
plantName = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get().name();
}