Compare commits

...
Author SHA1 Message Date
schrom01 2d88c9ea91 implemented multithreading 2022-11-25 12:58:03 +01:00
schrom01 e48be29d59 Merge branch 'feature_taskList_m2' into feature_notification_m3 2022-11-25 11:14:47 +01:00
schrom01 a437236788 created Class Notifier 2022-11-24 23:45:33 +01:00
7 changed files with 77 additions and 1 deletions
@@ -1,16 +1,23 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
import ch.zhaw.gartenverwaltung.notifier.Notifier;
import javafx.application.Application;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
AppLoader appLoader = new AppLoader();
Notifier notifier = new Notifier(appLoader.getGardenSchedule());
Thread notificationThread = new Thread(notifier);
notificationThread.start();
notificationThread.interrupt();
appLoader.loadSceneToStage("MainFXML.fxml", stage);
stage.setTitle("Gartenverwaltung");
@@ -10,6 +10,7 @@ import ch.zhaw.gartenverwaltung.io.TaskList;
import ch.zhaw.gartenverwaltung.models.Garden;
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
import ch.zhaw.gartenverwaltung.models.PlantListModel;
import ch.zhaw.gartenverwaltung.notifier.Notifier;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.DialogPane;
@@ -41,6 +42,7 @@ public class AppLoader {
public AppLoader() throws IOException {
}
@@ -154,4 +156,8 @@ public class AppLoader {
default -> null;
};
}
public GardenSchedule getGardenSchedule() {
return gardenSchedule;
}
}
@@ -9,7 +9,6 @@ import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class GardenSchedule {
@@ -0,0 +1,48 @@
package ch.zhaw.gartenverwaltung.notifier;
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
import ch.zhaw.gartenverwaltung.types.Task;
import java.io.IOException;
import java.time.LocalDate;
import java.util.function.Consumer;
public class Notifier implements Runnable{
private final GardenSchedule gardenSchedule;
private boolean interrupted = false;
public Notifier(GardenSchedule gardenSchedule) {
this.gardenSchedule = gardenSchedule;
}
private void sendNotification(Task task){
// TODO implement
}
private void sendNotifications(){
System.out.println("sending Notifications");
try {
gardenSchedule.getTaskList().forEach(task -> {
if(task.getNextNotification() != null && task.getNextNotification().isBefore(LocalDate.now().minusDays(1))){
sendNotification(task);
task.setNextNotification(task.getNextExecution());
}
});
} catch (IOException e) {
// TODO Logger
e.printStackTrace();
}
}
@Override
public void run() {
while(!interrupted){
try {
sendNotifications();
Thread.sleep(3000);
} catch (InterruptedException e) {
interrupted = true;
}
}
}
}
@@ -71,8 +71,10 @@ public class Task {
public void done(){
if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){
nextExecution = nextExecution.plusDays(interval);
nextNotification = nextExecution;
} else {
nextExecution = null;
nextNotification = null;
}
}
+2
View File
@@ -13,4 +13,6 @@ module ch.zhaw.gartenverwaltung {
exports ch.zhaw.gartenverwaltung.types;
exports ch.zhaw.gartenverwaltung.models;
exports ch.zhaw.gartenverwaltung.json;
exports ch.zhaw.gartenverwaltung.notifier;
opens ch.zhaw.gartenverwaltung.notifier to javafx.fxml;
}
@@ -4,6 +4,8 @@
"name" : "sow plant",
"description": "Plant the seeds, crops in de bed.",
"startDate" : "2022-05-01",
"nextExecution": "2022-05-01",
"nextNotification": "2022-05-01",
"endDate" : "2022-05-01",
"interval" : 0,
"cropId" : 0
@@ -13,6 +15,8 @@
"name" : "water plant",
"description": "water the plant, so that the soil is wet around the plant.",
"startDate" : "2022-05-01",
"nextExecution": "2022-05-01",
"nextNotification": "2022-05-01",
"endDate" : "2022-09-01",
"interval" : 2,
"cropId" : 0
@@ -22,6 +26,8 @@
"name" : "fertilize plant",
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
"startDate" : "2022-06-01",
"nextExecution": "2022-05-01",
"nextNotification": "2022-05-01",
"endDate" : "2022-08-01",
"interval" : 28,
"cropId" : 0
@@ -31,6 +37,8 @@
"name" : "covering plant",
"description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage",
"startDate" : "2022-07-01",
"nextExecution": "2022-05-01",
"nextNotification": "2022-05-01",
"endDate" : "2022-07-01",
"interval" : 0,
"cropId" : 0
@@ -40,6 +48,8 @@
"name" : "look after plant",
"description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil",
"startDate" : "2022-05-01",
"nextExecution": "2022-05-01",
"nextNotification": "2022-05-01",
"endDate" : "2022-09-01",
"interval" : 5,
"cropId" : 0
@@ -49,6 +59,8 @@
"name" : "harvest plant",
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
"startDate" : "2022-09-01",
"nextExecution": "2022-05-01",
"nextNotification": "2022-05-01",
"endDate" : "2022-09-01",
"interval" : 0,
"cropId" : 0