created Class Notifier
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
|
||||
public Notifier(GardenSchedule gardenSchedule) {
|
||||
this.gardenSchedule = gardenSchedule;
|
||||
}
|
||||
|
||||
private void sendNotification(Task task){
|
||||
// TODO implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
gardenSchedule.getTaskList().forEach(new Consumer<Task>() {
|
||||
@Override
|
||||
public void accept(Task 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,8 +69,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user