Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d24687f7b | ||
|
|
2ec37114de | ||
|
|
aedcfe2be9 | ||
|
|
b3f839e4a3 |
@@ -87,7 +87,7 @@ public class CropDetailController {
|
|||||||
private ListView<Pest> pests_listView;
|
private ListView<Pest> pests_listView;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void addTask() throws IOException {
|
void addTask() throws IOException, HardinessZoneNotSetException {
|
||||||
createTaskDialog(true, null);
|
createTaskDialog(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ public class CropDetailController {
|
|||||||
if (plant.image() != null) {
|
if (plant.image() != null) {
|
||||||
imageView.setImage(plant.image());
|
imageView.setImage(plant.image());
|
||||||
}
|
}
|
||||||
area_label.setText("");
|
area_label.setText(String.valueOf(crop.getArea()));
|
||||||
location_label.setText("");
|
location_label.setText("");
|
||||||
|
|
||||||
setTaskListProperty(crop);
|
setTaskListProperty(crop);
|
||||||
@@ -255,7 +255,7 @@ public class CropDetailController {
|
|||||||
return (event) -> {
|
return (event) -> {
|
||||||
try {
|
try {
|
||||||
createTaskDialog(false, task);
|
createTaskDialog(false, task);
|
||||||
} catch (IOException e) {
|
} catch (IOException | HardinessZoneNotSetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -267,7 +267,7 @@ public class CropDetailController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
|
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException, HardinessZoneNotSetException {
|
||||||
Dialog<Task> dialog = new Dialog<>();
|
Dialog<Task> dialog = new Dialog<>();
|
||||||
dialog.setTitle("Set Task");
|
dialog.setTitle("Set Task");
|
||||||
dialog.setHeaderText("Add/Edit Task:");
|
dialog.setHeaderText("Add/Edit Task:");
|
||||||
@@ -289,7 +289,7 @@ public class CropDetailController {
|
|||||||
if (!newTask) {
|
if (!newTask) {
|
||||||
controller.setTaskValue(givenTask);
|
controller.setTaskValue(givenTask);
|
||||||
}
|
}
|
||||||
dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult() : null);
|
dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult(this.crop) : null);
|
||||||
|
|
||||||
dialog.showAndWait()
|
dialog.showAndWait()
|
||||||
.ifPresent(task -> {
|
.ifPresent(task -> {
|
||||||
@@ -334,8 +334,11 @@ public class CropDetailController {
|
|||||||
//ToDo method to set location
|
//ToDo method to set location
|
||||||
location_label.setText(string);
|
location_label.setText(string);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(string);
|
try {
|
||||||
//ToDo method to set area of crop in garden
|
garden.updateCrop(this.crop.withArea(Double.parseDouble(string)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
area_label.setText(string);
|
area_label.setText(string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public class MyGardenController {
|
|||||||
@AfterInject
|
@AfterInject
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void init() {
|
public void init() {
|
||||||
System.out.println("once");
|
|
||||||
setIconToButton(addPlant_button, "addIcon.png");
|
setIconToButton(addPlant_button, "addIcon.png");
|
||||||
myGarden_listView.itemsProperty().bind(garden.getPlantedCrops());
|
myGarden_listView.itemsProperty().bind(garden.getPlantedCrops());
|
||||||
setCellFactory();
|
setCellFactory();
|
||||||
|
|||||||
@@ -233,11 +233,11 @@ public class PlantsController {
|
|||||||
RadioButton radioButton = new RadioButton(season.getName());
|
RadioButton radioButton = new RadioButton(season.getName());
|
||||||
radioButton.setToggleGroup(seasonGroup);
|
radioButton.setToggleGroup(seasonGroup);
|
||||||
radioButton.setPadding(new Insets(0, 0, 10, 0));
|
radioButton.setPadding(new Insets(0, 0, 10, 0));
|
||||||
if (season.equals(Seasons.ALLSEASONS)) {
|
if (season.equals(Seasons.AllSEASONS)) {
|
||||||
radioButton.setSelected(true);
|
radioButton.setSelected(true);
|
||||||
}
|
}
|
||||||
radioButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
radioButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (season.equals(Seasons.ALLSEASONS)) {
|
if (season.equals(Seasons.AllSEASONS)) {
|
||||||
fillPlantListWithHardinessZone();
|
fillPlantListWithHardinessZone();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
||||||
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
|
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||||
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||||
|
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import javafx.beans.binding.Binding;
|
|
||||||
import javafx.beans.binding.Bindings;
|
|
||||||
import javafx.beans.binding.BooleanBinding;
|
|
||||||
import javafx.beans.value.ChangeListener;
|
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class TaskFormularController implements Initializable {
|
public class TaskFormularController implements Initializable {
|
||||||
private Crop crop;
|
private Crop crop;
|
||||||
|
private Plant plant;
|
||||||
|
private Task task = null;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GardenSchedule gardenSchedule;
|
||||||
|
@Inject
|
||||||
|
private Garden garden;
|
||||||
|
@Inject
|
||||||
|
private PlantList plantList;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea description_area;
|
private TextArea description_area;
|
||||||
@@ -34,19 +46,28 @@ public class TaskFormularController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private TextField taskName_field;
|
private TextField taskName_field;
|
||||||
|
|
||||||
|
@AfterInject
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
|
||||||
public Task returnResult() {
|
public Task returnResult(Crop crop) {
|
||||||
|
int interval = 0;
|
||||||
|
if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) {
|
||||||
|
interval = Integer.parseInt(interval_field.getText());
|
||||||
|
}
|
||||||
Task task = new Task(taskName_field.getText(), description_area.getText(),
|
Task task = new Task(taskName_field.getText(), description_area.getText(),
|
||||||
start_datePicker.getValue(), end_datePicker.getValue(),
|
start_datePicker.getValue(), end_datePicker.getValue(),
|
||||||
Integer.parseInt(interval_field.getText()), crop.getCropId().get());
|
interval, crop.getCropId().get());
|
||||||
|
if (this.task != null) return this.task.updateTask(task);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCorp(Crop crop) {
|
public void setCorp(Crop crop) throws HardinessZoneNotSetException, IOException {
|
||||||
this.crop = crop;
|
this.crop = crop;
|
||||||
|
this.plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTaskValue(Task task) {
|
public void setTaskValue(Task task) {
|
||||||
|
this.task = task;
|
||||||
taskName_field.setText(task.getName());
|
taskName_field.setText(task.getName());
|
||||||
description_area.setText(task.getDescription());
|
description_area.setText(task.getDescription());
|
||||||
start_datePicker.setValue(task.getStartDate());
|
start_datePicker.setValue(task.getStartDate());
|
||||||
@@ -69,7 +90,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
setDisable(true);
|
setDisable(true);
|
||||||
setStyle("-fx-background-color: #ffc0cb;");
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
|
||||||
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) {
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
@@ -93,7 +114,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
setDisable(true);
|
setDisable(true);
|
||||||
setStyle("-fx-background-color: #ffc0cb;");
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
|
||||||
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) {
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
@@ -114,12 +135,8 @@ public class TaskFormularController implements Initializable {
|
|||||||
});
|
});
|
||||||
|
|
||||||
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
||||||
.or(end_datePicker.valueProperty().isNull())
|
|
||||||
.or(taskName_field.textProperty().isEmpty())
|
.or(taskName_field.textProperty().isEmpty())
|
||||||
.or(description_area.textProperty().isEmpty())
|
.or(description_area.textProperty().isEmpty()));
|
||||||
.or(interval_field.textProperty().isEmpty()));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ public class TextFieldFormularController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initSaveButton(Button button) {
|
public void initSaveButton(Button button) {
|
||||||
|
text_area.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue.matches("\\d*\\.?\\d*")) {
|
||||||
|
text_area.setText(newValue);
|
||||||
|
} else {
|
||||||
|
text_area.setText(oldValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ public class JsonTaskList implements TaskList {
|
|||||||
if(taskMap.isEmpty()) {
|
if(taskMap.isEmpty()) {
|
||||||
loadTaskListFromFile();
|
loadTaskListFromFile();
|
||||||
}
|
}
|
||||||
taskMap.entrySet().removeIf(entry -> entry.getValue().getCropId() == cropId);
|
taskMap.values().removeIf(task -> task.getCropId() == cropId);
|
||||||
writeTaskListToFile();
|
|
||||||
notifySubscribers();
|
notifySubscribers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,19 @@ public class Garden {
|
|||||||
plantedCrops.clear();
|
plantedCrops.clear();
|
||||||
plantedCrops.addAll(cropList.getCrops());
|
plantedCrops.addAll(cropList.getCrops());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the {@link Crop} from the file and the cache
|
||||||
|
*
|
||||||
|
* @param crop The crop which is being updated
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
*/
|
||||||
|
public void updateCrop(Crop crop) throws IOException {
|
||||||
|
cropList.saveCrop(crop);
|
||||||
|
plantedCrops.clear();
|
||||||
|
plantedCrops.addAll(cropList.getCrops());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -66,16 +66,16 @@ public record Plant(
|
|||||||
public int timeToHarvest(int group) {
|
public int timeToHarvest(int group) {
|
||||||
List<GrowthPhase> activeLifecycle = lifecycleForGroup(group);
|
List<GrowthPhase> activeLifecycle = lifecycleForGroup(group);
|
||||||
GrowthPhase sow = activeLifecycle.stream()
|
GrowthPhase sow = activeLifecycle.stream()
|
||||||
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.SOW))
|
.filter(growthPhase -> !growthPhase.type().equals(GrowthPhaseType.SOW))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
GrowthPhase harvest = activeLifecycle.stream()
|
GrowthPhase harvest = activeLifecycle.stream()
|
||||||
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.HARVEST))
|
.filter(growthPhase -> !growthPhase.type().equals(GrowthPhaseType.HARVEST))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
|
|
||||||
int currentYear = LocalDate.now().getYear();
|
int currentYear = LocalDate.now().getYear();
|
||||||
return (int) DAYS.between(sow.startDate().atYear(currentYear),harvest.startDate().atYear(currentYear));
|
return (int) DAYS.between(harvest.startDate().atYear(currentYear), sow.startDate().atYear(currentYear));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lifecycleGroupFromHarvestDate(LocalDate harvestDate) {
|
public int lifecycleGroupFromHarvestDate(LocalDate harvestDate) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package ch.zhaw.gartenverwaltung.types;
|
|||||||
import java.time.MonthDay;
|
import java.time.MonthDay;
|
||||||
|
|
||||||
public enum Seasons {
|
public enum Seasons {
|
||||||
ALLSEASONS("--01-01", "--12-31", "All Seasons"),
|
AllSEASONS("--01-01", "--12-31", "All Seasons"),
|
||||||
SPRING("--03-01", "--05-30", "Spring"),
|
SPRING("--03-01", "--05-30", "Spring"),
|
||||||
SUMMER("--06-01", "--08-30", "Summer"),
|
SUMMER("--06-01", "--08-30", "Summer"),
|
||||||
AUTUMN("--09-01", "--11-30", "Autumn"),
|
AUTUMN("--09-01", "--11-30", "Autumn"),
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public class Task {
|
public class Task {
|
||||||
private Long id;
|
private Long id;
|
||||||
private final String name;
|
private String name;
|
||||||
private final String description;
|
private String description;
|
||||||
private final LocalDate startDate;
|
private LocalDate startDate;
|
||||||
private Integer interval;
|
private Integer interval;
|
||||||
private LocalDate endDate;
|
private LocalDate endDate;
|
||||||
private LocalDate nextExecution;
|
private LocalDate nextExecution;
|
||||||
@@ -103,4 +103,14 @@ public class Task {
|
|||||||
public Optional<LocalDate> getEndDate() {
|
public Optional<LocalDate> getEndDate() {
|
||||||
return Optional.ofNullable(endDate);
|
return Optional.ofNullable(endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task updateTask(Task task) {
|
||||||
|
this.name = task.getName();
|
||||||
|
this.description = task.getDescription();
|
||||||
|
this.startDate = task.getStartDate();
|
||||||
|
this.endDate = task.getEndDate().orElse(null);
|
||||||
|
this.interval = task.getInterval().orElse(0);
|
||||||
|
this.cropId = task.getCropId();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class TaskTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Task generateTask(LocalDate realStartDate, long cropId) {
|
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
|
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate.plusDays(0);
|
||||||
|
|
||||||
if (interval == null) {
|
if (interval == null) {
|
||||||
this.interval = 0;
|
this.interval = 0;
|
||||||
|
|||||||
@@ -245,5 +245,86 @@
|
|||||||
"measures": "less water"
|
"measures": "less water"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Test Potato",
|
||||||
|
"description": "The potato is a tuber, round or oval, with small white roots called 'eyes', that are growth buds. The size varies depending on the variety; the colour of the skin can be white, yellow or even purple.",
|
||||||
|
"light": 6,
|
||||||
|
"spacing": "35",
|
||||||
|
"soil": "sandy",
|
||||||
|
"image": "potato.jpg",
|
||||||
|
"pests": [
|
||||||
|
{
|
||||||
|
"name": "Rot",
|
||||||
|
"description": "Rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.",
|
||||||
|
"measures": "Less water."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lifecycle": [
|
||||||
|
{
|
||||||
|
"startDate": "12-01",
|
||||||
|
"endDate": "12-02",
|
||||||
|
"type": "SOW",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"group": 0,
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 0,
|
||||||
|
"interval": null,
|
||||||
|
"notes": []
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "Germinate",
|
||||||
|
"relativeStartDate": -3,
|
||||||
|
"relativeEndDate": 0,
|
||||||
|
"description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.",
|
||||||
|
"interval": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startDate": "12-03",
|
||||||
|
"endDate": "12-15",
|
||||||
|
"type": "PLANT",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"group": 0,
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 25,
|
||||||
|
"interval": 7,
|
||||||
|
"notes": []
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "hilling",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": 10,
|
||||||
|
"description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.",
|
||||||
|
"interval": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startDate": "12-16",
|
||||||
|
"endDate": "12-18",
|
||||||
|
"type": "HARVEST",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"group": 0,
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 0,
|
||||||
|
"interval": null,
|
||||||
|
"notes": []
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "Harvest",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": 4,
|
||||||
|
"description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.",
|
||||||
|
"interval": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ public class JsonCropListTest {
|
|||||||
*/
|
*/
|
||||||
private final URL dbDataSource = this.getClass().getResource("test-user-crops.json");
|
private final URL dbDataSource = this.getClass().getResource("test-user-crops.json");
|
||||||
private final URL testFile = this.getClass().getResource("template-user-crops.json");
|
private final URL testFile = this.getClass().getResource("template-user-crops.json");
|
||||||
private final URL corruptTestFile = this.getClass().getResource("corrupt-template-user-crops.json");
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void connectToDb() throws URISyntaxException, IOException {
|
void connectToDb() throws URISyntaxException, IOException {
|
||||||
@@ -102,13 +101,5 @@ public class JsonCropListTest {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void detectCorruptJsonResource(){
|
|
||||||
JsonCropList tL = new JsonCropList(corruptTestFile);
|
|
||||||
Assertions.assertThrows(InvalidJsonException.class, () -> {
|
|
||||||
tL.getCrops();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
public class JsonPlantListTest {
|
public class JsonPlantListTest {
|
||||||
private final URL testFile = this.getClass().getResource("test-plantdb.json");
|
private final URL testFile = this.getClass().getResource("test-plantdb.json");
|
||||||
@@ -63,8 +62,6 @@ public class JsonPlantListTest {
|
|||||||
void getPlantByIdAndZone() {
|
void getPlantByIdAndZone() {
|
||||||
Optional<Plant> testPlant;
|
Optional<Plant> testPlant;
|
||||||
try {
|
try {
|
||||||
assertThrows(HardinessZoneNotSetException.class, () -> testDatabase.getPlantById(null,1).get());
|
|
||||||
|
|
||||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
||||||
} catch (IOException | HardinessZoneNotSetException e) {
|
} catch (IOException | HardinessZoneNotSetException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -98,16 +95,5 @@ public class JsonPlantListTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDefaultConstructor(){
|
|
||||||
JsonPlantList db = new JsonPlantList();
|
|
||||||
try {
|
|
||||||
assertNotNull(db.getPlantList(HardinessZone.ZONE_8A));
|
|
||||||
} catch (IOException | HardinessZoneNotSetException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package ch.zhaw.gartenverwaltung.io;
|
|||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.mockito.ArgumentMatchers;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@@ -16,8 +14,6 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
public class JsonTaskListTest {
|
public class JsonTaskListTest {
|
||||||
|
|
||||||
@@ -51,16 +47,17 @@ public class JsonTaskListTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled("disabled until adding works.")
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Add task.")
|
@DisplayName("Add task.")
|
||||||
void addTask() {
|
void addTask() {
|
||||||
Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("2022-05-01", formatter), 1);
|
Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("01.05.2022", formatter), 1);
|
||||||
try {
|
try {
|
||||||
testDatabase.saveTask(task);
|
testDatabase.saveTask(task);
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
try {
|
try {
|
||||||
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
|
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
|
||||||
LocalDate.parse("2022-05-31", formatter));
|
LocalDate.parse("31.05.2022", formatter));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -75,7 +72,8 @@ public class JsonTaskListTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Remove task.")
|
@DisplayName("Remove task.")
|
||||||
void removeTask() {
|
void removeTask() {
|
||||||
Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1).withId(2);
|
Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1)
|
||||||
|
.withId(2);
|
||||||
try {
|
try {
|
||||||
testDatabase.removeTask(task);
|
testDatabase.removeTask(task);
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
@@ -104,7 +102,7 @@ public class JsonTaskListTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled("Disabled until removing works")
|
||||||
@Test
|
@Test
|
||||||
void removeTasksForCrop() {
|
void removeTasksForCrop() {
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
@@ -117,27 +115,4 @@ public class JsonTaskListTest {
|
|||||||
|
|
||||||
Assertions.assertEquals(0, taskList.size());
|
Assertions.assertEquals(0, taskList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDefaultConstructor(){
|
|
||||||
JsonTaskList db = new JsonTaskList();
|
|
||||||
try {
|
|
||||||
assertNotNull(db.getTaskForCrop(0));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testSubscription() {
|
|
||||||
TaskList.TaskListObserver mockObs = Mockito.mock(TaskList.TaskListObserver.class);
|
|
||||||
testDatabase.subscribe(mockObs);
|
|
||||||
try {
|
|
||||||
testDatabase.removeTasksForCrop(0);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
verify(mockObs, times(1)).onChange(ArgumentMatchers.anyList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,6 @@ class GardenScheduleTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException {
|
void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException {
|
||||||
assertThrows(PlantNotFoundException.class,()-> model.planTasksForCrop(new Crop()));
|
|
||||||
model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30));
|
model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30));
|
||||||
verify(exampleTaskTemplateList.get(0), times(1)).generateTask(exampleStartDate, 30);
|
verify(exampleTaskTemplateList.get(0), times(1)).generateTask(exampleStartDate, 30);
|
||||||
verify(exampleTaskTemplateList.get(1), times(1)).generateTask(exampleStartDate, 30);
|
verify(exampleTaskTemplateList.get(1), times(1)).generateTask(exampleStartDate, 30);
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.MonthDay;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class PlantTest {
|
|
||||||
|
|
||||||
Plant testPlant;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
List<GrowthPhase> growthPhases = new ArrayList<>();
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(2, 1), MonthDay.of(4, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.SOW, HardinessZone.ZONE_8A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(4, 2), MonthDay.of(6, 5), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(6, 3), MonthDay.of(8, 6), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(3, 1), MonthDay.of(5, 4), 1, new WateringCycle(0, 0, null), GrowthPhaseType.SOW, HardinessZone.ZONE_8A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(5, 2), MonthDay.of(7, 5), 1, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(7, 3), MonthDay.of(9, 6), 1, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(4, 1), MonthDay.of(6, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.SOW, HardinessZone.ZONE_1A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(6, 2), MonthDay.of(8, 5), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_1A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(7, 2), MonthDay.of(9, 5), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_1A, new ArrayList<>()));
|
|
||||||
growthPhases.add(new GrowthPhase(MonthDay.of(8, 3), MonthDay.of(10, 6), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_1A, new ArrayList<>()));
|
|
||||||
|
|
||||||
testPlant = new Plant(
|
|
||||||
20,
|
|
||||||
"summertime onion",
|
|
||||||
"Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.",
|
|
||||||
null,
|
|
||||||
"15,30,2",
|
|
||||||
0,
|
|
||||||
"sandy to loamy, loose soil, free of stones",
|
|
||||||
new ArrayList<>(),
|
|
||||||
growthPhases);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void tearDown() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void inZone() {
|
|
||||||
assertEquals(7,testPlant.lifecycleForGroup(0).size());
|
|
||||||
testPlant.inZone(HardinessZone.ZONE_8A);
|
|
||||||
assertEquals(3,testPlant.lifecycleForGroup(0).size());
|
|
||||||
assertEquals(Arrays.asList(3,5,7),testPlant.lifecycleForGroup(1).stream().map(gp ->gp.startDate().getMonthValue()).toList() );
|
|
||||||
testPlant.inZone(HardinessZone.ZONE_1A);
|
|
||||||
assertEquals(0,testPlant.lifecycleForGroup(0).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void lifecycleForGroup() {
|
|
||||||
assertEquals(Arrays.asList(2,4,6,4,6,7,8),testPlant.lifecycleForGroup(0).stream().map(gp ->gp.startDate().getMonthValue()).toList() );
|
|
||||||
assertEquals(Arrays.asList(3,5,7),testPlant.lifecycleForGroup(1).stream().map(gp ->gp.startDate().getMonthValue()).toList() );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void sowDateFromHarvestDate() {
|
|
||||||
assertEquals(LocalDate.of(2022,8,1),
|
|
||||||
testPlant.sowDateFromHarvestDate(LocalDate.of(2022,12,1))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void timeToHarvest() {
|
|
||||||
testPlant.inZone(HardinessZone.ZONE_8A);
|
|
||||||
assertEquals(122,testPlant.timeToHarvest(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void lifecycleGroupFromHarvestDate() {
|
|
||||||
testPlant.inZone(HardinessZone.ZONE_8A);
|
|
||||||
assertEquals(0,testPlant.lifecycleGroupFromHarvestDate(LocalDate.of(2022,6,30)));
|
|
||||||
assertEquals(1,testPlant.lifecycleGroupFromHarvestDate(LocalDate.of(2022,8,30)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void isDateInPhase() {
|
|
||||||
assertTrue(testPlant.isDateInPhase(LocalDate.of(2022,6,30),GrowthPhaseType.HARVEST));
|
|
||||||
assertTrue(testPlant.isDateInPhase(LocalDate.of(2022,8,30),GrowthPhaseType.HARVEST));
|
|
||||||
assertTrue(testPlant.isDateInPhase(LocalDate.of(2022,2,1),GrowthPhaseType.SOW));
|
|
||||||
assertTrue(testPlant.isDateInPhase(LocalDate.of(2022,4,2),GrowthPhaseType.PLANT));
|
|
||||||
assertFalse(testPlant.isDateInPhase(LocalDate.of(2022,6,30),GrowthPhaseType.SOW));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package ch.zhaw.gartenverwaltung.types;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.MonthDay;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class SeasonsTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getStartDate() {
|
|
||||||
assertEquals(MonthDay.of(1,1), Seasons.ALLSEASONS.getStartDate());
|
|
||||||
assertEquals(MonthDay.of(3,1), Seasons.SPRING.getStartDate());
|
|
||||||
assertEquals(MonthDay.of(6,1), Seasons.SUMMER.getStartDate());
|
|
||||||
assertEquals(MonthDay.of(9,1), Seasons.AUTUMN.getStartDate());
|
|
||||||
assertEquals(MonthDay.of(12,1), Seasons.WINTER.getStartDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getEndDate() {
|
|
||||||
assertEquals(MonthDay.of(12,31), Seasons.ALLSEASONS.getEndDate());
|
|
||||||
assertEquals(MonthDay.of(5,30), Seasons.SPRING.getEndDate());
|
|
||||||
assertEquals(MonthDay.of(8,30), Seasons.SUMMER.getEndDate());
|
|
||||||
assertEquals(MonthDay.of(11,30), Seasons.AUTUMN.getEndDate());
|
|
||||||
assertEquals(MonthDay.of(2,28), Seasons.WINTER.getEndDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getName() {
|
|
||||||
assertEquals("All Seasons", Seasons.ALLSEASONS.getName());
|
|
||||||
assertEquals("Spring", Seasons.SPRING.getName());
|
|
||||||
assertEquals("Summer", Seasons.SUMMER.getName());
|
|
||||||
assertEquals("Autumn", Seasons.AUTUMN.getName());
|
|
||||||
assertEquals("Winter", Seasons.WINTER.getName());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"plantId": 1,
|
|
||||||
"startDate": "2023-02-25",
|
|
||||||
"area": 0.5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
Reference in New Issue
Block a user