diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index a849bbc..5d92e56 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; @@ -57,6 +58,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 8b955f9..b3514b0 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json @@ -1,50 +1,56 @@ [ { - "id": 1, - "name": "sow plant", - "description": "Plant the seeds, crops in de bed.", - "startDate": "2022-05-01", - "endDate": "2022-05-01", - "interval": 0 + "id" : 1, + "name" : "sow plant", + "description": "Plant the seeds, crops in de bed.", + "startDate" : "2022-05-01", + "endDate" : "2022-05-01", + "interval" : 0, + "cropID" : 0 }, { - "id": 2, - "name": "water plant", + "id" : 2, + "name" : "water plant", "description": "water the plant, so that the soil is wet around the plant.", - "startDate": "2022-05-01", - "endDate": "2022-09-01", - "interval": 2 + "startDate" : "2022-05-01", + "endDate" : "2022-09-01", + "interval" : 2, + "cropID" : 0 }, { - "id": 3, - "name": "fertilize plant", + "id" : 3, + "name" : "fertilize plant", "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 + "startDate" : "2022-06-01", + "endDate" : "2022-08-01", + "interval" : 28, + "cropID" : 0 }, { - "id": 4, - "name": "covering plant", + "id" : 4, + "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", - "endDate": "2022-07-01", - "interval": 0 + "startDate" : "2022-07-01", + "endDate" : "2022-07-01", + "interval" : 0, + "cropID" : 0 }, { - "id": 5, - "name": "look after plant", + "id" : 5, + "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", - "endDate": "2022-09-01", - "interval": 5 + "startDate" : "2022-05-01", + "endDate" : "2022-09-01", + "interval" : 5, + "cropID" : 0 }, { - "id": 6, - "name": "harvest plant", + "id" : 6, + "name" : "harvest plant", "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 + "startDate" : "2022-09-01", + "endDate" : "2022-09-01", + "interval" : 0, + "cropID" : 0 } -] +] \ No newline at end of file