parent
d1d9d11b66
commit
0e4e207581
|
@ -0,0 +1,19 @@
|
||||||
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
private static HardinessZone currentHardinessZone;
|
||||||
|
|
||||||
|
static {
|
||||||
|
currentHardinessZone = HardinessZone.ZONE_8A;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HardinessZone getCurrentHardinessZone() {
|
||||||
|
return currentHardinessZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
|
||||||
|
Config.currentHardinessZone = currentHardinessZone;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,16 @@
|
||||||
package ch.zhaw.gartenverwaltung.taskList;
|
package ch.zhaw.gartenverwaltung.taskList;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.Config;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase;
|
import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.io.TaskDatabase;
|
import ch.zhaw.gartenverwaltung.io.TaskDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.*;
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TaskListModel {
|
public class TaskListModel {
|
||||||
|
@ -36,14 +33,15 @@ public class TaskListModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
||||||
Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
Plant plant = plantDatabase.getPlantById(Config.getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||||
// TODO new exception
|
for (GrowthPhase growthPhase : plant.lifecycle()) {
|
||||||
// TODO HArdiness Zone
|
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
|
||||||
return;
|
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTasksForCrop(Crop crop) {
|
public void removeTasksForCrop(Crop crop) {
|
||||||
//TODO implement
|
|
||||||
taskDatabase.removeTasksForCrop(crop);
|
taskDatabase.removeTasksForCrop(crop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,22 +15,24 @@ public class Task {
|
||||||
private final LocalDate startDate;
|
private final LocalDate startDate;
|
||||||
private Integer interval;
|
private Integer interval;
|
||||||
private LocalDate endDate;
|
private LocalDate endDate;
|
||||||
private Crop cropId;
|
private long cropId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
* (used by Json deserializer)
|
* (used by Json deserializer)
|
||||||
*/
|
*/
|
||||||
public Task(){
|
public Task(long cropId){
|
||||||
name= "";
|
name= "";
|
||||||
description= "";
|
description= "";
|
||||||
startDate = LocalDate.now();
|
startDate = LocalDate.now();
|
||||||
|
this.cropId = cropId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task(String name, String description, LocalDate startDate) {
|
public Task(String name, String description, LocalDate startDate, long cropId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
|
this.cropId = cropId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval) {
|
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval) {
|
||||||
|
@ -56,10 +58,7 @@ public class Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
||||||
if(startDate.isAfter(searchStartDate) &&startDate.isBefore(searchEndDate)){
|
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class TaskTemplate {
|
||||||
this.relativeStartDate = relativeStartDate;
|
this.relativeStartDate = relativeStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task generateTask(LocalDate realStartDate) {
|
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||||
Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate));
|
Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId);
|
||||||
if (relativeEndDate != null) {
|
if (relativeEndDate != null) {
|
||||||
task.withEndDate(realStartDate.plusDays(relativeEndDate));
|
task.withEndDate(realStartDate.plusDays(relativeEndDate));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue