#27 first implemention of the Gardenplanmodel

This commit is contained in:
Gian-Andrea Hutter 2022-10-30 23:34:42 +01:00
parent 8120071348
commit 63d7eddff4
1 changed files with 87 additions and 1 deletions

View File

@ -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<Crop> 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<Crop> getCrops(){
if(cropList.isEmpty()){
try {
cropList = gardenplan.getCrops();
} catch (IOException ioException){
System.err.println("Crops could not be loaded");
}
}
return cropList;
}
public Optional<Crop> 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