Merge remote-tracking branch 'origin/feature_taskList_m2' into feature_gardenplan-model_M2

# Conflicts:
#	src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json
This commit is contained in:
Gian-Andrea Hutter 2022-10-31 14:32:33 +01:00
commit 0987b42086
6 changed files with 70 additions and 34 deletions

View File

@ -1,5 +1,6 @@
package ch.zhaw.gartenverwaltung.io; package ch.zhaw.gartenverwaltung.io;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Task; import ch.zhaw.gartenverwaltung.types.Task;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
@ -57,6 +58,16 @@ public class JsonTaskDatabase implements TaskDatabase{
return taskMap.values().stream().filter(task -> task.isInTimePeriode(start, end)).toList(); return taskMap.values().stream().filter(task -> task.isInTimePeriode(start, end)).toList();
} }
@Override
public List<Task> getTaskForCrop(Crop crop) {
return null; //TODO implement
}
@Override
public void removeTasksForCrop(Crop crop) {
// TODO implement
}
/** /**
* If no data is currently loaded, data is loaded from {@link #dataSource}. * If no data is currently loaded, data is loaded from {@link #dataSource}.
* If the {@link Task} has an id than the task is added to the {@link #taskMap} * If the {@link Task} has an id than the task is added to the {@link #taskMap}

View File

@ -1,5 +1,6 @@
package ch.zhaw.gartenverwaltung.io; package ch.zhaw.gartenverwaltung.io;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.HardinessZone; import ch.zhaw.gartenverwaltung.types.HardinessZone;
import ch.zhaw.gartenverwaltung.types.Plant; import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Task; import ch.zhaw.gartenverwaltung.types.Task;
@ -24,6 +25,10 @@ public interface TaskDatabase {
*/ */
List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException; List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException;
List<Task> getTaskForCrop(Crop crop); //TODO Javadoc
void removeTasksForCrop(Crop crop); // TODO Javadoc
/** /**
* Saves the {@link Task} in the Cache. * Saves the {@link Task} in the Cache.
* *

View File

@ -0,0 +1,7 @@
package ch.zhaw.gartenverwaltung.taskList;
public class PlantNotFoundException extends Exception {
public PlantNotFoundException() {
super("The selected Plant was not found in Database!");
}
}

View File

@ -13,6 +13,7 @@ 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 {
@ -34,13 +35,18 @@ public class TaskListModel {
taskDatabase.saveTask(task); taskDatabase.saveTask(task);
} }
public void planTasksForCrop(Crop crop) throws HardinessZoneNotSetException, IOException { public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow(); Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
// TODO new exception // TODO new exception
// TODO HArdiness Zone // TODO HArdiness Zone
return; return;
} }
public void removeTasksForCrop(Crop crop) {
//TODO implement
taskDatabase.removeTasksForCrop(crop);
}
public void removeTask(Task task) throws IOException { public void removeTask(Task task) throws IOException {
taskDatabase.removeTask(task); taskDatabase.removeTask(task);
} }

View File

@ -15,6 +15,7 @@ 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;
/** /**
* default constructor * default constructor

View File

@ -1,50 +1,56 @@
[ [
{ {
"id": 1, "id" : 1,
"name": "sow plant", "name" : "sow plant",
"description": "Plant the seeds, crops in de bed.", "description": "Plant the seeds, crops in de bed.",
"startDate": "2022-05-01", "startDate" : "2022-05-01",
"endDate": "2022-05-01", "endDate" : "2022-05-01",
"interval": 0 "interval" : 0,
"cropID" : 0
}, },
{ {
"id": 2, "id" : 2,
"name": "water plant", "name" : "water plant",
"description": "water the plant, so that the soil is wet around the plant.", "description": "water the plant, so that the soil is wet around the plant.",
"startDate": "2022-05-01", "startDate" : "2022-05-01",
"endDate": "2022-09-01", "endDate" : "2022-09-01",
"interval": 2 "interval" : 2,
"cropID" : 0
}, },
{ {
"id": 3, "id" : 3,
"name": "fertilize plant", "name" : "fertilize plant",
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture", "description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
"startDate": "2022-06-01", "startDate" : "2022-06-01",
"endDate": "2022-08-01", "endDate" : "2022-08-01",
"interval": 28 "interval" : 28,
"cropID" : 0
}, },
{ {
"id": 4, "id" : 4,
"name": "covering plant", "name" : "covering plant",
"description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage", "description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage",
"startDate": "2022-07-01", "startDate" : "2022-07-01",
"endDate": "2022-07-01", "endDate" : "2022-07-01",
"interval": 0 "interval" : 0,
"cropID" : 0
}, },
{ {
"id": 5, "id" : 5,
"name": "look after plant", "name" : "look after plant",
"description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil", "description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil",
"startDate": "2022-05-01", "startDate" : "2022-05-01",
"endDate": "2022-09-01", "endDate" : "2022-09-01",
"interval": 5 "interval" : 5,
"cropID" : 0
}, },
{ {
"id": 6, "id" : 6,
"name": "harvest plant", "name" : "harvest plant",
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ", "description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
"startDate": "2022-09-01", "startDate" : "2022-09-01",
"endDate": "2022-09-01", "endDate" : "2022-09-01",
"interval": 0 "interval" : 0,
"cropID" : 0
} }
] ]