#23 documentation
This commit is contained in:
parent
0fa2b81427
commit
28f76e7a04
|
@ -11,6 +11,10 @@ import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The WeatherGardenTaskPlanner creates Tasks based on weather events and the rain amount from the last days
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class WeatherGradenTaskPlanner {
|
public class WeatherGradenTaskPlanner {
|
||||||
private final TaskList taskList;
|
private final TaskList taskList;
|
||||||
private final PlantList plantList;
|
private final PlantList plantList;
|
||||||
|
@ -25,6 +29,12 @@ public class WeatherGradenTaskPlanner {
|
||||||
weatherService = new WeatherService();
|
weatherService = new WeatherService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to refresh watering tasks and severe weather tasks
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
* @throws HardinessZoneNotSetException If the hardiness zone is not available
|
||||||
|
* @throws PlantNotFoundException if the plant is not available for the watering task
|
||||||
|
*/
|
||||||
public void refreshTasks() throws IOException, HardinessZoneNotSetException, PlantNotFoundException {
|
public void refreshTasks() throws IOException, HardinessZoneNotSetException, PlantNotFoundException {
|
||||||
getSevereWeatherEvents();
|
getSevereWeatherEvents();
|
||||||
getRainAmount();
|
getRainAmount();
|
||||||
|
@ -46,7 +56,11 @@ public class WeatherGradenTaskPlanner {
|
||||||
adjustWateringTask(rainAmount);
|
adjustWateringTask(rainAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createPreHailTask() throws IOException {
|
/**
|
||||||
|
* Method to create a PreHailTask
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
*/
|
||||||
|
private 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,21 +69,36 @@ public class WeatherGradenTaskPlanner {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createPreFrostTask() throws IOException {
|
/**
|
||||||
|
* Method to create a PreFrosttask
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
*/
|
||||||
|
private 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 createPreSnowTask() throws IOException {
|
/**
|
||||||
|
* Method to create a PreSnowTask
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
*/
|
||||||
|
private 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));
|
||||||
taskList.saveTask(preSnowTask);
|
taskList.saveTask(preSnowTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void adjustWateringTask(int rainAmount) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
/**
|
||||||
|
* Method to adjust the water plant tasks
|
||||||
|
* @param rainAmount Amount of rain from the last 7 days
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
* @throws HardinessZoneNotSetException If the hardiness zone is not available
|
||||||
|
* @throws PlantNotFoundException if the plant is not available for the watering task
|
||||||
|
*/
|
||||||
|
private void adjustWateringTask(int rainAmount) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
||||||
|
|
||||||
for (Crop crop : cropList.getCrops()) {
|
for (Crop crop : cropList.getCrops()) {
|
||||||
Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||||
|
@ -80,7 +109,14 @@ public class WeatherGradenTaskPlanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// vom startdatum abhängig,
|
|
||||||
|
/**
|
||||||
|
* Method to set next execution date of the water plant tasks
|
||||||
|
* @param cropTaskList List with tasks from crops
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
* @throws HardinessZoneNotSetException If the hardiness zone is not available
|
||||||
|
* @throws PlantNotFoundException if the plant is not available for the watering task
|
||||||
|
*/
|
||||||
private void adjustNextExecutionOfWateringTasks(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")){
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package ch.zhaw.gartenverwaltung.backgroundtasks.weather;
|
package ch.zhaw.gartenverwaltung.backgroundtasks.weather;
|
||||||
|
/**
|
||||||
|
* The WeatherService is a class to cause weather events for the WeatherGardenTaskPlanner
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class WeatherService {
|
public class WeatherService {
|
||||||
private static final int NO_RAIN = 0;
|
private static final int NO_RAIN = 0;
|
||||||
private static final int LITTLE_RAIN = 15;
|
private static final int LITTLE_RAIN = 15;
|
||||||
|
|
Loading…
Reference in New Issue