Merged Notification Branch with Weather Branch
This commit is contained in:
parent
fd28ca7cc2
commit
55f92f92bd
|
@ -2,9 +2,11 @@ package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||||
import ch.zhaw.gartenverwaltung.backgroundtasks.BackgroundTasks;
|
import ch.zhaw.gartenverwaltung.backgroundtasks.BackgroundTasks;
|
||||||
|
import ch.zhaw.gartenverwaltung.io.CropList;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||||
import ch.zhaw.gartenverwaltung.io.TaskList;
|
import ch.zhaw.gartenverwaltung.io.TaskList;
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||||
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
@ -19,7 +21,7 @@ public class Main extends Application {
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
AppLoader appLoader = new AppLoader();
|
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);
|
backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 1000);
|
||||||
|
|
||||||
appLoader.loadSceneToStage("MainFXML.fxml", stage);
|
appLoader.loadSceneToStage("MainFXML.fxml", stage);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ch.zhaw.gartenverwaltung.backgroundtasks;
|
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.PlantList;
|
||||||
import ch.zhaw.gartenverwaltung.io.TaskList;
|
import ch.zhaw.gartenverwaltung.io.TaskList;
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||||
|
@ -10,11 +12,11 @@ import java.util.TimerTask;
|
||||||
|
|
||||||
public class BackgroundTasks extends TimerTask {
|
public class BackgroundTasks extends TimerTask {
|
||||||
private final Notifier notifier;
|
private final Notifier notifier;
|
||||||
//TODO uncomment: privat final WeatherGardenTaskPlaner weatherGardenTaskPlaner;
|
private final WeatherGradenTaskPlanner weatherGardenTaskPlaner;
|
||||||
|
|
||||||
public BackgroundTasks(TaskList taskList, Garden garden, PlantList plantList) {
|
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
|
||||||
notifier = new Notifier(taskList, garden, plantList);
|
notifier = new Notifier(taskList, plantList, cropList);
|
||||||
//TODO uncomment: weatherGardenTaskPlaner = new WeatherGardenTaskPlaner(taskList);
|
weatherGardenTaskPlaner = new WeatherGradenTaskPlanner(taskList, plantList, cropList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,10 +2,10 @@ package ch.zhaw.gartenverwaltung.backgroundtasks;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.Settings;
|
import ch.zhaw.gartenverwaltung.Settings;
|
||||||
import ch.zhaw.gartenverwaltung.backgroundtasks.email.EMailSender;
|
import ch.zhaw.gartenverwaltung.backgroundtasks.email.EMailSender;
|
||||||
|
import ch.zhaw.gartenverwaltung.io.CropList;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||||
import ch.zhaw.gartenverwaltung.io.TaskList;
|
import ch.zhaw.gartenverwaltung.io.TaskList;
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
|
|
||||||
|
@ -15,21 +15,21 @@ import java.time.LocalDate;
|
||||||
|
|
||||||
public class Notifier {
|
public class Notifier {
|
||||||
private final TaskList taskList;
|
private final TaskList taskList;
|
||||||
private final Garden garden;
|
private final CropList cropList;
|
||||||
private final PlantList plantList;
|
private final PlantList plantList;
|
||||||
private final EMailSender eMailSender = new EMailSender();
|
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.taskList = taskList;
|
||||||
this.garden = garden;
|
this.cropList = cropList;
|
||||||
this.plantList = plantList;
|
this.plantList = plantList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification(Task task) {
|
private void sendNotification(Task task) {
|
||||||
String plantName = "unkown plant";
|
String plantName = "unkown plant";
|
||||||
try {
|
try {
|
||||||
if(garden.getCrop(task.getCropId()).isPresent()){
|
if(cropList.getCropById((task.getCropId())).isPresent()){
|
||||||
Crop crop = garden.getCrop(task.getCropId()).get();
|
Crop crop = cropList.getCropById(task.getCropId()).get();
|
||||||
if(plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).isPresent()) {
|
if(plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).isPresent()) {
|
||||||
plantName = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get().name();
|
plantName = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get().name();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue