diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Config.java b/src/main/java/ch/zhaw/gartenverwaltung/Config.java new file mode 100644 index 0000000..2fa0117 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/Config.java @@ -0,0 +1,19 @@ +package ch.zhaw.gartenverwaltung; + +import ch.zhaw.gartenverwaltung.types.HardinessZone; + +public class Config { + private static HardinessZone currentHardinessZone; + + static { + currentHardinessZone = HardinessZone.ZONE_8A; + } + + public static HardinessZone getCurrentHardinessZone() { + return currentHardinessZone; + } + + public static void setCurrentHardinessZone(HardinessZone currentHardinessZone) { + Config.currentHardinessZone = currentHardinessZone; + } +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java index a42738d..a285723 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java @@ -1,19 +1,16 @@ package ch.zhaw.gartenverwaltung.taskList; +import ch.zhaw.gartenverwaltung.Config; import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase; import ch.zhaw.gartenverwaltung.io.PlantDatabase; import ch.zhaw.gartenverwaltung.io.TaskDatabase; -import ch.zhaw.gartenverwaltung.types.Crop; -import ch.zhaw.gartenverwaltung.types.HardinessZone; -import ch.zhaw.gartenverwaltung.types.Plant; -import ch.zhaw.gartenverwaltung.types.Task; +import ch.zhaw.gartenverwaltung.types.*; import java.io.IOException; import java.time.LocalDate; import java.util.Comparator; import java.util.List; -import java.util.function.Supplier; import java.util.stream.Collectors; public class TaskListModel { @@ -36,14 +33,15 @@ public class TaskListModel { } public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException { - Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow(PlantNotFoundException::new); - // TODO new exception - // TODO HArdiness Zone - return; + Plant plant = plantDatabase.getPlantById(Config.getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new); + for (GrowthPhase growthPhase : plant.lifecycle()) { + for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) { + addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L))); + } + } } public void removeTasksForCrop(Crop crop) { - //TODO implement taskDatabase.removeTasksForCrop(crop); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index dabaf58..8d3db25 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -15,22 +15,24 @@ public class Task { private final LocalDate startDate; private Integer interval; private LocalDate endDate; - private Crop cropId; + private long cropId; /** * default constructor * (used by Json deserializer) */ - public Task(){ + public Task(long cropId){ name= ""; description= ""; startDate = LocalDate.now(); + this.cropId = cropId; } - public Task(String name, String description, LocalDate startDate) { + public Task(String name, String description, LocalDate startDate, long cropId) { this.name = name; this.description = description; this.startDate = startDate; + this.cropId = cropId; } public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval) { @@ -56,10 +58,7 @@ public class Task { } public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){ - if(startDate.isAfter(searchStartDate) &&startDate.isBefore(searchEndDate)){ - return true; - } - return false; + return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate); } // Getters diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java index 290175e..8ae7862 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java @@ -44,8 +44,8 @@ public class TaskTemplate { this.relativeStartDate = relativeStartDate; } - public Task generateTask(LocalDate realStartDate) { - Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate)); + public Task generateTask(LocalDate realStartDate, long cropId) { + Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId); if (relativeEndDate != null) { task.withEndDate(realStartDate.plusDays(relativeEndDate)); }