#23 bugfix adjust task

This commit is contained in:
Gian-Andrea Hutter 2022-12-05 11:02:15 +01:00
parent d0c6525d7a
commit 0fa2b81427
1 changed files with 8 additions and 8 deletions

View File

@ -33,11 +33,11 @@ public class WeatherGradenTaskPlanner {
private void getSevereWeatherEvents() throws IOException { private void getSevereWeatherEvents() throws IOException {
SevereWeather actualWeather = weatherService.causeSevereWeather(1); SevereWeather actualWeather = weatherService.causeSevereWeather(1);
if (SevereWeather.HAIL.equals(actualWeather)) { if (SevereWeather.HAIL.equals(actualWeather)) {
createPreHail(); createPreHailTask();
} else if (SevereWeather.FROST.equals(actualWeather)) { } else if (SevereWeather.FROST.equals(actualWeather)) {
createPreFrost(); createPreFrostTask();
} else if (SevereWeather.SNOW.equals(actualWeather)) { } else if (SevereWeather.SNOW.equals(actualWeather)) {
createPreSnow(); createPreSnowTask();
} }
} }
@ -46,7 +46,7 @@ public class WeatherGradenTaskPlanner {
adjustWateringTask(rainAmount); adjustWateringTask(rainAmount);
} }
public void createPreHail() throws IOException { public void createPreHailTask() throws IOException {
Task preHailTask = new Task("Hail", Task preHailTask = new Task("Hail",
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin", "During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
@ -55,14 +55,14 @@ public class WeatherGradenTaskPlanner {
} }
public void createPreFrost() throws IOException { public void createPreFrostTask() throws IOException {
Task preFrostTask = new Task("Frost", Task preFrostTask = new Task("Frost",
"The temperatur falls below zero degrees, cover especially the root with wool", "The temperatur falls below zero degrees, cover especially the root with wool",
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L)); dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
taskList.saveTask(preFrostTask); taskList.saveTask(preFrostTask);
} }
public void createPreSnow() throws IOException { public void createPreSnowTask() throws IOException {
Task preSnowTask = new Task("Snow", Task preSnowTask = new Task("Snow",
"The weather brings little snowfall. Cover your crops", "The weather brings little snowfall. Cover your crops",
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L)); dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
@ -75,13 +75,13 @@ public class WeatherGradenTaskPlanner {
Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new); Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
if(plant.wateringCycle().litersPerSqM() < rainAmount){ if(plant.wateringCycle().litersPerSqM() < rainAmount){
adjustNextExecutionOfWateringTask(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7))); adjustNextExecutionOfWateringTasks(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7)));
} }
} }
} }
// vom startdatum abhängig, // vom startdatum abhängig,
private void adjustNextExecutionOfWateringTask(List<Task> cropTaskList){ private void adjustNextExecutionOfWateringTasks(List<Task> cropTaskList){
for(Task task : cropTaskList){ for(Task task : cropTaskList){
if(task.getName().equals("water plant")){ if(task.getName().equals("water plant")){
task.setNextExecution(task.getNextExecution().plusDays(task.getInterval().orElse(1))); task.setNextExecution(task.getNextExecution().plusDays(task.getInterval().orElse(1)));