#27 first implemention of the Gardenplanmodel
This commit is contained in:
parent
8120071348
commit
63d7eddff4
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue