From 55f92f92bded75d98e4c3bc6c448974acb85cc8e Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 29 Nov 2022 12:12:16 +0100 Subject: [PATCH] Merged Notification Branch with Weather Branch --- src/main/java/ch/zhaw/gartenverwaltung/Main.java | 4 +++- .../backgroundtasks/BackgroundTasks.java | 12 +++++++----- .../gartenverwaltung/backgroundtasks/Notifier.java | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Main.java b/src/main/java/ch/zhaw/gartenverwaltung/Main.java index 1b3dfc0..9005ec0 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Main.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Main.java @@ -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); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java index 2cb5e2e..bfa5571 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java @@ -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 diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java index c172e83..da44149 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java @@ -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(); }