Compare commits

..

No commits in common. "aa87a23f7db53d82c3eb005f9f119ae740e68852" and "233ce6b088599114f647d43e644f93f36bdf7937" have entirely different histories.

49 changed files with 373 additions and 929 deletions

View File

@ -22,7 +22,6 @@ import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
@ -88,7 +87,7 @@ public class CropDetailController {
private ListView<Pest> pests_listView;
@FXML
void addTask() throws IOException, HardinessZoneNotSetException {
void addTask() throws IOException {
createTaskDialog(true, null);
}
@ -137,7 +136,7 @@ public class CropDetailController {
if (plant.image() != null) {
imageView.setImage(plant.image());
}
area_label.setText(String.valueOf(crop.getArea()));
area_label.setText("");
location_label.setText("");
setTaskListProperty(crop);
@ -206,28 +205,22 @@ public class CropDetailController {
}
private HBox createTaskHBox(Task task) {
HBox hBox = new HBox(10);
HBox hBox = new HBox();
Label taskName = new Label(task.getName()+": ");
taskName.setMinWidth(100);
taskName.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
taskName.setStyle("-fx-font-weight: bold");
Label taskDescription = new Label(task.getDescription());
taskDescription.setWrapText(true);
taskDescription.setMaxSize(600, Double.MAX_VALUE);
Pane puffer = new Pane();
HBox.setHgrow(puffer, Priority.ALWAYS);
taskDescription.setMaxWidth(2000);
HBox.setHgrow(taskDescription, Priority.ALWAYS);
Button edit = new Button();
Button delete = new Button();
HBox.setHgrow(edit, Priority.NEVER);
HBox.setHgrow(delete, Priority.NEVER);
setIconToButton(edit, "editIcon.png");
setIconToButton(delete, "deleteIcon.png");
edit.setOnAction(getEditTaskEvent(task));
delete.setOnAction(deleteTask(task));
hBox.getChildren().addAll(taskName, taskDescription, puffer, edit, delete);
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
return hBox;
}
@ -236,15 +229,12 @@ public class CropDetailController {
label.setStyle("-fx-font-weight: bold");
HBox hBox = new HBox();
hBox.fillHeightProperty();
Label description = new Label(pest.description());
description.setAlignment(Pos.TOP_LEFT);
description.setWrapText(true);
description.setMaxWidth(600);
Pane puffer = new Pane();
HBox.setHgrow(puffer, Priority.ALWAYS);
Label label1 = new Label(pest.description());
label1.setAlignment(Pos.TOP_LEFT);
label1.setWrapText(true);
label1.setMaxWidth(600);
Button button = new Button("Get Counter Measures");
HBox.setHgrow(button, Priority.NEVER);
hBox.getChildren().addAll(label, description, puffer, button);
hBox.getChildren().addAll(label, label1, button);
return hBox;
}
@ -265,7 +255,7 @@ public class CropDetailController {
return (event) -> {
try {
createTaskDialog(false, task);
} catch (IOException | HardinessZoneNotSetException e) {
} catch (IOException e) {
e.printStackTrace();
}
};
@ -277,7 +267,7 @@ public class CropDetailController {
};
}
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException, HardinessZoneNotSetException {
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
Dialog<Task> dialog = new Dialog<>();
dialog.setTitle("Set Task");
dialog.setHeaderText("Add/Edit Task:");
@ -299,7 +289,7 @@ public class CropDetailController {
if (!newTask) {
controller.setTaskValue(givenTask);
}
dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult(this.crop) : null);
dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult() : null);
dialog.showAndWait()
.ifPresent(task -> {
@ -344,11 +334,8 @@ public class CropDetailController {
//ToDo method to set location
location_label.setText(string);
} else {
try {
garden.updateCrop(this.crop.withArea(Double.parseDouble(string)));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(string);
//ToDo method to set area of crop in garden
area_label.setText(string);
}
});

View File

@ -0,0 +1,14 @@
package ch.zhaw.gartenverwaltung;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
public class HelloController {
@FXML
private Label welcomeText;
@FXML
protected void onHelloButtonClick() {
welcomeText.setText("Welcome to JavaFX Application!");
}
}

View File

@ -51,6 +51,7 @@ public class MyGardenController {
@AfterInject
@SuppressWarnings("unused")
public void init() {
System.out.println("once");
setIconToButton(addPlant_button, "addIcon.png");
myGarden_listView.itemsProperty().bind(garden.getPlantedCrops());
setCellFactory();

View File

@ -9,14 +9,11 @@ import ch.zhaw.gartenverwaltung.models.GardenSchedule;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Task;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import java.io.IOException;
@ -27,7 +24,6 @@ import java.util.logging.Logger;
public class MyScheduleController {
private static final Logger LOG = Logger.getLogger(MyScheduleController.class.getName());
private final ListProperty<List<Task>> taskListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private Crop selectedCrop = null;
@ -39,7 +35,46 @@ public class MyScheduleController {
private PlantList plantList;
@FXML
private ListView<List<Task>> week_listView;
private Label day1_label;
@FXML
private Pane day1_pane;
@FXML
private Label day2_label;
@FXML
private Pane day2_pane;
@FXML
private Label day3_label;
@FXML
private Pane day3_pane;
@FXML
private Label day4_label;
@FXML
private Pane day4_pane;
@FXML
private Label day5_label;
@FXML
private Pane day5_pane;
@FXML
private Label day6_label;
@FXML
private Pane day6_pane;
@FXML
private Label day7_label;
@FXML
private Pane day7_pane;
@FXML
private Label information_label;
@ -50,11 +85,10 @@ public class MyScheduleController {
@AfterInject
@SuppressWarnings("unused")
public void init() {
setCellFactoryCropListView();
setCellFactoryTaskListView();
setCellFactoryListView();
scheduledPlants_listview.itemsProperty().bind(garden.getPlantedCrops());
week_listView.itemsProperty().bind(taskListProperty);
lookForSelectedListEntries();
setDayLabels();
information_label.setText("");
try {
loadTaskList();
@ -74,7 +108,18 @@ public class MyScheduleController {
});
}
private void setCellFactoryCropListView() {
private void setDayLabels() {
LocalDate today = LocalDate.now();
day1_label.setText(today.getDayOfWeek().toString());
day2_label.setText(today.plusDays(1).getDayOfWeek().toString());
day3_label.setText(today.plusDays(2).getDayOfWeek().toString());
day4_label.setText(today.plusDays(3).getDayOfWeek().toString());
day5_label.setText(today.plusDays(4).getDayOfWeek().toString());
day6_label.setText(today.plusDays(5).getDayOfWeek().toString());
day7_label.setText(today.plusDays(6).getDayOfWeek().toString());
}
private void setCellFactoryListView() {
scheduledPlants_listview.setCellFactory(param -> new ListCell<>() {
@Override
protected void updateItem(Crop crop, boolean empty) {
@ -96,23 +141,6 @@ public class MyScheduleController {
});
}
private void setCellFactoryTaskListView() {
week_listView.setCellFactory(param -> new ListCell<>() {
@Override
protected void updateItem(List<Task> taskList, boolean empty) {
super.updateItem(taskList, empty);
if (empty || taskList == null) {
setGraphic(null);
setText(null);
} else {
setText("");
setGraphic(weekTaskVBox(taskList, this.getIndex()));
}
}
});
}
private void loadTaskList() throws IOException {
List<List<Task>> taskLists;
if (selectedCrop != null) {
@ -120,66 +148,25 @@ public class MyScheduleController {
} else {
taskLists = gardenSchedule.getTasksUpcomingWeek();
}
taskListProperty.clear();
taskListProperty.addAll(taskLists);
}
private VBox weekTaskVBox(List<Task> tasks, int dayIndex) {
VBox vBox = new VBox(10);
LocalDate today = LocalDate.now();
Label weekDay = new Label(today.plusDays(dayIndex).getDayOfWeek().toString());
weekDay.setStyle("-fx-font-weight: bold; -fx-underline: true");
vBox.getChildren().add(weekDay);
for (Task task : tasks) {
HBox hBox = new HBox(10);
Label taskName = new Label(task.getName() + ":");
taskName.setStyle("-fx-font-weight: bold");
taskName.setMinWidth(100);
taskName.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
hBox.getChildren().addAll(taskName);
HBox hBoxDescription = new HBox();
Label taskDescription = new Label(task.getDescription());
taskDescription.setWrapText(true);
taskDescription.setMaxSize(600, Double.MAX_VALUE);
Pane puffer = new Pane();
HBox.setHgrow(puffer, Priority.ALWAYS);
CheckBox checkBox = new CheckBox("Task completed?");
checkBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
showConfirmation(task, checkBox);
}
});
HBox.setHgrow(checkBox, Priority.NEVER);
hBoxDescription.getChildren().addAll(taskDescription, puffer, checkBox);
vBox.getChildren().addAll(hBox, hBoxDescription);
if (!taskLists.isEmpty()) {
viewTaskListOfDay(day1_pane, taskLists.get(0));
viewTaskListOfDay(day2_pane, taskLists.get(1));
viewTaskListOfDay(day3_pane, taskLists.get(2));
viewTaskListOfDay(day4_pane, taskLists.get(3));
viewTaskListOfDay(day5_pane, taskLists.get(4));
viewTaskListOfDay(day6_pane, taskLists.get(5));
viewTaskListOfDay(day7_pane, taskLists.get(6));
}
return vBox;
}
/**
* Alert to confirm that task has been completed.
* @param task {@link Task} which is selected
*/
private void showConfirmation(Task task, CheckBox checkBox) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Task Completed?");
alert.setHeaderText("Are you sure you have completed this task?");
alert.setContentText("Confirming that you have completed the task will remove it from the schedule.");
alert.showAndWait()
.ifPresent(buttonType -> {
if (buttonType == ButtonType.OK) {
task.done();
try {
loadTaskList();
} catch (IOException e) {
e.printStackTrace();
}
} else {
checkBox.setSelected(false);
}
});
private void viewTaskListOfDay(Pane pane, List<Task> tasks) {
//ToDo update pane with task list
VBox vBox = new VBox();
for (Task task : tasks) {
Label label = new Label(task.getDescription());
vBox.getChildren().add(label);
}
pane.getChildren().add(vBox);
}

View File

@ -233,11 +233,11 @@ public class PlantsController {
RadioButton radioButton = new RadioButton(season.getName());
radioButton.setToggleGroup(seasonGroup);
radioButton.setPadding(new Insets(0, 0, 10, 0));
if (season.equals(Seasons.ALLSEASONS)) {
if (season.equals(Seasons.AllSEASONS)) {
radioButton.setSelected(true);
}
radioButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (season.equals(Seasons.ALLSEASONS)) {
if (season.equals(Seasons.AllSEASONS)) {
fillPlantListWithHardinessZone();
} else {
try {

View File

@ -1,35 +1,23 @@
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.Plant;
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.Initializable;
import javafx.scene.control.*;
import javafx.util.Callback;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;
public class TaskFormularController implements Initializable {
private Crop crop;
private Plant plant;
private Task task = null;
@Inject
private GardenSchedule gardenSchedule;
@Inject
private Garden garden;
@Inject
private PlantList plantList;
@FXML
private TextArea description_area;
@ -46,28 +34,19 @@ public class TaskFormularController implements Initializable {
@FXML
private TextField taskName_field;
@AfterInject
@SuppressWarnings("unused")
public Task returnResult(Crop crop) {
int interval = 0;
if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) {
interval = Integer.parseInt(interval_field.getText());
}
public Task returnResult() {
Task task = new Task(taskName_field.getText(), description_area.getText(),
start_datePicker.getValue(), end_datePicker.getValue(),
interval, crop.getCropId().get());
if (this.task != null) return this.task.updateTask(task);
Integer.parseInt(interval_field.getText()), crop.getCropId().get());
return task;
}
public void setCorp(Crop crop) throws HardinessZoneNotSetException, IOException {
public void setCorp(Crop crop) {
this.crop = crop;
this.plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get();
}
public void setTaskValue(Task task) {
this.task = task;
taskName_field.setText(task.getName());
description_area.setText(task.getDescription());
start_datePicker.setValue(task.getStartDate());
@ -90,7 +69,7 @@ public class TaskFormularController implements Initializable {
setDisable(true);
setStyle("-fx-background-color: #ffc0cb;");
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) {
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
setDisable(false);
setStyle("-fx-background-color: #32CD32;");
}
@ -114,7 +93,7 @@ public class TaskFormularController implements Initializable {
setDisable(true);
setStyle("-fx-background-color: #ffc0cb;");
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) {
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
setDisable(false);
setStyle("-fx-background-color: #32CD32;");
}
@ -135,8 +114,12 @@ public class TaskFormularController implements Initializable {
});
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
.or(end_datePicker.valueProperty().isNull())
.or(taskName_field.textProperty().isEmpty())
.or(description_area.textProperty().isEmpty()));
.or(description_area.textProperty().isEmpty())
.or(interval_field.textProperty().isEmpty()));
}
@Override

View File

@ -27,15 +27,6 @@ public class TextFieldFormularController {
}
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());
}
}

View File

@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates a method to be executed after all dependencies annotated with {@link Inject}
* Annotates a method to be executed after all dependencies annotates with {@link Inject}
* have been injected.
*/
@Retention(RetentionPolicy.RUNTIME)

View File

@ -18,10 +18,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* Class responsible for bootstrapping the application wide dependencies
* and injecting them into JavaFX Controllers.
*/
public class AppLoader {
/**
* Caching the panes
@ -31,25 +27,19 @@ public class AppLoader {
/**
* Application-wide dependencies
*/
private final Map<String, Object> dependencies = new HashMap<>();
private final PlantList plantList = new JsonPlantList();
private final CropList cropList = new JsonCropList();
private final TaskList taskList = new JsonTaskList();
private final GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
private final WeatherGradenTaskPlanner weatherGradenTaskPlanner = new WeatherGradenTaskPlanner(taskList,plantList,cropList);
private final Garden garden = new Garden(gardenSchedule, cropList);
public AppLoader() throws IOException {
PlantList plantList = new JsonPlantList();
CropList cropList = new JsonCropList();
TaskList taskList = new JsonTaskList();
GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
dependencies.put(PlantList.class.getSimpleName(), plantList);
dependencies.put(CropList.class.getSimpleName(), cropList);
dependencies.put(TaskList.class.getSimpleName(), taskList);
dependencies.put(PlantListModel.class.getSimpleName(), new PlantListModel(plantList));
dependencies.put(GardenSchedule.class.getSimpleName(), gardenSchedule);
dependencies.put(Garden.class.getSimpleName(), new Garden(gardenSchedule, cropList));
dependencies.put(AppLoader.class.getSimpleName(), this);
}
/**
* Loads and returns a {@link Pane} (cached).
*
@ -141,18 +131,26 @@ public class AppLoader {
});
Arrays.stream(controller.getClass().getMethods())
.filter(method -> method.isAnnotationPresent(AfterInject.class) && method.getParameterCount() == 0)
.filter(method -> method.isAnnotationPresent(AfterInject.class))
.forEach(afterInjectMethod -> {
try {
afterInjectMethod.invoke(controller);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO: Log
e.printStackTrace();
if (afterInjectMethod.getParameterCount() == 0) {
try {
afterInjectMethod.invoke(controller);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
});
}
private Object getAppDependency(Class<?> type) {
return dependencies.get(type.getSimpleName());
return switch (type.getSimpleName()) {
case "Garden" -> garden;
case "PlantList" -> plantList;
case "PlantListModel" -> new PlantListModel(plantList);
case "GardenSchedule" -> gardenSchedule;
case "AppLoader" -> this;
default -> null;
};
}
}

View File

@ -3,20 +3,11 @@ package ch.zhaw.gartenverwaltung.bootstrap;
import javafx.event.Event;
import javafx.event.EventType;
/**
* Represents an event that should lead to a view being changed.
*/
public class ChangeViewEvent extends Event {
private final String view;
public static final EventType<ChangeViewEvent> CHANGE_MAIN_VIEW = new EventType<>("CHANGE_MAIN_VIEW");
/**
* Creates an Event that should lead to the main view being changed.
*
* @param eventType The {@link EventType<ChangeViewEvent>} specifying which view should be changed.
* @param view The filename of the View to be changed to
*/
public ChangeViewEvent(EventType<? extends Event> eventType, String view) {
super(eventType);
this.view = view;

View File

@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates a Field to be injected from the application-dependencies.
* Annotates a Field to be injected from the application-dependencies
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)

View File

@ -6,10 +6,6 @@ import java.io.IOException;
import java.util.List;
import java.util.Optional;
/**
* Represents a List of {@link Crop}s.
* The interface specifies the operations to add/update and remove entries.
*/
public interface CropList {
/**
* Yields a list of all {@link Crop}s in the database.

View File

@ -1,18 +1,10 @@
package ch.zhaw.gartenverwaltung.io;
/**
* Provides an sequential ID starting from the given initial Value.
*/
public class IdProvider {
private long currentId;
public IdProvider(long initialValue) {
currentId = initialValue;
}
/**
* Yields the next ID in the sequence.
* @return The next ID
*/
public long incrementAndGet() {
return ++currentId;
}

View File

@ -19,11 +19,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* Implements the {@link CropList} interface for reading and writing {@link Crop} objects
* from and to a local JSON file.
* The reads are cached to minimize file-io operations.
*/
public class JsonCropList implements CropList {
private final URL dataSource;
@ -45,7 +40,7 @@ public class JsonCropList implements CropList {
}
/**
* Default constructor. Uses a file from the app resources.
* Default constructor
*/
public JsonCropList() {
this.dataSource = getClass().getResource("user-crops.json");

View File

@ -20,8 +20,8 @@ import java.util.Map;
import java.util.Optional;
/**
* Implements the {@link PlantList} interface for reading {@link Plant} objects
* from a local JSON file.
* Implements the {@link PlantList} interface for loading {@link Plant} objects
* from a JSON file.
* The reads are cached to minimize file-io operations.
*/
public class JsonPlantList implements PlantList {
@ -44,17 +44,9 @@ public class JsonPlantList implements PlantList {
imageModule.addDeserializer(Image.class, new PlantImageDeserializer());
}
/**
* Default constructor. Uses a file from the app resources.
*/
public JsonPlantList() {
this.dataSource = getClass().getResource("plantdb.json");
}
/**
* Constructor to use a specified {@link URL} as a {@link #dataSource}
* @param dataSource A {@link URL} to the file to be used as a data source
*/
public JsonPlantList(URL dataSource) {
this.dataSource = dataSource;
}
@ -75,7 +67,7 @@ public class JsonPlantList implements PlantList {
}
/**
* @see PlantList#getPlantById(HardinessZone, long)
* @see PlantList#getPlantById(long)
*/
@Override
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws HardinessZoneNotSetException, IOException {

View File

@ -20,8 +20,8 @@ import java.util.List;
import java.util.Map;
/**
* Implements the {@link TaskList} interface for reading and writing {@link Task} objects
* from and to a local JSON file.
* Implements the {@link TaskList} interface for loading and writing {@link Task} objects
* from and to a JSON file.
* The reads are cached to minimize file-io operations.
*/
public class JsonTaskList implements TaskList {
@ -45,17 +45,9 @@ public class JsonTaskList implements TaskList {
timeModule.addSerializer(LocalDate.class, dateSerializer);
}
/**
* Default constructor. Uses a file from the app resources.
*/
public JsonTaskList() {
this.dataSource = getClass().getResource("taskdb.json");
}
/**
* Constructor to use a specified {@link URL} as a {@link #dataSource}
* @param dataSource A {@link URL} to the file to be used as a data source
*/
public JsonTaskList(URL dataSource) {
this.dataSource = dataSource;
}
@ -96,8 +88,7 @@ public class JsonTaskList implements TaskList {
if(taskMap.isEmpty()) {
loadTaskListFromFile();
}
taskMap.entrySet().removeIf(entry -> entry.getValue().getCropId() == cropId);
writeTaskListToFile();
taskMap.values().removeIf(task -> task.getCropId() == cropId);
notifySubscribers();
}

View File

@ -8,7 +8,7 @@ import java.util.List;
import java.util.Optional;
/**
* A List of {@link Plant}s.
* A database of {@link Plant}s.
* The interface specifies the minimal required operations.
*/
public interface PlantList {

View File

@ -7,8 +7,8 @@ import java.time.LocalDate;
import java.util.List;
/**
* Represents a List of {@link Task}s.
* The interface specifies the operations to add/update and remove entries.
* A database of {@link Task}s.
* The interface specifies the minimal required operations.
*/
public interface TaskList {
/**

View File

@ -73,14 +73,16 @@ public class WeatherGradenTaskPlanner {
for (Crop crop : cropList.getCrops()) {
Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
// nur für aktuelle growthphase
if(plant.wateringCycle().litersPerSqM() < rainAmount){
adjustNextExecutionOfWateringTask(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7)));
for (GrowthPhase growthphase : plant.lifecycle()) {
if(growthphase.wateringCycle().litersPerSqM() < rainAmount){
adjustNextExecutionOfWateringTask(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7)));
}
}
}
}
// vom startdatum abhängig,
private void adjustNextExecutionOfWateringTask(List<Task> cropTaskList){
for(Task task : cropTaskList){
if(task.getName().equals("watering task")){

View File

@ -7,9 +7,6 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
/**
* Used by the Jackson Library to deserialize a String to a {@link GrowthPhaseType}
*/
public class GrowthPhaseTypeDeserializer extends StdDeserializer<GrowthPhaseType> {
public GrowthPhaseTypeDeserializer(Class<?> vc) {
super(vc);

View File

@ -7,9 +7,6 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
/**
* Used by the Jackson Library to deserialize a String to a {@link HardinessZone}
*/
public class HardinessZoneDeserializer extends StdDeserializer<HardinessZone> {
public HardinessZoneDeserializer(Class<?> vc) {
super(vc);

View File

@ -13,9 +13,6 @@ import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
/**
* Used by the Jackson Library to deserialize a String to a {@link Image}
*/
public class PlantImageDeserializer extends JsonDeserializer<Image> {
@Override

View File

@ -70,19 +70,6 @@ public class Garden {
plantedCrops.clear();
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.
*

View File

@ -49,13 +49,16 @@ public class GardenSchedule {
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
int growPhaseGroup = plant.getGrowphaseGroupForDate(crop.getStartDate());
addTask(new Task("watering Task", "pour water over the plant circa : "+ plant.wateringCycle().litersPerSqM() +" per square meter",
crop.getStartDate(), crop.getStartDate().plusDays(plant.timeToHarvest(0)),
plant.wateringCycle().interval(), crop.getCropId().orElse(0L)));
for (GrowthPhase growthPhase : plant.lifecycleForGroup(growPhaseGroup)) {
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
}
//TODO add wateringtask
if(growthPhase.wateringCycle() != null){
addTask(new Task("watering Task", "pour water over the plant circa : "+ growthPhase.wateringCycle().litersPerSqM() +" per square meter",
growthPhase.startDate().atYear(LocalDate.now().getYear()), growthPhase.endDate().atYear(LocalDate.now().getYear()),
growthPhase.wateringCycle().interval(), crop.getCropId().orElse(0L)));
}
}
}
@ -150,18 +153,13 @@ public class GardenSchedule {
dayTaskList.add(new ArrayList<>());
final int finalI = i;
weekTasks.forEach(task -> {
if (task.getNextExecution() == null) {
task.isDone();
} else {
LocalDate checkDate = task.getNextExecution();
do {
if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) {
dayTaskList.get(finalI).add(task);
}
checkDate = checkDate.plusDays(task.getInterval().orElse(0));
} while (!(task.getInterval().orElse(0) == 0) && checkDate.isBefore(LocalDate.now().plusDays(listLength)));
}
LocalDate checkDate = task.getNextExecution();
do {
if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) {
dayTaskList.get(finalI).add(task);
}
checkDate = checkDate.plusDays(task.getInterval().orElse(0));
} while (task.getInterval().isPresent() && checkDate.isBefore(LocalDate.now().plusDays(listLength)));
});
}
return dayTaskList;
@ -196,6 +194,6 @@ public class GardenSchedule {
* @return a sorted coppy of the given Tasklist
*/
private List<Task> getSortedTaskList(List<Task> taskList, Comparator<Task> comparator) {
return taskList.stream().filter(task -> task.getNextExecution() != null).sorted(comparator).collect(Collectors.toList());
return taskList.stream().sorted(comparator).collect(Collectors.toList());
}
}

View File

@ -1,8 +1,5 @@
package ch.zhaw.gartenverwaltung.types;
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
import ch.zhaw.gartenverwaltung.io.PlantList;
import java.time.LocalDate;
import java.util.Objects;
import java.util.Optional;

View File

@ -12,6 +12,7 @@ public record GrowthPhase(
MonthDay startDate,
MonthDay endDate,
int group,
WateringCycle wateringCycle,
@JsonDeserialize(using = GrowthPhaseTypeDeserializer.class) GrowthPhaseType type,
@JsonDeserialize(using = HardinessZoneDeserializer.class) HardinessZone zone,
List<TaskTemplate> taskTemplates) {

View File

@ -18,7 +18,6 @@ public record Plant(
int light,
String soil,
List<Pest> pests,
WateringCycle wateringCycle,
List<GrowthPhase> lifecycle) {
/**
@ -67,16 +66,16 @@ public record Plant(
public int timeToHarvest(int group) {
List<GrowthPhase> activeLifecycle = lifecycleForGroup(group);
GrowthPhase sow = activeLifecycle.stream()
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.SOW))
.filter(growthPhase -> !growthPhase.type().equals(GrowthPhaseType.SOW))
.findFirst()
.orElseThrow();
GrowthPhase harvest = activeLifecycle.stream()
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.HARVEST))
.filter(growthPhase -> !growthPhase.type().equals(GrowthPhaseType.HARVEST))
.findFirst()
.orElseThrow();
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) {

View File

@ -3,7 +3,7 @@ package ch.zhaw.gartenverwaltung.types;
import java.time.MonthDay;
public enum Seasons {
ALLSEASONS("--01-01", "--12-31", "All Seasons"),
AllSEASONS("--01-01", "--12-31", "All Seasons"),
SPRING("--03-01", "--05-30", "Spring"),
SUMMER("--06-01", "--08-30", "Summer"),
AUTUMN("--09-01", "--11-30", "Autumn"),

View File

@ -10,15 +10,14 @@ import java.util.Optional;
*/
public class Task {
private Long id;
private String name;
private String description;
private LocalDate startDate;
private final String name;
private final String description;
private final LocalDate startDate;
private Integer interval;
private LocalDate endDate;
private LocalDate nextExecution;
private LocalDate nextNotification;
private long cropId;
private boolean done;
/**
* default constructor
@ -79,7 +78,7 @@ public class Task {
}
public void done(){
if(interval != null && interval != 0 && !nextExecution.plusDays(interval).isAfter(endDate)){
if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){
nextExecution = nextExecution.plusDays(interval);
} else {
nextExecution = null;
@ -113,14 +112,4 @@ public class Task {
public Optional<LocalDate> getEndDate() {
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;
}
}

View File

@ -42,7 +42,7 @@ public class TaskTemplate {
}
public Task generateTask(LocalDate realStartDate, long cropId) {
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate;
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
if (interval == null) {
this.interval = 0;

View File

@ -107,7 +107,7 @@
<Insets right="60.0" />
</HBox.margin>
</Label>
<Label fx:id="area_label" minWidth="-Infinity" prefWidth="50.0" text="Label">
<Label fx:id="area_label" text="Label">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
@ -125,7 +125,7 @@
<Insets right="40.0" />
</HBox.margin>
</Label>
<Label fx:id="location_label" minHeight="-Infinity" prefWidth="50.0" text="Label">
<Label fx:id="location_label" text="Label">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>

View File

@ -7,14 +7,14 @@
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="938.0" prefWidth="1110.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.MainFXMLController">
<children>
<HBox fx:id="menubar" maxWidth="35.0" minHeight="40.0" prefHeight="38.0" prefWidth="1110.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox maxWidth="35.0" minHeight="35.0" prefHeight="38.0" prefWidth="1110.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Button fx:id="home_button" mnemonicParsing="false" onAction="#goToHome" prefHeight="38.0" prefWidth="38.0" HBox.hgrow="NEVER" />
<Button fx:id="home_button" mnemonicParsing="false" onAction="#goToHome" prefHeight="38.0" prefWidth="40.0" HBox.hgrow="NEVER" />
<Button fx:id="myGarden_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToMyPlants" prefHeight="38.0" prefWidth="121.0" text="My Garden" />
<Button fx:id="mySchedule_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToMySchedule" prefHeight="38.0" prefWidth="121.0" text="My Schedule" />
<Button fx:id="tutorial_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#showTutorial" prefHeight="38.0" prefWidth="121.0" text="Tutorial" />
<Pane fx:id="menu_pane" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<Button fx:id="settings_button" mnemonicParsing="false" onAction="#openSettings" prefHeight="38.0" prefWidth="38.0" HBox.hgrow="NEVER" />
<Pane maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<Button fx:id="settings_button" maxHeight="1.7976931348623157E308" mnemonicParsing="false" onAction="#openSettings" prefHeight="38.0" prefWidth="40.0" HBox.hgrow="NEVER" />
</children>
</HBox>
<AnchorPane fx:id="mainPane" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="35.0" />

View File

@ -1,15 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="572.0" prefWidth="867.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.MyScheduleController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="572.0" prefWidth="867.0"
xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.MyScheduleController">
<children>
<Label layoutX="14.0" layoutY="14.0" text="MySchedule">
<font>
@ -18,18 +22,41 @@
</Label>
<HBox layoutY="31.0" prefHeight="541.0" prefWidth="867.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="50.0">
<children>
<ListView fx:id="scheduledPlants_listview" maxWidth="1.7976931348623157E308" prefHeight="522.0" prefWidth="271.0" HBox.hgrow="NEVER">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin></ListView>
<ListView fx:id="scheduledPlants_listview" maxWidth="1.7976931348623157E308" prefHeight="522.0" prefWidth="365.0" HBox.hgrow="NEVER" />
<VBox maxWidth="1.7976931348623157E308" prefHeight="537.0" prefWidth="650.0" HBox.hgrow="ALWAYS">
<children>
<ListView fx:id="week_listView" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</ListView>
<Pane prefHeight="131.0" prefWidth="593.0" VBox.vgrow="NEVER">
<GridPane alignment="CENTER_LEFT" gridLinesVisible="true" maxWidth="1.7976931348623157E308" prefHeight="403.0" prefWidth="575.0" VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints fillWidth="false" hgrow="NEVER" maxWidth="278.0" minWidth="100.0" prefWidth="173.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="402.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label fx:id="day1_label" alignment="CENTER" prefHeight="32.0" prefWidth="173.0" text="Label" />
<Label fx:id="day2_label" alignment="CENTER" prefHeight="29.0" prefWidth="173.0" text="Label" GridPane.rowIndex="1" />
<Label fx:id="day3_label" alignment="CENTER" prefHeight="32.0" prefWidth="172.0" text="Label" GridPane.rowIndex="2" />
<Label fx:id="day4_label" alignment="CENTER" prefHeight="35.0" prefWidth="173.0" text="Label" GridPane.rowIndex="3" />
<Label fx:id="day5_label" alignment="CENTER" prefHeight="31.0" prefWidth="173.0" text="Label" GridPane.rowIndex="4" />
<Label fx:id="day6_label" alignment="CENTER" prefHeight="31.0" prefWidth="173.0" text="Label" GridPane.rowIndex="5" />
<Label fx:id="day7_label" alignment="CENTER" prefHeight="35.0" prefWidth="173.0" text="Label" GridPane.rowIndex="6" />
<Pane fx:id="day1_pane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" />
<Pane fx:id="day2_pane" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Pane fx:id="day3_pane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Pane fx:id="day4_pane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Pane fx:id="day5_pane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Pane fx:id="day6_pane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" />
<Pane fx:id="day7_pane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="6" />
</children>
</GridPane>
<Pane prefHeight="119.0" prefWidth="575.0" VBox.vgrow="NEVER">
<children>
<Label alignment="TOP_LEFT" layoutX="14.0" layoutY="14.0" prefHeight="17.0" prefWidth="550.0" text="Importants Information:" wrapText="true">
<font>
@ -38,9 +65,6 @@
</Label>
<Label fx:id="information_label" alignment="TOP_LEFT" layoutX="14.0" layoutY="31.0" maxWidth="1.7976931348623157E308" prefHeight="82.0" prefWidth="550.0" text="Label" wrapText="true" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</Pane>
</children>
</VBox>

View File

@ -9,7 +9,9 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="259.0" prefWidth="390.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TaskFormularController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="259.0" prefWidth="390.0" xmlns="http://javafx.com/javafx/17"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TaskFormularController">
<children>
<VBox layoutX="14.0" layoutY="14.0" prefHeight="272.0" prefWidth="390.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding>
@ -25,7 +27,7 @@
<HBox prefHeight="77.0" prefWidth="350.0">
<children>
<Label maxWidth="1.7976931348623157E308" text="Description:" HBox.hgrow="ALWAYS" />
<TextArea fx:id="description_area" prefHeight="73.0" prefWidth="206.0" promptText="Description" wrapText="true" />
<TextArea fx:id="description_area" prefHeight="73.0" prefWidth="206.0" promptText="Description" />
</children>
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="30.0" layoutY="30.0" prefHeight="35.0" prefWidth="560.0">

View File

@ -1,25 +1,6 @@
/*
#home_button, #myGarden_button,
#mySchedule_button, #settings_button,
#tutorial_button, #menu_pane {
-fx-text-fill: white;
-fx-background-color: rgb(0,128,0);
}
#menubar {
-fx-background-color: rgb(0,128,0);
}
#home_button:hover, #myGarden_button:hover,
#mySchedule_button:hover, #settings_button:hover,
#tutorial_button:hover,
#home_button:focused, #myGarden_button:focused,
#mySchedule_button:focused, #settings_button:focused,
#tutorial_button:focused{
-fx-background-color: darkgreen;
}
.root, .split-pane {
-fx-background-color: linear-gradient(green 0%, lawngreen 33%, lightgreen 66%, #eee 100%);
}./
.button{
-fx-text-fill: rgb(49, 89, 23);
-fx-border-color: rgb(49, 89, 23);
-fx-border-radius: 5;
-fx-padding: 3 6 6 6;
}

View File

@ -14,11 +14,6 @@
"measures": "Less water."
}
],
"wateringCycle": {
"litersPerSqM": 25,
"interval": null,
"notes": []
},
"lifecycle": [
{
"startDate": "03-10",
@ -26,6 +21,11 @@
"type": "SOW",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": []
},
"taskTemplates": [
{
"name": "Germinate",
@ -42,6 +42,11 @@
"type": "PLANT",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 25,
"interval": 7,
"notes": []
},
"taskTemplates": [
{
"name": "hilling",
@ -58,6 +63,11 @@
"type": "HARVEST",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": []
},
"taskTemplates": [
{
"name": "Harvest",
@ -75,11 +85,6 @@
"name": "Early Carrot",
"description": "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.",
"image": "carrot.jpg",
"wateringCycle": {
"litersPerSqM": 15,
"interval": 3,
"notes": []
},
"lifecycle": [
{
"startDate": "02-20",
@ -87,7 +92,11 @@
"zone": "ZONE_8A",
"type": "SOW",
"group": 0,
"wateringCycle": {
"litersPerSqM": 15,
"interval": 3,
"notes": []
},
"taskTemplates": [
{
"name": "hilling",
@ -104,6 +113,13 @@
"zone": "ZONE_8A",
"type": "PLANT",
"group": 0,
"wateringCycle": {
"litersPerSqM": 25,
"interval": 3,
"notes": [
"Be careful not to pour water over the leaves, as this will lead to sunburn."
]
},
"taskTemplates": [
{
"name": "hilling",
@ -120,6 +136,11 @@
"zone": "ZONE_8A",
"type": "HARVEST",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": []
},
"taskTemplates": [
{
"name": "Harvesting",
@ -146,12 +167,6 @@
"name": "Summertime Onion",
"description": "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.",
"image": "onion.jpg",
"wateringCycle": {
"litersPerSqM": 15,
"interval": 4,
"notes": [
]
},
"lifecycle": [
{
"startDate": "03-15",
@ -159,6 +174,12 @@
"type": "SOW",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 15,
"interval": 4,
"notes": [
]
},
"taskTemplates": [
{
"name": "Plant Sets",
@ -175,6 +196,13 @@
"type": "PLANT",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 25,
"interval": 3,
"notes": [
""
]
},
"taskTemplates": [
{
"name": "hilling",
@ -191,6 +219,12 @@
"type": "HARVEST",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": [
]
},
"taskTemplates": [
{
"name": "Harvesting",
@ -211,86 +245,5 @@
"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": 1
}
]
},
{
"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
}
]
}
]
}
]

View File

@ -30,7 +30,6 @@ public class JsonCropListTest {
*/
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 corruptTestFile = this.getClass().getResource("corrupt-template-user-crops.json");
@BeforeEach
void connectToDb() throws URISyntaxException, IOException {
@ -102,13 +101,5 @@ public class JsonCropListTest {
throw new RuntimeException(e);
}
}
@Test
void detectCorruptJsonResource(){
JsonCropList tL = new JsonCropList(corruptTestFile);
Assertions.assertThrows(InvalidJsonException.class, () -> {
tL.getCrops();
});
}
}

View File

@ -15,7 +15,6 @@ import java.util.Optional;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class JsonPlantListTest {
private final URL testFile = this.getClass().getResource("test-plantdb.json");
@ -63,8 +62,6 @@ public class JsonPlantListTest {
void getPlantByIdAndZone() {
Optional<Plant> testPlant;
try {
assertThrows(HardinessZoneNotSetException.class, () -> testDatabase.getPlantById(null,1).get());
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
} catch (IOException | HardinessZoneNotSetException 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);
}
}
}

View File

@ -2,8 +2,6 @@ package ch.zhaw.gartenverwaltung.io;
import ch.zhaw.gartenverwaltung.types.Task;
import org.junit.jupiter.api.*;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import java.io.IOException;
import java.net.URISyntaxException;
@ -16,8 +14,6 @@ import java.time.format.DateTimeFormatter;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
public class JsonTaskListTest {
@ -51,16 +47,17 @@ public class JsonTaskListTest {
}
@Disabled("disabled until adding works.")
@Test
@DisplayName("Add task.")
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 {
testDatabase.saveTask(task);
List<Task> taskList;
try {
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
LocalDate.parse("2022-05-31", formatter));
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -75,7 +72,8 @@ public class JsonTaskListTest {
@Test
@DisplayName("Remove task.")
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 {
testDatabase.removeTask(task);
List<Task> taskList;
@ -104,7 +102,7 @@ public class JsonTaskListTest {
}
@Disabled("Disabled until removing works")
@Test
void removeTasksForCrop() {
List<Task> taskList;
@ -117,27 +115,4 @@ public class JsonTaskListTest {
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());
}
}

View File

@ -49,12 +49,11 @@ public class GardenPlanModelTest {
0,
"sandy to loamy, loose soil, free of stones",
new ArrayList<>(),
new WateringCycle(15, 0, null),
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(8, 5), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(8, 5), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.of(2023, 3, 1))
.withId(3);
@ -67,8 +66,7 @@ public class GardenPlanModelTest {
0,
"sandy to loamy, loose soil, free of stones",
new ArrayList<>(),
new WateringCycle(25, 0, null),
List.of(new GrowthPhase(MonthDay.of(4, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
List.of(new GrowthPhase(MonthDay.of(4, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
exampleCropCarrot = new Crop(examplePlantCarrot.id(), LocalDate.now())
.withId(5);

View File

@ -7,14 +7,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.time.LocalDate;
import java.time.MonthDay;
import java.time.format.DateTimeFormatter;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
@ -94,13 +88,12 @@ class GardenScheduleTest {
0,
"sandy to loamy, loose soil, free of stones",
new ArrayList<>(),
new WateringCycle(15, 0, null),
List.of(
new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, List.of(
new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, List.of(
exampleTaskTemplateList.get(0),
exampleTaskTemplateList.get(1)
)),
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, List.of(
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, List.of(
exampleTaskTemplateList.get(2),
exampleTaskTemplateList.get(3)
))
@ -194,7 +187,7 @@ class GardenScheduleTest {
}
@Test
void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException, URISyntaxException {
void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException {
model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30));
verify(exampleTaskTemplateList.get(0), times(1)).generateTask(exampleStartDate, 30);
verify(exampleTaskTemplateList.get(1), times(1)).generateTask(exampleStartDate, 30);
@ -204,18 +197,5 @@ class GardenScheduleTest {
verify(taskList, times(1)).saveTask(exampleTaskList.get(1));
verify(taskList, times(1)).saveTask(exampleTaskList.get(2));
verify(taskList, times(1)).saveTask(exampleTaskList.get(3));
final URL dbDataSource = this.getClass().getResource("test-taskdb.json");
final URL testFile = this.getClass().getResource("template-taskdb.json");
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
JsonTaskList testTaskList = new JsonTaskList(dbDataSource);
model = spy(new GardenSchedule(testTaskList,plantList));
model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30));
assertEquals(5,testTaskList.getTaskList(LocalDate.MIN,LocalDate.MAX).size());
testTaskList.getTaskList(LocalDate.MIN,LocalDate.MAX).get(0);
}
}

View File

@ -49,12 +49,11 @@ class PlantListModelTest {
0,
"sandy to loamy, loose soil, free of stones",
new ArrayList<>(),
new WateringCycle(25, 0, null),
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(8, 5), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())))
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(8, 5), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())))
);
examplePlantList.add(new Plant(
0,
@ -65,9 +64,8 @@ class PlantListModelTest {
6,
"sandy",
new ArrayList<>(),
new WateringCycle(0, 0, null),
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())))
List.of(new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())))
);
examplePlantList.add(new Plant(
1,
@ -78,8 +76,7 @@ class PlantListModelTest {
0,
"sandy to loamy, loose soil, free of stones",
new ArrayList<>(),
new WateringCycle(25, 0, null),
List.of(new GrowthPhase(MonthDay.of(4, 4), MonthDay.of(12, 4), 0, GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())))
List.of(new GrowthPhase(MonthDay.of(4, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())))
);
}

View File

@ -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));
}
}

View File

@ -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());
}
}

View File

@ -1,7 +0,0 @@
[
{
"plantId": 1,
"startDate": "2023-02-25",
"area": 0.5
}
]

View File

@ -1,215 +0,0 @@
[
{
"id": 0,
"name": "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."
}
],
"wateringCycle": {
"litersPerSqM": 25,
"interval": null,
"notes": []
},
"lifecycle": [
{
"startDate": "03-10",
"endDate": "04-10",
"type": "SOW",
"zone": "ZONE_8A",
"group": 0,
"taskTemplates": [
{
"name": "Germinate",
"relativeStartDate": -14,
"relativeEndDate": null,
"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": "04-10",
"endDate": "07-10",
"type": "PLANT",
"zone": "ZONE_8A",
"group": 0,
"taskTemplates": [
{
"name": "hilling",
"relativeStartDate": 0,
"relativeEndDate": null,
"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": 21
}
]
},
{
"startDate": "06-10",
"endDate": "08-10",
"type": "HARVEST",
"zone": "ZONE_8A",
"group": 0,
"taskTemplates": [
{
"name": "Harvest",
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.",
"interval": null
}
]
}
]
},
{
"id": 1,
"name": "Early Carrot",
"description": "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.",
"image": "carrot.jpg",
"wateringCycle": {
"litersPerSqM": 15,
"interval": 3,
"notes": []
},
"lifecycle": [
{
"startDate": "02-20",
"endDate": "03-10",
"zone": "ZONE_8A",
"type": "SOW",
"group": 0,
"taskTemplates": [
{
"name": "hilling",
"relativeStartDate": 0,
"relativeEndDate": 0,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": null
}
]
},
{
"startDate": "03-10",
"endDate": "05-10",
"zone": "ZONE_8A",
"type": "PLANT",
"group": 0,
"taskTemplates": [
{
"name": "hilling",
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": 15
}
]
},
{
"startDate": "05-10",
"endDate": "05-20",
"zone": "ZONE_8A",
"type": "HARVEST",
"group": 0,
"taskTemplates": [
{
"name": "Harvesting",
"relativeStartDate": 0,
"relativeEndDate": 14,
"description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.",
"interval": null
}
]
}
],
"soil": "sandy to loamy, loose soil, free of stones",
"spacing": "5,35,2.5",
"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"
}
]
},
{
"id": 2,
"name": "Summertime Onion",
"description": "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.",
"image": "onion.jpg",
"wateringCycle": {
"litersPerSqM": 15,
"interval": 4,
"notes": [
]
},
"lifecycle": [
{
"startDate": "03-15",
"endDate": "04-10",
"type": "SOW",
"zone": "ZONE_8A",
"group": 0,
"taskTemplates": [
{
"name": "Plant Sets",
"relativeStartDate": 0,
"relativeEndDate": 0,
"description": "Plant the sets about 5cm deep into the soil.",
"interval": null
}
]
},
{
"startDate": "04-10",
"endDate": "07-10",
"type": "PLANT",
"zone": "ZONE_8A",
"group": 0,
"taskTemplates": [
{
"name": "hilling",
"relativeStartDate": 0,
"relativeEndDate": null,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": 15
}
]
},
{
"startDate": "07-10",
"endDate": "09-20",
"type": "HARVEST",
"zone": "ZONE_8A",
"group": 0,
"taskTemplates": [
{
"name": "Harvesting",
"relativeStartDate": 0,
"relativeEndDate": 14,
"description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter",
"interval": null
}
]
}
],
"soil": "sandy to loamy, loose soil, free of stones",
"spacing": "15,30,2",
"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"
}
]
}
]

View File

@ -14,11 +14,6 @@
"measures": "Less water."
}
],
"wateringCycle": {
"litersPerSqM": 25,
"interval": null,
"notes": []
},
"lifecycle": [
{
"startDate": "03-10",
@ -26,6 +21,11 @@
"type": "SOW",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": []
},
"taskTemplates": [
{
"name": "Germinate",
@ -42,6 +42,11 @@
"type": "PLANT",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 25,
"interval": 7,
"notes": []
},
"taskTemplates": [
{
"name": "hilling",
@ -58,6 +63,11 @@
"type": "HARVEST",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": []
},
"taskTemplates": [
{
"name": "Harvest",
@ -75,11 +85,6 @@
"name": "Early Carrot",
"description": "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.",
"image": "carrot.jpg",
"wateringCycle": {
"litersPerSqM": 15,
"interval": 3,
"notes": []
},
"lifecycle": [
{
"startDate": "02-20",
@ -87,7 +92,11 @@
"zone": "ZONE_8A",
"type": "SOW",
"group": 0,
"wateringCycle": {
"litersPerSqM": 15,
"interval": 3,
"notes": []
},
"taskTemplates": [
{
"name": "hilling",
@ -104,6 +113,13 @@
"zone": "ZONE_8A",
"type": "PLANT",
"group": 0,
"wateringCycle": {
"litersPerSqM": 25,
"interval": 3,
"notes": [
"Be careful not to pour water over the leaves, as this will lead to sunburn."
]
},
"taskTemplates": [
{
"name": "hilling",
@ -120,6 +136,11 @@
"zone": "ZONE_8A",
"type": "HARVEST",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": []
},
"taskTemplates": [
{
"name": "Harvesting",
@ -146,12 +167,6 @@
"name": "Summertime Onion",
"description": "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.",
"image": "onion.jpg",
"wateringCycle": {
"litersPerSqM": 15,
"interval": 4,
"notes": [
]
},
"lifecycle": [
{
"startDate": "03-15",
@ -159,12 +174,19 @@
"type": "SOW",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 15,
"interval": 4,
"notes": [
]
},
"taskTemplates": [
{
"name": "Plant Sets",
"name": "hilling",
"relativeStartDate": 0,
"relativeEndDate": 0,
"description": "Plant the sets about 5cm deep into the soil.",
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": null
}
]
@ -175,6 +197,13 @@
"type": "PLANT",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 25,
"interval": 3,
"notes": [
""
]
},
"taskTemplates": [
{
"name": "hilling",
@ -191,6 +220,13 @@
"type": "HARVEST",
"zone": "ZONE_8A",
"group": 0,
"wateringCycle": {
"litersPerSqM": 0,
"interval": null,
"notes": [
]
},
"taskTemplates": [
{
"name": "Harvesting",