From d1d9d11b665690ed825d8f8630de54804e74e939 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Mon, 31 Oct 2022 14:30:42 +0100 Subject: [PATCH] added Methods in TaskListModel added Field Crop ID in Task added method removeTasksforCrop --- .../gartenverwaltung/io/JsonTaskDatabase.java | 11 +++++++++++ .../zhaw/gartenverwaltung/io/TaskDatabase.java | 5 +++++ .../taskList/PlantNotFoundException.java | 7 +++++++ .../taskList/TaskListModel.java | 10 ++++++++-- .../ch/zhaw/gartenverwaltung/types/Task.java | 1 + .../ch/zhaw/gartenverwaltung/io/taskdb.json | 18 ++++++++++++------ 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/taskList/PlantNotFoundException.java diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index e16a74d..62c18ba 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java @@ -1,5 +1,6 @@ package ch.zhaw.gartenverwaltung.io; +import ch.zhaw.gartenverwaltung.types.Crop; import ch.zhaw.gartenverwaltung.types.Task; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @@ -51,6 +52,16 @@ public class JsonTaskDatabase implements TaskDatabase{ return taskMap.values().stream().filter(task -> task.isInTimePeriode(start, end)).toList(); } + @Override + public List getTaskForCrop(Crop crop) { + return null; //TODO implement + } + + @Override + public void removeTasksForCrop(Crop crop) { + // TODO implement + } + /** * If no data is currently loaded, data is loaded from {@link #dataSource}. * If the {@link Task} has an id than the task is added to the {@link #taskMap} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java index 19ad778..02ca54d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java @@ -1,5 +1,6 @@ package ch.zhaw.gartenverwaltung.io; +import ch.zhaw.gartenverwaltung.types.Crop; import ch.zhaw.gartenverwaltung.types.HardinessZone; import ch.zhaw.gartenverwaltung.types.Plant; import ch.zhaw.gartenverwaltung.types.Task; @@ -24,6 +25,10 @@ public interface TaskDatabase { */ List getTaskList(LocalDate start, LocalDate end) throws IOException; + List getTaskForCrop(Crop crop); //TODO Javadoc + + void removeTasksForCrop(Crop crop); // TODO Javadoc + /** * Saves the {@link Task} in the Cache. * diff --git a/src/main/java/ch/zhaw/gartenverwaltung/taskList/PlantNotFoundException.java b/src/main/java/ch/zhaw/gartenverwaltung/taskList/PlantNotFoundException.java new file mode 100644 index 0000000..149e1ef --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/taskList/PlantNotFoundException.java @@ -0,0 +1,7 @@ +package ch.zhaw.gartenverwaltung.taskList; + +public class PlantNotFoundException extends Exception { + public PlantNotFoundException() { + super("The selected Plant was not found in Database!"); + } +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java index 7525886..a42738d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java @@ -13,6 +13,7 @@ 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 { @@ -34,13 +35,18 @@ public class TaskListModel { taskDatabase.saveTask(task); } - public void planTasksForCrop(Crop crop) throws HardinessZoneNotSetException, IOException { - Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow(); + 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; } + public void removeTasksForCrop(Crop crop) { + //TODO implement + taskDatabase.removeTasksForCrop(crop); + } + public void removeTask(Task task) throws IOException { taskDatabase.removeTask(task); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index 3b26745..dabaf58 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -15,6 +15,7 @@ public class Task { private final LocalDate startDate; private Integer interval; private LocalDate endDate; + private Crop cropId; /** * default constructor diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json index da201c9..b3514b0 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json @@ -5,7 +5,8 @@ "description": "Plant the seeds, crops in de bed.", "startDate" : "2022-05-01", "endDate" : "2022-05-01", - "interval" : 0 + "interval" : 0, + "cropID" : 0 }, { "id" : 2, @@ -13,7 +14,8 @@ "description": "water the plant, so that the soil is wet around the plant.", "startDate" : "2022-05-01", "endDate" : "2022-09-01", - "interval" : 2 + "interval" : 2, + "cropID" : 0 }, { "id" : 3, @@ -21,7 +23,8 @@ "description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture", "startDate" : "2022-06-01", "endDate" : "2022-08-01", - "interval" : 28 + "interval" : 28, + "cropID" : 0 }, { "id" : 4, @@ -29,7 +32,8 @@ "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", "endDate" : "2022-07-01", - "interval" : 0 + "interval" : 0, + "cropID" : 0 }, { "id" : 5, @@ -37,7 +41,8 @@ "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", "endDate" : "2022-09-01", - "interval" : 5 + "interval" : 5, + "cropID" : 0 }, { "id" : 6, @@ -45,6 +50,7 @@ "description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ", "startDate" : "2022-09-01", "endDate" : "2022-09-01", - "interval" : 0 + "interval" : 0, + "cropID" : 0 } ] \ No newline at end of file