From 63d7eddff46bb39599346133bf5783bfbe017d1c Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Sun, 30 Oct 2022 23:34:42 +0100 Subject: [PATCH 01/11] #27 first implemention of the Gardenplanmodel --- .../gardenplan/Gardenplanmodel.java | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java index 24757bd..4eec7fb 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java @@ -1,7 +1,93 @@ package ch.zhaw.gartenverwaltung.gardenplan; +import ch.zhaw.gartenverwaltung.io.*; +import ch.zhaw.gartenverwaltung.types.*; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + public class Gardenplanmodel { -// private JasonGardenplan gardenplan; + private GardenPlan gardenplan; + private TaskDatabase taskDatabase; + private PlantDatabase plantDatabase; +// private TaskListmodel; + private List cropList = Collections.emptyList(); + + public Gardenplanmodel() { + try { + cropList = gardenplan.getCrops(); + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + + } + + public void plantCrop(Crop crop){ + cropList.add(crop); + + try { + gardenplan.saveCrop(crop); + createGardeningTasks(crop); + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + + } + + public void removeCrop(Crop crop){ + cropList.remove(crop); + try { + gardenplan.removeCrop(crop); + //TaskListModel.removeTasksForCrop(crop) + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + + } + + public List getCrops(){ + if(cropList.isEmpty()){ + try { + cropList = gardenplan.getCrops(); + } catch (IOException ioException){ + System.err.println("Crops could not be loaded"); + } + + } + return cropList; + } + + public Optional getCrop(Long id){ + try { + return gardenplan.getCropById(id); + + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + return null; + } + + private void createGardeningTasks(Crop crop) throws IOException { + //TaskListModel.generateTasksForCrop(crop) + long plantId = crop.getPlantId(); + Optional plant; + + try { + plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, plantId); + } catch (IOException ioException){ + + } catch (HardinessZoneNotSetException hardinessZoneNotSetException){ + System.out.println("Hardinesszone not set!"); + } + //TODO need to get the plants templates + // plant.getPlantTemplates + // CreateTaskWithTasktemplate + //taskDatabase.saveTask(task); + } + // liste von crops //task generieren //plant holen, task template mit tasktemplateklasse tasks erstellen From 251060811791e16f4230bc906111d0740631f71a Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Mon, 31 Oct 2022 11:55:20 +0100 Subject: [PATCH 02/11] Extended taskDb tests --- .../io/JsonTaskDatabaseTest.java | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java index e75ea40..a6c3689 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java @@ -6,32 +6,80 @@ import org.junit.jupiter.api.*; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; +import java.util.Optional; + public class JsonTaskDatabaseTest { TaskDatabase testDatabase; - SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); @BeforeEach void connectToDb() { - // testDatabase = new JsonTaskDatabase(); + testDatabase = new JsonTaskDatabase(); } @Test @DisplayName("Check if results are retrieved completely") void getTasks(){ - /* + List taskList=null; try { - taskList = testDatabase.getTaskList(formatter.parse("01.05.2022"), formatter.parse("01.08.2022")); + taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022",formatter), + LocalDate.parse("31.05.2022",formatter)); } catch (IOException e) { throw new RuntimeException(e); - } catch (ParseException e) { - throw new RuntimeException(e); } - Assertions.assertTrue(taskList.size()>0); - */ + Assertions.assertEquals(3,taskList.size()); + } + + @Disabled("disabled until idProvider works") + @Test + @DisplayName("Add task.") + void addTask(){ + Task task = new Task("Testtask","This is a test Task.",LocalDate.parse("01.05.2022",formatter)); + try { + testDatabase.saveTask(task); + List taskList=null; + try { + taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022",formatter), + LocalDate.parse("31.05.2022",formatter)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Assertions.assertEquals(4,taskList.size()); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + @DisplayName("Remove task.") + void removeTask(){ + Task task = new Task("Dummy","Dummy",LocalDate.parse("31.05.2022",formatter)).withId(2); + try { + testDatabase.removeTask(task); + List taskList=null; + try { + taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022",formatter), + LocalDate.parse("31.05.2022",formatter)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Assertions.assertEquals(2,taskList.size()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + } From 6273b0e59a37f95d0235c144be78d50b5601a44f Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Mon, 31 Oct 2022 12:24:54 +0100 Subject: [PATCH 03/11] #27 implementation of task template with task generation --- .../gardenplan/Gardenplanmodel.java | 106 +++++++++++++++++- .../gartenverwaltung/io/JsonTaskDatabase.java | 3 + 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java index 24757bd..c2cabee 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java @@ -1,8 +1,106 @@ package ch.zhaw.gartenverwaltung.gardenplan; +import ch.zhaw.gartenverwaltung.io.GardenPlan; +import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; +import ch.zhaw.gartenverwaltung.io.TaskDatabase; +import ch.zhaw.gartenverwaltung.io.PlantDatabase; +import ch.zhaw.gartenverwaltung.types.*; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + public class Gardenplanmodel { -// private JasonGardenplan gardenplan; - // liste von crops - //task generieren - //plant holen, task template mit tasktemplateklasse tasks erstellen + private GardenPlan gardenplan; + private TaskDatabase taskDatabase; + private PlantDatabase plantDatabase; +// private TaskListmodel; + private List cropList = Collections.emptyList(); + + public Gardenplanmodel() { + try { + cropList = gardenplan.getCrops(); + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + + } + + public void plantCrop(Crop crop){ + cropList.add(crop); + + try { + gardenplan.saveCrop(crop); + createGardeningTasks(crop); + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + + } + + public void removeCrop(Crop crop){ + cropList.remove(crop); + try { + gardenplan.removeCrop(crop); + //TaskListModel.removeTasksForCrop(crop) + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + + } + + public List getCrops(){ + if(cropList.isEmpty()){ + try { + cropList = gardenplan.getCrops(); + } catch (IOException ioException){ + System.err.println("Crops could not be loaded"); + } + + } + return cropList; + } + + public Optional getCrop(Long id){ + try { + return gardenplan.getCropById(id); + + } catch (IOException ioException){ + System.err.println("The task can not be created!"); + } + return null; + } + + private void createGardeningTasks(Crop crop) throws IOException, HardinessZoneNotSetException { + //TaskListModel.generateTasksForCrop(crop) + long plantId = crop.getPlantId(); + Optional plant; + Task task; + + Plant plantL = plant; + + + plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, plantId); + + if(plant.isPresent()){ + List growthPhases = plantL.lifecycleForGroup(0); + GrowthPhase growthPhase = growthPhases.get(0); + List taskTemplatesForLyfecycle= growthPhase.taskTemplates(); + + task = taskTemplatesForLyfecycle.get(0).generateTask(crop.getStartDate()); + taskDatabase.saveTask(task); + } else { + + } + + + + + //TODO need to get the plants templates, or through the Growphase + // plant.getPlantTemplates + // CreateTaskWithTasktemplate + + } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index e16a74d..82d5812 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; import java.io.File; import java.io.IOException; @@ -34,6 +35,8 @@ public class JsonTaskDatabase implements TaskDatabase{ static { DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateDeserializer dateDeserializer = new LocalDateDeserializer(dateFormat); + //TODO Serializer + LocalDateSerializer dateSerializer = new LocalDateSerializer(dateFormat); timeModule.addDeserializer(LocalDate.class, dateDeserializer); } From afac3ba855583cfcf99de624e16c1d4a37bd240e Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Mon, 31 Oct 2022 12:45:24 +0100 Subject: [PATCH 04/11] #17 Serialization implemented --- .../java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index e16a74d..37c7016 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; import java.io.File; import java.io.IOException; @@ -34,7 +35,10 @@ public class JsonTaskDatabase implements TaskDatabase{ static { DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateDeserializer dateDeserializer = new LocalDateDeserializer(dateFormat); + LocalDateSerializer dateSerializer = new LocalDateSerializer(dateFormat); + timeModule.addDeserializer(LocalDate.class, dateDeserializer); + timeModule.addSerializer(LocalDate.class, dateSerializer); } /** From 5c6528a038597eb7aa8bf8612c725c7c7be2aa5c Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Mon, 31 Oct 2022 12:54:52 +0100 Subject: [PATCH 05/11] Update JsonTaskDatabaseTest.java --- .../java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java index a6c3689..f4df3da 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java @@ -38,7 +38,7 @@ public class JsonTaskDatabaseTest { } - @Disabled("disabled until idProvider works") + //@Disabled("disabled until idProvider works") @Test @DisplayName("Add task.") void addTask(){ From 29ad2fdae211e306c8413c7da4f76ec9f4aedf03 Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Mon, 31 Oct 2022 13:19:14 +0100 Subject: [PATCH 06/11] #17 Bug Mismatchexception fixed --- .../gartenverwaltung/io/JsonTaskDatabase.java | 19 ++++-- .../ch/zhaw/gartenverwaltung/io/taskdb.json | 64 +++++++++---------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index 37c7016..a849bbc 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -25,6 +26,7 @@ import java.util.Map; public class JsonTaskDatabase implements TaskDatabase{ IdProvider idProvider; private final URL dataSource = getClass().getResource("taskdb.json"); + private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!"; private Map taskMap = Collections.emptyMap(); @@ -99,12 +101,16 @@ public class JsonTaskDatabase implements TaskDatabase{ * @throws IOException If the database cannot be accessed */ private void writeTaskListToFile() throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(timeModule) - .registerModule(new Jdk8Module()); - if(dataSource != null) { - mapper.writeValue(new File(dataSource.getFile()), taskMap); + try { + new ObjectMapper() + .registerModule(timeModule) + .registerModule(new Jdk8Module()) + .writeValue(new File(dataSource.toURI()), taskMap.values()); + + } catch (URISyntaxException e) { + throw new IOException(INVALID_DATASOURCE_MSG, e); + } } } @@ -116,7 +122,8 @@ public class JsonTaskDatabase implements TaskDatabase{ private void loadTaskListFromFile() throws IOException { if (dataSource != null) { ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(timeModule); + mapper.registerModule(timeModule) + .registerModule(new Jdk8Module()); List result; result = mapper.readerForListOf(Task.class).readValue(dataSource); diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json index da201c9..8b955f9 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json @@ -1,50 +1,50 @@ [ { - "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 }, { - "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 }, { - "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 }, { - "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 }, { - "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 }, { - "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 } -] \ No newline at end of file +] From 9e14920fbb71fa183ea97ae5198d5a242389a9ec Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Tue, 1 Nov 2022 10:33:07 +0100 Subject: [PATCH 07/11] #27 gardenplanmodel fully implemented --- .../gardenplan/Gardenplanmodel.java | 144 ++++++++---------- 1 file changed, 64 insertions(+), 80 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java index c2cabee..18e072b 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java @@ -2,105 +2,89 @@ package ch.zhaw.gartenverwaltung.gardenplan; import ch.zhaw.gartenverwaltung.io.GardenPlan; import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; +import ch.zhaw.gartenverwaltung.io.JsonGardenPlan; import ch.zhaw.gartenverwaltung.io.TaskDatabase; -import ch.zhaw.gartenverwaltung.io.PlantDatabase; -import ch.zhaw.gartenverwaltung.types.*; +import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException; +import ch.zhaw.gartenverwaltung.taskList.TaskListModel; +import ch.zhaw.gartenverwaltung.types.Crop; +import ch.zhaw.gartenverwaltung.types.Plant; +import ch.zhaw.gartenverwaltung.types.Task; import java.io.IOException; -import java.util.Collection; -import java.util.Collections; +import java.time.LocalDate; import java.util.List; import java.util.Optional; +/** + * The Gardenplan model manages the crops in the gardenplan. + */ public class Gardenplanmodel { - private GardenPlan gardenplan; - private TaskDatabase taskDatabase; - private PlantDatabase plantDatabase; -// private TaskListmodel; - private List cropList = Collections.emptyList(); - - public Gardenplanmodel() { - try { - cropList = gardenplan.getCrops(); - } catch (IOException ioException){ - System.err.println("The task can not be created!"); - } + private GardenPlan gardenPlan; + private List cropList; + private TaskListModel taskListModel; + /** + * Constructor of Gardenplan model + * + * @param taskListModel holds a reference to the task list object. + */ + public Gardenplanmodel(TaskListModel taskListModel) throws IOException { + this.taskListModel = taskListModel; + gardenPlan = new JsonGardenPlan(); + cropList = gardenPlan.getCrops(); } - public void plantCrop(Crop crop){ + /** + * Creates a Crop with a {@link Plant} and the planting date of the plant. Then let the Tasklistmodel create the + * gardening {@link Task} for the crop. Store the crop in the gardenplan file and the cache. + * + * @param plant The plant which is wnated to be planted + * @param plantingDate The date, when the plant is planted + * @throws IOException If the database cannot be accessed + * @throws HardinessZoneNotSetException If the hardinesszone could not be added + * @throws PlantNotFoundException If the plant is not found in the database. + */ + public void plantAsCrop(Plant plant, LocalDate plantingDate) throws IOException, HardinessZoneNotSetException, PlantNotFoundException { + Crop crop = new Crop(plant.id(),plantingDate); + //TODO Add Area to Plant + crop.withArea(0); + cropList.add(crop); - - try { - gardenplan.saveCrop(crop); - createGardeningTasks(crop); - } catch (IOException ioException){ - System.err.println("The task can not be created!"); - } - + gardenPlan.saveCrop(crop); + taskListModel.planTasksForCrop(crop); } - public void removeCrop(Crop crop){ + /** + * Removes a {@link Crop} from the file and the cache + * + * @param crop The plant which is wnated to be planted + * @throws IOException If the database cannot be accessed + */ + public void removeCrop(Crop crop) throws IOException { + cropList.remove(crop); - try { - gardenplan.removeCrop(crop); - //TaskListModel.removeTasksForCrop(crop) - } catch (IOException ioException){ - System.err.println("The task can not be created!"); - } - + gardenPlan.removeCrop(crop); + taskListModel.removeTasksForCrop(crop); } - - public List getCrops(){ + /** + * Returns a list of {@link Crop}s which are currently in the gardenplan. + * + * @throws IOException If the database cannot be accessed + */ + public List getCrops() throws IOException { if(cropList.isEmpty()){ - try { - cropList = gardenplan.getCrops(); - } catch (IOException ioException){ - System.err.println("Crops could not be loaded"); - } - + cropList = gardenPlan.getCrops(); } return cropList; } - public Optional getCrop(Long id){ - try { - return gardenplan.getCropById(id); - - } catch (IOException ioException){ - System.err.println("The task can not be created!"); - } - return null; - } - - private void createGardeningTasks(Crop crop) throws IOException, HardinessZoneNotSetException { - //TaskListModel.generateTasksForCrop(crop) - long plantId = crop.getPlantId(); - Optional plant; - Task task; - - Plant plantL = plant; - - - plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, plantId); - - if(plant.isPresent()){ - List growthPhases = plantL.lifecycleForGroup(0); - GrowthPhase growthPhase = growthPhases.get(0); - List taskTemplatesForLyfecycle= growthPhase.taskTemplates(); - - task = taskTemplatesForLyfecycle.get(0).generateTask(crop.getStartDate()); - taskDatabase.saveTask(task); - } else { - - } - - - - - //TODO need to get the plants templates, or through the Growphase - // plant.getPlantTemplates - // CreateTaskWithTasktemplate - + /** + * Returns an Optional of {@link Crop} if the crop is the gardenplan + * + * @param cropId The date, when the plant is planted + * @throws IOException If the database cannot be accessed + */ + public Optional getCrop(Long cropId) throws IOException { + return gardenPlan.getCropById(cropId); } } From b1e4e51d68d5abf72773e41693e74af679687f30 Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Wed, 2 Nov 2022 13:08:23 +0100 Subject: [PATCH 08/11] #27 gardenplanmodelTest first version implemented --- .../gardenplan/Gardenplanmodel.java | 14 ++- .../zhaw/gartenverwaltung/io/GardenPlan.java | 4 +- .../gardenplan/GardenPlanModelTest.java | 109 ++++++++++++++++++ 3 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java diff --git a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java index 18e072b..5dfe5cd 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java @@ -3,7 +3,6 @@ package ch.zhaw.gartenverwaltung.gardenplan; import ch.zhaw.gartenverwaltung.io.GardenPlan; import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; import ch.zhaw.gartenverwaltung.io.JsonGardenPlan; -import ch.zhaw.gartenverwaltung.io.TaskDatabase; import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException; import ch.zhaw.gartenverwaltung.taskList.TaskListModel; import ch.zhaw.gartenverwaltung.types.Crop; @@ -12,9 +11,12 @@ import ch.zhaw.gartenverwaltung.types.Task; import java.io.IOException; import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; + /** * The Gardenplan model manages the crops in the gardenplan. */ @@ -31,6 +33,7 @@ public class Gardenplanmodel { public Gardenplanmodel(TaskListModel taskListModel) throws IOException { this.taskListModel = taskListModel; gardenPlan = new JsonGardenPlan(); + cropList = new ArrayList<>(); cropList = gardenPlan.getCrops(); } @@ -47,11 +50,10 @@ public class Gardenplanmodel { public void plantAsCrop(Plant plant, LocalDate plantingDate) throws IOException, HardinessZoneNotSetException, PlantNotFoundException { Crop crop = new Crop(plant.id(),plantingDate); //TODO Add Area to Plant - crop.withArea(0); - - cropList.add(crop); + //crop.withArea(0); gardenPlan.saveCrop(crop); taskListModel.planTasksForCrop(crop); + cropList = gardenPlan.getCrops(); } /** @@ -62,9 +64,9 @@ public class Gardenplanmodel { */ public void removeCrop(Crop crop) throws IOException { - cropList.remove(crop); gardenPlan.removeCrop(crop); taskListModel.removeTasksForCrop(crop); + cropList = gardenPlan.getCrops(); } /** * Returns a list of {@link Crop}s which are currently in the gardenplan. @@ -72,7 +74,7 @@ public class Gardenplanmodel { * @throws IOException If the database cannot be accessed */ public List getCrops() throws IOException { - if(cropList.isEmpty()){ + if(!cropList.isEmpty()){ cropList = gardenPlan.getCrops(); } return cropList; diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/GardenPlan.java b/src/main/java/ch/zhaw/gartenverwaltung/io/GardenPlan.java index 0e04f9a..38d0598 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/GardenPlan.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/GardenPlan.java @@ -18,11 +18,11 @@ public interface GardenPlan { /** * Attempts to retrieve the {@link Crop} with the specified cropId. * - * @param id The {@link Crop#cropId} to look for + * @param cropId The {@link Crop} to look for * @return {@link Optional} of the found {@link Crop}, {@link Optional#empty()} if no entry matched the criteria * @throws IOException If there is a problem reading from or writing to the database */ - Optional getCropById(long id) throws IOException; + Optional getCropById(long cropId) throws IOException; /** * Saves a Crop to the Database. diff --git a/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java b/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java new file mode 100644 index 0000000..1f951ea --- /dev/null +++ b/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java @@ -0,0 +1,109 @@ +package ch.zhaw.gartenverwaltung.gardenplan; + +import ch.zhaw.gartenverwaltung.io.*; +import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException; +import ch.zhaw.gartenverwaltung.taskList.TaskListModel; +import ch.zhaw.gartenverwaltung.types.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.internal.stubbing.answers.DoesNothing; + +import java.io.IOException; +import java.time.LocalDate; +import java.time.MonthDay; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.*; + +public class GardenPlanModelTest { + GardenPlan gardenPlan; + List cropList; + Crop exampleCropOnion; + Crop exampleCropCarrot; + Crop exampleCrop1; + Crop exampleCrop2; + Crop exampleCrop3; + Plant examplePlantOnion; + Plant examplePlantCarrot; + Gardenplanmodel model; + + @BeforeEach + void setUp() throws IOException { + examplePlantOnion = new Plant( + 0, + "summertime onion", + "Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.", + null, + "15,30,2", + 0, + "sandy to loamy, loose soil, free of stones", + new ArrayList<>(), + List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()), + new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()), + new GrowthPhase(MonthDay.of(8, 5), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()), + new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()), + new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()))); + + exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.now()); + exampleCropOnion.withId(13); + examplePlantCarrot = new Plant( + 1, + "Early Carrot", + "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.", + null, + "5,35,2.5", + 0, + "sandy to loamy, loose soil, free of stones", + new ArrayList<>(), + List.of(new GrowthPhase(MonthDay.of(4, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()))); + exampleCropCarrot = new Crop(examplePlantCarrot.id(), LocalDate.now()); + exampleCropCarrot.withId(5); + + exampleCrop1 = new Crop(1, LocalDate.of(2023,2,25)); + exampleCrop1.withId(0); + exampleCrop1.withArea(0.5); + exampleCrop2 = new Crop(1,LocalDate.of(2023,3,1)); + exampleCrop2.withId(1); + exampleCrop2.withArea(0.5); + exampleCrop3 = new Crop(0,LocalDate.of(2023,3,25)); + exampleCrop3.withId(2); + exampleCrop3.withArea(1.5); + + cropList = new ArrayList<>(); + cropList.add(exampleCrop1); + cropList.add(exampleCrop2); + cropList.add(exampleCrop3); + gardenPlan = mockGardenPlan(cropList); + + TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase()); + model = new Gardenplanmodel(taskListModel); + } + + GardenPlan mockGardenPlan(List cropList) throws IOException { + GardenPlan gardenPlan = mock(GardenPlan.class); + when(gardenPlan.getCrops()).thenReturn(cropList); + when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot)); + when(gardenPlan.getCropById(13)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion)); + return gardenPlan; + } + + @Test + void plantAsCrop() throws HardinessZoneNotSetException, IOException, PlantNotFoundException { + + model.plantAsCrop(examplePlantOnion, LocalDate.of(2023,3,1)); + assertTrue(model.getCrops().contains(exampleCropOnion)); + } + + @Test + void removeCrop() throws IOException { + exampleCrop1.withId(2); + exampleCrop1.withArea(1.500000); + model.removeCrop(exampleCrop1); + assertEquals(2,model.getCrops().size()); + } +} From 2361afd5374726db451f672bd5f366ab8a92577c Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Fri, 4 Nov 2022 15:32:15 +0100 Subject: [PATCH 09/11] #27 gardenplanmodel bugfixed cropid --- .../zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java | 8 ++++---- .../ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java | 3 +++ src/main/java/ch/zhaw/gartenverwaltung/types/Task.java | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java index 5dfe5cd..00ebd44 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/gardenplan/Gardenplanmodel.java @@ -12,9 +12,9 @@ import ch.zhaw.gartenverwaltung.types.Task; import java.io.IOException; import java.time.LocalDate; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.function.Supplier; /** @@ -24,6 +24,7 @@ public class Gardenplanmodel { private GardenPlan gardenPlan; private List cropList; private TaskListModel taskListModel; + private Object IllegalArgumentException; /** * Constructor of Gardenplan model @@ -48,7 +49,7 @@ public class Gardenplanmodel { * @throws PlantNotFoundException If the plant is not found in the database. */ public void plantAsCrop(Plant plant, LocalDate plantingDate) throws IOException, HardinessZoneNotSetException, PlantNotFoundException { - Crop crop = new Crop(plant.id(),plantingDate); + Crop crop = new Crop(plant.id(), plantingDate); //TODO Add Area to Plant //crop.withArea(0); gardenPlan.saveCrop(crop); @@ -63,9 +64,8 @@ public class Gardenplanmodel { * @throws IOException If the database cannot be accessed */ public void removeCrop(Crop crop) throws IOException { - gardenPlan.removeCrop(crop); - taskListModel.removeTasksForCrop(crop); + taskListModel.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new)); cropList = gardenPlan.getCrops(); } /** diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index 7c9f6b0..be0d2ab 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java @@ -159,5 +159,8 @@ public class JsonTaskDatabase implements TaskDatabase{ (res, task) -> res.put(task.getId(), task), (existing, replacement) -> {}); } + + Long maxId = taskMap.isEmpty() ? 0L : Collections.max(taskMap.keySet()); + idProvider = new IdProvider(maxId); } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index 02d6480..545864d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -21,11 +21,11 @@ public class Task { * default constructor * (used by Json deserializer) */ - public Task(long cropId){ + public Task(){ name= ""; description= ""; startDate = LocalDate.now(); - this.cropId = cropId; + // this.cropId = cropId; } public Task(String name, String description, LocalDate startDate, long cropId) { From e91773b360b98b956d6077c01ffd24004096e2df Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Fri, 4 Nov 2022 15:35:45 +0100 Subject: [PATCH 10/11] #27 gardenplanmodelTest bugfixed --- .../ch/zhaw/gartenverwaltung/io/taskdb.json | 12 +- .../gardenplan/GardenPlanModelTest.java | 27 +- .../plantdb.json | 257 ++++++++++++++++++ .../taskdb.json | 56 ++++ .../ch/zhaw/gartenverwaltung/io/plantdb.json | 257 ++++++++++++++++++ .../ch/zhaw/gartenverwaltung/io/taskdb.json | 50 ---- 6 files changed, 594 insertions(+), 65 deletions(-) create mode 100644 src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/plantdb.json create mode 100644 src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/taskdb.json create mode 100644 src/test/resources/ch/zhaw/gartenverwaltung/io/plantdb.json delete mode 100644 src/test/resources/ch/zhaw/gartenverwaltung/io/taskdb.json diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json index b3514b0..ff69563 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json @@ -6,7 +6,7 @@ "startDate" : "2022-05-01", "endDate" : "2022-05-01", "interval" : 0, - "cropID" : 0 + "cropId" : 0 }, { "id" : 2, @@ -15,7 +15,7 @@ "startDate" : "2022-05-01", "endDate" : "2022-09-01", "interval" : 2, - "cropID" : 0 + "cropId" : 0 }, { "id" : 3, @@ -24,7 +24,7 @@ "startDate" : "2022-06-01", "endDate" : "2022-08-01", "interval" : 28, - "cropID" : 0 + "cropId" : 0 }, { "id" : 4, @@ -33,7 +33,7 @@ "startDate" : "2022-07-01", "endDate" : "2022-07-01", "interval" : 0, - "cropID" : 0 + "cropId" : 0 }, { "id" : 5, @@ -42,7 +42,7 @@ "startDate" : "2022-05-01", "endDate" : "2022-09-01", "interval" : 5, - "cropID" : 0 + "cropId" : 0 }, { "id" : 6, @@ -51,6 +51,6 @@ "startDate" : "2022-09-01", "endDate" : "2022-09-01", "interval" : 0, - "cropID" : 0 + "cropId" : 0 } ] \ No newline at end of file diff --git a/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java b/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java index 1f951ea..6b30ce9 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java @@ -6,15 +6,15 @@ import ch.zhaw.gartenverwaltung.taskList.TaskListModel; import ch.zhaw.gartenverwaltung.types.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.internal.stubbing.answers.DoesNothing; +import java.io.File; import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; import java.time.LocalDate; import java.time.MonthDay; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -34,6 +34,8 @@ public class GardenPlanModelTest { @BeforeEach void setUp() throws IOException { + + examplePlantOnion = new Plant( 0, "summertime onion", @@ -49,8 +51,8 @@ public class GardenPlanModelTest { new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()), new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()))); - exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.now()); - exampleCropOnion.withId(13); + exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.of(2023,3,1)); + exampleCropOnion.withId(3); examplePlantCarrot = new Plant( 1, "Early Carrot", @@ -70,9 +72,9 @@ public class GardenPlanModelTest { exampleCrop2 = new Crop(1,LocalDate.of(2023,3,1)); exampleCrop2.withId(1); exampleCrop2.withArea(0.5); - exampleCrop3 = new Crop(0,LocalDate.of(2023,3,25)); + exampleCrop3 = new Crop(0,LocalDate.of(2023,3,01)); exampleCrop3.withId(2); - exampleCrop3.withArea(1.5); + exampleCrop3.withArea(1.0); cropList = new ArrayList<>(); cropList.add(exampleCrop1); @@ -82,13 +84,18 @@ public class GardenPlanModelTest { TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase()); model = new Gardenplanmodel(taskListModel); + +// final URL dataSource = getClass().getClassLoader().getResource("taskdb.json"); +// File src = new File(String.valueOf(getClass().getResource("originalDB/taskdb.json"))); +// File dest = new File(String.valueOf(getClass().getClassLoader().getResource("originalDB/taskdb.json"))); +// Files.copy(src.toPath(), dest.getParentFile().toPath()); } GardenPlan mockGardenPlan(List cropList) throws IOException { GardenPlan gardenPlan = mock(GardenPlan.class); when(gardenPlan.getCrops()).thenReturn(cropList); when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot)); - when(gardenPlan.getCropById(13)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion)); + when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion)); return gardenPlan; } @@ -96,7 +103,9 @@ public class GardenPlanModelTest { void plantAsCrop() throws HardinessZoneNotSetException, IOException, PlantNotFoundException { model.plantAsCrop(examplePlantOnion, LocalDate.of(2023,3,1)); - assertTrue(model.getCrops().contains(exampleCropOnion)); + exampleCropOnion = model.getCrop(2L).get(); + assertEquals(model.getCrops().get(2),exampleCropOnion); + } @Test diff --git a/src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/plantdb.json b/src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/plantdb.json new file mode 100644 index 0000000..5a23d09 --- /dev/null +++ b/src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/plantdb.json @@ -0,0 +1,257 @@ +[ + { + "id": 0, + "name": "Potato", + "description": "The potato is a tuber, round or oval, with small white roots called 'eyes', that are growth buds. The size varies depending on the variety; the colour of the skin can be white, yellow or even purple.", + "light": 6, + "spacing": "35", + "soil": "sandy", + "image": "potato.jpg", + "pests": [ + { + "name": "Rot", + "description": "Rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "Less water." + } + ], + "lifecycle": [ + { + "startDate": "03-10", + "endDate": "04-10", + "type": "SOW", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Germinate", + "relativeStartDate": -14, + "relativeEndDate": null, + "description": "\"Take an egg carton and fill it with soil. Put the seedling deep enaugh so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.\"", + "interval": null, + "isOptional": false + } + ] + }, + { + "startDate": "04-10", + "endDate": "07-10", + "type": "PLANT", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 25, + "interval": 7, + "notes": [] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "\"When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.\"", + "interval": 21, + "isOptional": false + } + ] + }, + { + "startDate": "06-10", + "endDate": "08-10", + "type": "HARVEST", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Harvest", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", + "interval": null, + "isOptional": false + } + ] + } + ] + }, + { + "id": 1, + "name": "Early Carrot", + "description": "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.", + "image": "carrot.jpg", + "lifecycle": [ + { + "startDate": "02-20", + "endDate": "03-10", + "zone": "ZONE_8A", + "type": "SOW", + "wateringCycle": { + "litersPerSqM": 15, + "interval": 3, + "notes": [] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": 0, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": null, + "isOptional": false + } + ] + }, + { + "startDate": "03-10", + "endDate": "05-10", + "zone": "ZONE_8A", + "type": "PLANT", + "wateringCycle": { + "litersPerSqM": 25, + "interval": 3, + "notes": [ + "Be careful not to pour water over the leaves, as this will lead to sunburn." + ] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": 15, + "isOptional": true + } + ] + }, + { + "startDate": "05-10", + "endDate": "05-20", + "zone": "ZONE_8A", + "type": "HARVEST", + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Harvesting", + "relativeStartDate": 0, + "relativeEndDate": 14, + "description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.", + "interval": null, + "isOptional": false + } + ] + } + ], + "soil": "sandy to loamy, loose soil, free of stones", + "spacing": "5,35,2.5", + "pests": [ + { + "name": "Rot", + "description": "rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "less water" + } + ] + }, + { + "id": 2, + "name": "Summertime Onion", + "description": "Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.", + "image": "onion.jpg", + "lifecycle": [ + { + "startDate": "03-15", + "endDate": "04-10", + "type": "SOW", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 15, + "interval": 4, + "notes": [ + + ] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": 0, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": null, + "isOptional": false + } + ] + }, + { + "startDate": "04-10", + "endDate": "07-10", + "type": "PLANT", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 25, + "interval": 3, + "notes": [ + "" + ] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": 15, + "isOptional": true + } + ] + }, + { + "startDate": "07-10", + "endDate": "09-20", + "type": "HARVEST", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [ + + ] + }, + "taskTemplates": [ + { + "name": "Harvesting", + "relativeStartDate": 0, + "relativeEndDate": 14, + "description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter", + "interval": null, + "isOptional": false + } + ] + } + ], + "soil": "sandy to loamy, loose soil, free of stones", + "spacing": "15,30,2", + "pests": [ + { + "name": "Rot", + "description": "rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "less water" + } + ] + } +] diff --git a/src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/taskdb.json b/src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/taskdb.json new file mode 100644 index 0000000..b3514b0 --- /dev/null +++ b/src/test/resources/ch.zhaw.gartenverwaltung.gardenplan/taskdb.json @@ -0,0 +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, + "cropID" : 0 + }, + { + "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, + "cropID" : 0 + }, + { + "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, + "cropID" : 0 + }, + { + "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, + "cropID" : 0 + }, + { + "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, + "cropID" : 0 + }, + { + "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, + "cropID" : 0 + } +] \ No newline at end of file diff --git a/src/test/resources/ch/zhaw/gartenverwaltung/io/plantdb.json b/src/test/resources/ch/zhaw/gartenverwaltung/io/plantdb.json new file mode 100644 index 0000000..5a23d09 --- /dev/null +++ b/src/test/resources/ch/zhaw/gartenverwaltung/io/plantdb.json @@ -0,0 +1,257 @@ +[ + { + "id": 0, + "name": "Potato", + "description": "The potato is a tuber, round or oval, with small white roots called 'eyes', that are growth buds. The size varies depending on the variety; the colour of the skin can be white, yellow or even purple.", + "light": 6, + "spacing": "35", + "soil": "sandy", + "image": "potato.jpg", + "pests": [ + { + "name": "Rot", + "description": "Rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "Less water." + } + ], + "lifecycle": [ + { + "startDate": "03-10", + "endDate": "04-10", + "type": "SOW", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Germinate", + "relativeStartDate": -14, + "relativeEndDate": null, + "description": "\"Take an egg carton and fill it with soil. Put the seedling deep enaugh so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.\"", + "interval": null, + "isOptional": false + } + ] + }, + { + "startDate": "04-10", + "endDate": "07-10", + "type": "PLANT", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 25, + "interval": 7, + "notes": [] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "\"When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.\"", + "interval": 21, + "isOptional": false + } + ] + }, + { + "startDate": "06-10", + "endDate": "08-10", + "type": "HARVEST", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Harvest", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", + "interval": null, + "isOptional": false + } + ] + } + ] + }, + { + "id": 1, + "name": "Early Carrot", + "description": "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.", + "image": "carrot.jpg", + "lifecycle": [ + { + "startDate": "02-20", + "endDate": "03-10", + "zone": "ZONE_8A", + "type": "SOW", + "wateringCycle": { + "litersPerSqM": 15, + "interval": 3, + "notes": [] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": 0, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": null, + "isOptional": false + } + ] + }, + { + "startDate": "03-10", + "endDate": "05-10", + "zone": "ZONE_8A", + "type": "PLANT", + "wateringCycle": { + "litersPerSqM": 25, + "interval": 3, + "notes": [ + "Be careful not to pour water over the leaves, as this will lead to sunburn." + ] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": 15, + "isOptional": true + } + ] + }, + { + "startDate": "05-10", + "endDate": "05-20", + "zone": "ZONE_8A", + "type": "HARVEST", + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Harvesting", + "relativeStartDate": 0, + "relativeEndDate": 14, + "description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.", + "interval": null, + "isOptional": false + } + ] + } + ], + "soil": "sandy to loamy, loose soil, free of stones", + "spacing": "5,35,2.5", + "pests": [ + { + "name": "Rot", + "description": "rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "less water" + } + ] + }, + { + "id": 2, + "name": "Summertime Onion", + "description": "Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.", + "image": "onion.jpg", + "lifecycle": [ + { + "startDate": "03-15", + "endDate": "04-10", + "type": "SOW", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 15, + "interval": 4, + "notes": [ + + ] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": 0, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": null, + "isOptional": false + } + ] + }, + { + "startDate": "04-10", + "endDate": "07-10", + "type": "PLANT", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 25, + "interval": 3, + "notes": [ + "" + ] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": null, + "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", + "interval": 15, + "isOptional": true + } + ] + }, + { + "startDate": "07-10", + "endDate": "09-20", + "type": "HARVEST", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [ + + ] + }, + "taskTemplates": [ + { + "name": "Harvesting", + "relativeStartDate": 0, + "relativeEndDate": 14, + "description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter", + "interval": null, + "isOptional": false + } + ] + } + ], + "soil": "sandy to loamy, loose soil, free of stones", + "spacing": "15,30,2", + "pests": [ + { + "name": "Rot", + "description": "rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "less water" + } + ] + } +] diff --git a/src/test/resources/ch/zhaw/gartenverwaltung/io/taskdb.json b/src/test/resources/ch/zhaw/gartenverwaltung/io/taskdb.json deleted file mode 100644 index 1155b9a..0000000 --- a/src/test/resources/ch/zhaw/gartenverwaltung/io/taskdb.json +++ /dev/null @@ -1,50 +0,0 @@ -[ - { - "id" : "1", - "name" : "sow plant", - "description": "Plant the seeds/ crops in de bed.", - "startDate" : "01.05.2022", - "endDate" : "01.05.2022", - "interval" : "null" - }, - { - "id" : "2", - "name" : "water plant", - "description": "water the plant, so that the soil is wet around the plant.", - "startDate" : "01.05.2022", - "endDate" : "01.09.2022", - "interval" : "2" - }, - { - "id" : "3", - "name" : "fertilize plant", - "description": "The fertilizer has to be mixed with water. Then fertilize the plant's soil with the mixture", - "startDate" : "01.06.2022", - "endDate" : "01.08.2022", - "interval" : "28" - }, - { - "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" : "15.07.2022", - "endDate" : "15.07.2022", - "interval" : "null" - }, - { - "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" : "01.05.2022", - "endDate" : "01.09.2022", - "interval" : "5" - }, - { - "id" : "6", - "name" : "harvest plant", - "description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ", - "startDate" : "01.09.2022", - "endDate" : "01.09.2022", - "interval" : "null" - } -] \ No newline at end of file From 8408af175d9e965d2257e9259de5bdf12f5e5e40 Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Fri, 4 Nov 2022 15:46:11 +0100 Subject: [PATCH 11/11] #27 gardenplanmodelTest bugfixed --- .../gartenverwaltung/gardenplan/GardenPlanModelTest.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java b/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java index 6b30ce9..16ece04 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/gardenplan/GardenPlanModelTest.java @@ -84,11 +84,6 @@ public class GardenPlanModelTest { TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase()); model = new Gardenplanmodel(taskListModel); - -// final URL dataSource = getClass().getClassLoader().getResource("taskdb.json"); -// File src = new File(String.valueOf(getClass().getResource("originalDB/taskdb.json"))); -// File dest = new File(String.valueOf(getClass().getClassLoader().getResource("originalDB/taskdb.json"))); -// Files.copy(src.toPath(), dest.getParentFile().toPath()); } GardenPlan mockGardenPlan(List cropList) throws IOException {