created Class Notifier

This commit is contained in:
schrom01 2022-11-24 23:45:33 +01:00
parent b2c0886e46
commit a437236788
5 changed files with 63 additions and 18 deletions

View File

@ -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();
}
}
}

View File

@ -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;
}
}

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;
}

View File

@ -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

View File

@ -32,8 +32,7 @@
"relativeStartDate": -14,
"relativeEndDate": null,
"description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.",
"interval": null,
"isOptional": false
"interval": null
}
]
},
@ -54,8 +53,7 @@
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.",
"interval": 21,
"isOptional": false
"interval": 21
}
]
},
@ -76,8 +74,7 @@
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.",
"interval": null,
"isOptional": false
"interval": null
}
]
}
@ -106,8 +103,7 @@
"relativeStartDate": 0,
"relativeEndDate": 0,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": null,
"isOptional": false
"interval": null
}
]
},
@ -130,8 +126,7 @@
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": 15,
"isOptional": true
"interval": 15
}
]
},
@ -152,8 +147,7 @@
"relativeStartDate": 0,
"relativeEndDate": 14,
"description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.",
"interval": null,
"isOptional": false
"interval": null
}
]
}
@ -193,8 +187,7 @@
"relativeStartDate": 0,
"relativeEndDate": 0,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": null,
"isOptional": false
"interval": null
}
]
},
@ -217,8 +210,7 @@
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": 15,
"isOptional": true
"interval": 15
}
]
},
@ -241,8 +233,7 @@
"relativeStartDate": 0,
"relativeEndDate": 14,
"description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter",
"interval": null,
"isOptional": false
"interval": null
}
]
}