#27 gardenplanmodelTest first version implemented

This commit is contained in:
Gian-Andrea Hutter
2022-11-02 13:08:23 +01:00
parent 9e14920fbb
commit b1e4e51d68
3 changed files with 119 additions and 8 deletions
@@ -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<Crop> getCrops() throws IOException {
if(cropList.isEmpty()){
if(!cropList.isEmpty()){
cropList = gardenPlan.getCrops();
}
return cropList;
@@ -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<Crop> getCropById(long id) throws IOException;
Optional<Crop> getCropById(long cropId) throws IOException;
/**
* Saves a Crop to the Database.