From 63d7eddff46bb39599346133bf5783bfbe017d1c Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Sun, 30 Oct 2022 23:34:42 +0100 Subject: [PATCH] #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