Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dc2ad1774 | ||
|
|
e75ececedb | ||
|
|
560cea2ff9 | ||
|
|
4e720c2ddc | ||
|
|
77541c282c | ||
|
|
c79386ec88 | ||
|
|
f36826ef29 | ||
|
|
c9ba9c1234 | ||
|
|
04e4ea1dea | ||
|
|
1f049f86ab | ||
|
|
9b08113ff9 | ||
|
|
f389cfcdfd | ||
|
|
e22cb0b24d | ||
|
|
1c83fc4694 | ||
|
|
df19edb25a | ||
|
|
6b7a6f095d | ||
|
|
bcb36b89c7 |
@@ -104,16 +104,16 @@ public class CropDetailController {
|
|||||||
* open dialog to set area
|
* open dialog to set area
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void setArea() {
|
void setArea() throws IOException {
|
||||||
|
openTextFieldDialog("set Text Area", "Text Area", area_label.getText(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* open dialog to set location
|
* open dialog to set location
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void setLocation() {
|
void setLocation() throws IOException {
|
||||||
|
openTextFieldDialog("set Location", "Location", location_label.getText(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,6 +218,7 @@ public class CropDetailController {
|
|||||||
setIconToButton(edit, "editIcon.png");
|
setIconToButton(edit, "editIcon.png");
|
||||||
setIconToButton(delete, "deleteIcon.png");
|
setIconToButton(delete, "deleteIcon.png");
|
||||||
edit.setOnAction(getEditTaskEvent(task));
|
edit.setOnAction(getEditTaskEvent(task));
|
||||||
|
delete.setOnAction(deleteTask(task));
|
||||||
|
|
||||||
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
|
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
|
||||||
return hBox;
|
return hBox;
|
||||||
@@ -260,6 +261,12 @@ public class CropDetailController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EventHandler<ActionEvent> deleteTask(Task task) {
|
||||||
|
return (event) -> {
|
||||||
|
showDeleteTask(task);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
|
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
|
||||||
Dialog<Task> dialog = new Dialog<>();
|
Dialog<Task> dialog = new Dialog<>();
|
||||||
dialog.setTitle("Set Task");
|
dialog.setTitle("Set Task");
|
||||||
@@ -278,6 +285,7 @@ public class CropDetailController {
|
|||||||
|
|
||||||
if (appLoader.loadPaneToDialog("TaskFormular.fxml", dialogPane) instanceof TaskFormularController controller) {
|
if (appLoader.loadPaneToDialog("TaskFormular.fxml", dialogPane) instanceof TaskFormularController controller) {
|
||||||
controller.setCorp(this.crop);
|
controller.setCorp(this.crop);
|
||||||
|
controller.initSaveButton((Button) dialogPane.lookupButton(saveTask));
|
||||||
if (!newTask) {
|
if (!newTask) {
|
||||||
controller.setTaskValue(givenTask);
|
controller.setTaskValue(givenTask);
|
||||||
}
|
}
|
||||||
@@ -300,4 +308,56 @@ public class CropDetailController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openTextFieldDialog(String title, String labelDescription, String value, boolean isLocation) throws IOException {
|
||||||
|
Dialog<String> dialog = new Dialog<>();
|
||||||
|
dialog.setTitle(title);
|
||||||
|
dialog.setHeaderText(title);
|
||||||
|
dialog.setResizable(false);
|
||||||
|
|
||||||
|
DialogPane dialogPane = dialog.getDialogPane();
|
||||||
|
|
||||||
|
ButtonType save = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE);
|
||||||
|
dialogPane.getButtonTypes().addAll(save, ButtonType.CANCEL);
|
||||||
|
|
||||||
|
if (appLoader.loadPaneToDialog("TextFieldFormular.fxml", dialogPane) instanceof TextFieldFormularController controller) {
|
||||||
|
controller.setDescription_label(labelDescription);
|
||||||
|
controller.setValueTextArea(value);
|
||||||
|
controller.initSaveButton((Button) dialogPane.lookupButton(save));
|
||||||
|
|
||||||
|
dialog.setResultConverter(button -> button.equals(save) ? controller.getValue() : null);
|
||||||
|
|
||||||
|
dialog.showAndWait()
|
||||||
|
.ifPresent(string -> {
|
||||||
|
if (isLocation) {
|
||||||
|
System.out.println(string);
|
||||||
|
//ToDo method to set location
|
||||||
|
location_label.setText(string);
|
||||||
|
} else {
|
||||||
|
System.out.println(string);
|
||||||
|
//ToDo method to set area of crop in garden
|
||||||
|
area_label.setText(string);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showDeleteTask(Task task) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Delete " + task.getName());
|
||||||
|
alert.setHeaderText("Are you sure want to delete this Task?");
|
||||||
|
|
||||||
|
alert.showAndWait()
|
||||||
|
.ifPresent(buttonType -> {
|
||||||
|
if (buttonType == ButtonType.OK) {
|
||||||
|
try {
|
||||||
|
gardenSchedule.removeTask(task);
|
||||||
|
setTaskListProperty(this.crop);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO: Show error alert
|
||||||
|
LOG.log(Level.SEVERE, "Could not remove crop.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import javafx.scene.image.Image;
|
|||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.WindowEvent;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -40,6 +43,9 @@ public class MainFXMLController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button tutorial_button;
|
private Button tutorial_button;
|
||||||
|
|
||||||
|
private final Stage tutorialModal = new Stage();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* go to home pane
|
* go to home pane
|
||||||
*/
|
*/
|
||||||
@@ -95,11 +101,23 @@ public class MainFXMLController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* go to Tutorial pane
|
* Show the tutorial window
|
||||||
*/
|
*/
|
||||||
public void goToTutorial() {
|
public void showTutorial() {
|
||||||
showPaneAsMainView("Tutorial.fxml");
|
if (!tutorialModal.isShowing()) {
|
||||||
styleChangeButton(tutorial_button);
|
if (tutorialModal.getScene() == null) {
|
||||||
|
try {
|
||||||
|
appLoader.loadSceneToStage("Tutorial.fxml", tutorialModal);
|
||||||
|
tutorialModal.initModality(Modality.NONE);
|
||||||
|
tutorialModal.setResizable(false);
|
||||||
|
tutorialModal.sizeToScene();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.log(Level.SEVERE, "Could not load Tutorial");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tutorialModal.show();
|
||||||
|
}
|
||||||
|
tutorialModal.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +150,6 @@ public class MainFXMLController {
|
|||||||
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
||||||
appLoader.loadAndCacheFxml("MySchedule.fxml");
|
appLoader.loadAndCacheFxml("MySchedule.fxml");
|
||||||
appLoader.loadAndCacheFxml("Plants.fxml");
|
appLoader.loadAndCacheFxml("Plants.fxml");
|
||||||
appLoader.loadAndCacheFxml("Tutorial.fxml");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void styleChangeButton(Button button) {
|
private void styleChangeButton(Button button) {
|
||||||
@@ -153,12 +170,14 @@ public class MainFXMLController {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.log(Level.SEVERE, "Failed to load FXML-Pane!", e);
|
LOG.log(Level.SEVERE, "Failed to load FXML-Pane!", e);
|
||||||
}
|
}
|
||||||
|
mainPane.getScene().getWindow().setOnCloseRequest(this::closeWindowHandler);
|
||||||
setIconToButton(home_button, "homeIcon.png");
|
setIconToButton(home_button, "homeIcon.png");
|
||||||
setIconToButton(settings_button, "settingsIcon.png");
|
setIconToButton(settings_button, "settingsIcon.png");
|
||||||
Settings.getInstance().getShowTutorialProperty().addListener((observable, oldValue, newValue) -> {
|
tutorial_button.visibleProperty().bind(Settings.getInstance().getShowTutorialProperty());
|
||||||
tutorial_button.setVisible(newValue);
|
}
|
||||||
});
|
|
||||||
tutorial_button.setVisible(Settings.getInstance().getShowTutorial());
|
private void closeWindowHandler(WindowEvent windowEvent) {
|
||||||
|
tutorialModal.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,7 +192,4 @@ public class MainFXMLController {
|
|||||||
imageView.setPreserveRatio(true);
|
imageView.setPreserveRatio(true);
|
||||||
button.setGraphic(imageView);
|
button.setGraphic(imageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package ch.zhaw.gartenverwaltung;
|
|||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
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.DateCell;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.DatePicker;
|
|
||||||
import javafx.scene.control.TextArea;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -56,7 +58,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
private Callback<DatePicker, DateCell> getDayCellFactoryStartDate() {
|
||||||
|
|
||||||
return (datePicker) -> new DateCell() {
|
return (datePicker) -> new DateCell() {
|
||||||
private final LocalDate today = LocalDate.now();
|
private final LocalDate today = LocalDate.now();
|
||||||
@@ -71,16 +73,61 @@ public class TaskFormularController implements Initializable {
|
|||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (end_datePicker.getValue() != null && item.compareTo(end_datePicker.getValue()) > 0) {
|
||||||
|
setDisable(true);
|
||||||
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Callback<DatePicker, DateCell> getDayCellFactoryEndDate() {
|
||||||
|
|
||||||
|
return (datePicker) -> new DateCell() {
|
||||||
|
private final LocalDate today = LocalDate.now();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateItem(LocalDate item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
setDisable(true);
|
||||||
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
|
||||||
|
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
||||||
|
setDisable(false);
|
||||||
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_datePicker.getValue() != null && item.compareTo(start_datePicker.getValue()) < 0) {
|
||||||
|
setDisable(true);
|
||||||
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initSaveButton(Button button) {
|
||||||
|
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (!newValue.matches("\\d*")) {
|
||||||
|
interval_field.setText(newValue.replaceAll("[^\\d]", ""));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
||||||
|
.or(end_datePicker.valueProperty().isNull())
|
||||||
|
.or(taskName_field.textProperty().isEmpty())
|
||||||
|
.or(description_area.textProperty().isEmpty())
|
||||||
|
.or(interval_field.textProperty().isEmpty()));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
start_datePicker.setDayCellFactory(getDayCellFactory());
|
start_datePicker.setDayCellFactory(getDayCellFactoryStartDate());
|
||||||
start_datePicker.setEditable(false);
|
start_datePicker.setEditable(false);
|
||||||
|
|
||||||
end_datePicker.setDayCellFactory(getDayCellFactory());
|
end_datePicker.setDayCellFactory(getDayCellFactoryEndDate());
|
||||||
end_datePicker.setEditable(false);
|
end_datePicker.setEditable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class TextFieldFormularController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label description_label;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField text_area;
|
||||||
|
|
||||||
|
|
||||||
|
public void setDescription_label(String string) {
|
||||||
|
description_label.setText(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValueTextArea(String string) {
|
||||||
|
text_area.setText(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return text_area.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initSaveButton(Button button) {
|
||||||
|
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,61 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
public class TutorialController {
|
public class TutorialController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public Button previousPageButton;
|
||||||
|
@FXML
|
||||||
|
public Button nextPageButton;
|
||||||
|
@FXML
|
||||||
|
public StackPane tourPages;
|
||||||
|
public ImageView imgAddNewPlant;
|
||||||
|
public ImageView imgTaskList;
|
||||||
|
public ImageView imgSelectDate;
|
||||||
|
|
||||||
|
private int page = 0;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
switchViews();
|
||||||
|
setButtonAbilities();
|
||||||
|
|
||||||
|
Image placeholder = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||||
|
imgAddNewPlant.setImage(placeholder);
|
||||||
|
imgSelectDate.setImage(placeholder);
|
||||||
|
imgTaskList.setImage(placeholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void viewNextPage() {
|
||||||
|
page++;
|
||||||
|
switchViews();
|
||||||
|
setButtonAbilities();
|
||||||
|
}
|
||||||
|
public void viewPreviousPage() {
|
||||||
|
page--;
|
||||||
|
switchViews();
|
||||||
|
setButtonAbilities();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setButtonAbilities() {
|
||||||
|
previousPageButton.setDisable(page <= 0);
|
||||||
|
nextPageButton.setDisable(page >= tourPages.getChildren().size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void switchViews() {
|
||||||
|
tourPages.getChildren().forEach(node -> node.setOpacity(0));
|
||||||
|
tourPages.getChildren().get(page).setOpacity(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeTutorial() {
|
||||||
|
Stage root = (Stage) tourPages.getScene().getWindow();
|
||||||
|
root.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,10 @@ public class AppLoader {
|
|||||||
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
|
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
|
||||||
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
||||||
Pane root = loader.load();
|
Pane root = loader.load();
|
||||||
appendee.setScene(new Scene(root));
|
Scene scene = new Scene(root);
|
||||||
|
String css = Objects.requireNonNull(this.getClass().getResource("styles.css")).toExternalForm();
|
||||||
|
appendee.setScene(scene);
|
||||||
|
scene.getStylesheets().add(css);
|
||||||
Object controller = loader.getController();
|
Object controller = loader.getController();
|
||||||
annotationInject(controller);
|
annotationInject(controller);
|
||||||
return controller;
|
return controller;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,6 +30,7 @@ public class JsonTaskList implements TaskList {
|
|||||||
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
||||||
|
|
||||||
private Map<Long, Task> taskMap = Collections.emptyMap();
|
private Map<Long, Task> taskMap = Collections.emptyMap();
|
||||||
|
private final List<TaskListObserver> subscribers = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creating constant objects required to deserialize the {@link LocalDate} classes
|
* Creating constant objects required to deserialize the {@link LocalDate} classes
|
||||||
@@ -86,7 +88,9 @@ public class JsonTaskList implements TaskList {
|
|||||||
if(taskMap.isEmpty()) {
|
if(taskMap.isEmpty()) {
|
||||||
loadTaskListFromFile();
|
loadTaskListFromFile();
|
||||||
}
|
}
|
||||||
taskMap.values().removeIf(task -> task.getCropId() == cropId);
|
taskMap.entrySet().removeIf(entry -> entry.getValue().getCropId() == cropId);
|
||||||
|
writeTaskListToFile();
|
||||||
|
notifySubscribers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,6 +111,7 @@ public class JsonTaskList implements TaskList {
|
|||||||
|
|
||||||
taskMap.put(id, task.withId(id));
|
taskMap.put(id, task.withId(id));
|
||||||
writeTaskListToFile();
|
writeTaskListToFile();
|
||||||
|
notifySubscribers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +131,25 @@ public class JsonTaskList implements TaskList {
|
|||||||
taskMap.remove(taskId);
|
taskMap.remove(taskId);
|
||||||
writeTaskListToFile();
|
writeTaskListToFile();
|
||||||
}
|
}
|
||||||
|
notifySubscribers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* @param observer The change handler
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void subscribe(TaskListObserver observer) {
|
||||||
|
subscribers.add(observer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the change handler method on all registered observers.
|
||||||
|
*/
|
||||||
|
private void notifySubscribers() {
|
||||||
|
for (TaskListObserver subscriber : subscribers) {
|
||||||
|
subscriber.onChange(taskMap.values().stream().toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,4 +51,22 @@ public interface TaskList {
|
|||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
void removeTask(Task task) throws IOException;
|
void removeTask(Task task) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers an observer to be notified of Changes in the TaskList
|
||||||
|
* @param observer The change handler
|
||||||
|
*/
|
||||||
|
void subscribe(TaskListObserver observer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies an observer for a TaskList
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
interface TaskListObserver {
|
||||||
|
/**
|
||||||
|
* Method which will be called when changes occur.
|
||||||
|
* @param newTaskList The new values
|
||||||
|
*/
|
||||||
|
void onChange(List<Task> newTaskList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.time.LocalDate;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class GardenSchedule {
|
public class GardenSchedule {
|
||||||
@@ -19,6 +20,7 @@ public class GardenSchedule {
|
|||||||
* Comparators to create sorted Task List
|
* Comparators to create sorted Task List
|
||||||
*/
|
*/
|
||||||
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
||||||
|
static final Comparator<Task> sortByNextExecution = Comparator.comparing(Task::getNextExecution);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to create Database Objects.
|
* Constructor to create Database Objects.
|
||||||
@@ -136,10 +138,22 @@ public class GardenSchedule {
|
|||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<List<Task>> getTasksUpcomingWeek() throws IOException {
|
public List<List<Task>> getTasksUpcomingWeek() throws IOException {
|
||||||
|
final int listLength = 7;
|
||||||
|
List<Task> weekTasks = taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(listLength - 1));
|
||||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < listLength; i++) {
|
||||||
LocalDate date = LocalDate.now().plusDays(i);
|
LocalDate date = LocalDate.now().plusDays(i);
|
||||||
dayTaskList.add(taskList.getTaskList(date, date));
|
dayTaskList.add(new ArrayList<>());
|
||||||
|
final int finalI = i;
|
||||||
|
weekTasks.forEach(task -> {
|
||||||
|
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;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
@@ -150,11 +164,8 @@ public class GardenSchedule {
|
|||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
||||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
|
||||||
for(int i = 0; i < 7; i++) {
|
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
|
||||||
LocalDate date = LocalDate.now().plusDays(i);
|
|
||||||
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
|
|
||||||
}
|
|
||||||
return dayTaskList;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +177,7 @@ public class GardenSchedule {
|
|||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<Task> getFilteredTaskList(LocalDate start, LocalDate end) throws IOException {
|
public List<Task> getFilteredTaskList(LocalDate start, LocalDate end) throws IOException {
|
||||||
return getSortedTaskList(taskList.getTaskList(start, end), sortByStartDate);
|
return getSortedTaskList(taskList.getTaskList(start, end), sortByNextExecution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package ch.zhaw.gartenverwaltung.notifier;
|
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class Notifier implements Runnable{
|
|
||||||
private final GardenSchedule gardenSchedule;
|
|
||||||
|
|
||||||
public Notifier(GardenSchedule gardenSchedule) {
|
|
||||||
this.gardenSchedule = gardenSchedule;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendNotification(Task task){
|
|
||||||
// TODO implement
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
gardenSchedule.getTaskList().forEach(new Consumer<Task>() {
|
|
||||||
@Override
|
|
||||||
public void accept(Task task) {
|
|
||||||
if(task.getNextNotification() != null && task.getNextNotification().isBefore(LocalDate.now().minusDays(1))){
|
|
||||||
sendNotification(task);
|
|
||||||
task.setNextNotification(task.getNextExecution());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Logger
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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(harvest.startDate().atYear(currentYear), sow.startDate().atYear(currentYear));
|
return (int) DAYS.between(sow.startDate().atYear(currentYear),harvest.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"),
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class Task {
|
|||||||
name= "";
|
name= "";
|
||||||
description= "";
|
description= "";
|
||||||
startDate = LocalDate.now();
|
startDate = LocalDate.now();
|
||||||
|
endDate = startDate;
|
||||||
nextExecution = startDate;
|
nextExecution = startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ public class Task {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
|
this.endDate = startDate;
|
||||||
nextExecution = startDate;
|
nextExecution = startDate;
|
||||||
this.cropId = cropId;
|
this.cropId = cropId;
|
||||||
}
|
}
|
||||||
@@ -63,16 +65,14 @@ public class Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
||||||
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void done(){
|
public void done(){
|
||||||
if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){
|
if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){
|
||||||
nextExecution = nextExecution.plusDays(interval);
|
nextExecution = nextExecution.plusDays(interval);
|
||||||
nextNotification = nextExecution;
|
|
||||||
} else {
|
} else {
|
||||||
nextExecution = null;
|
nextExecution = null;
|
||||||
nextNotification = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ 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) : null;
|
||||||
|
|
||||||
|
if (interval == null) {
|
||||||
|
this.interval = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
|
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
|
||||||
.withInterval(interval)
|
.withInterval(interval)
|
||||||
.withEndDate(endDate);
|
.withEndDate(endDate);
|
||||||
|
|||||||
@@ -13,6 +13,4 @@ module ch.zhaw.gartenverwaltung {
|
|||||||
exports ch.zhaw.gartenverwaltung.types;
|
exports ch.zhaw.gartenverwaltung.types;
|
||||||
exports ch.zhaw.gartenverwaltung.models;
|
exports ch.zhaw.gartenverwaltung.models;
|
||||||
exports ch.zhaw.gartenverwaltung.json;
|
exports ch.zhaw.gartenverwaltung.json;
|
||||||
exports ch.zhaw.gartenverwaltung.notifier;
|
|
||||||
opens ch.zhaw.gartenverwaltung.notifier to javafx.fxml;
|
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<Button fx:id="home_button" mnemonicParsing="false" onAction="#goToHome" prefHeight="38.0" prefWidth="40.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="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="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="#goToTutorial" prefHeight="38.0" prefWidth="121.0" text="Tutorial" />
|
<Button fx:id="tutorial_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#showTutorial" prefHeight="38.0" prefWidth="121.0" text="Tutorial" />
|
||||||
<Pane maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
|
<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" />
|
<Button fx:id="settings_button" maxHeight="1.7976931348623157E308" mnemonicParsing="false" onAction="#openSettings" prefHeight="38.0" prefWidth="40.0" HBox.hgrow="NEVER" />
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
|
||||||
|
|
||||||
|
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="64.0" prefWidth="298.0" xmlns="http://javafx.com/javafx/17"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TextFieldFormularController">
|
||||||
|
<children>
|
||||||
|
<HBox alignment="CENTER" layoutX="153.0" layoutY="33.0" prefHeight="100.0" prefWidth="200.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="description_label" maxWidth="1.7976931348623157E308" text="Label" HBox.hgrow="ALWAYS" />
|
||||||
|
<TextField fx:id="text_area" HBox.hgrow="NEVER" />
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
@@ -1,27 +1,141 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.control.ButtonBar?>
|
||||||
|
<?import javafx.scene.control.CheckBox?>
|
||||||
|
<?import javafx.scene.control.Separator?>
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
<?import javafx.scene.text.Text?>
|
||||||
|
<?import javafx.scene.text.TextFlow?>
|
||||||
|
|
||||||
|
<BorderPane maxHeight="470.0" maxWidth="724.0" minHeight="470.0" minWidth="724.0" prefHeight="470.0" prefWidth="724.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TutorialController">
|
||||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17"
|
<bottom>
|
||||||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TutorialController">
|
<HBox alignment="CENTER" prefHeight="0.0" prefWidth="724.0" BorderPane.alignment="CENTER">
|
||||||
<children>
|
<children>
|
||||||
<VBox layoutX="7.0" layoutY="8.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<CheckBox mnemonicParsing="false" text="Don't show again" />
|
||||||
<children>
|
<Separator prefWidth="50.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||||
<Label text="Tutorial">
|
<ButtonBar prefHeight="40.0" prefWidth="200.0">
|
||||||
<font>
|
<buttons>
|
||||||
<Font size="18.0" />
|
<Button cancelButton="true" contentDisplay="CENTER" graphicTextGap="5.0" mnemonicParsing="false" text="Close" onAction="#closeTutorial"/>
|
||||||
</font>
|
<Button fx:id="previousPageButton" mnemonicParsing="false" text="Previous" onAction="#viewPreviousPage"/>
|
||||||
</Label>
|
<Button fx:id="nextPageButton" defaultButton="true" mnemonicParsing="false" text="Next" onAction="#viewNextPage" />
|
||||||
<Label text="To be added" />
|
</buttons>
|
||||||
|
</ButtonBar>
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
|
||||||
</padding>
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
</bottom>
|
||||||
|
<center>
|
||||||
|
<StackPane fx:id="tourPages" prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||||
|
<children>
|
||||||
|
<VBox layoutX="30.0" layoutY="26.0" opacity="0.0" prefHeight="200.0" prefWidth="100.0">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Managing Your Crops">
|
||||||
|
<font>
|
||||||
|
<Font size="24.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Separator prefWidth="200.0">
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets bottom="15.0" top="10.0" />
|
||||||
|
</VBox.margin>
|
||||||
|
</Separator>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="In the "My Garden" tab, you can see all of the plants you're planning on growing.">
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets bottom="20.0" />
|
||||||
|
</VBox.margin>
|
||||||
|
</Text>
|
||||||
|
<HBox prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<TextFlow lineSpacing="4.0" prefHeight="90.0" prefWidth="500.0">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="To get started, click on the "Add new Plant" button in the bottom left. This will open a list of all the plants you can grow. Use the search bar at the top, the filters on the left, or simply browse the list until you've found a plant you want to grow in your garden." wrappingWidth="345.80316162109375" />
|
||||||
|
</children>
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets bottom="20.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
</TextFlow>
|
||||||
|
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||||
|
<ImageView fx:id="imgAddNewPlant" fitHeight="98.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<TextFlow lineSpacing="4.0" prefHeight="200.0" prefWidth="500.0">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Once you've found what you're looking for, click the "Select Sow/Harvest Date" button at the bottom of the window. In the subsequently shown dialog, you can select the date you'd like to sow or harvest the crop. The date selector shows possible dates in green. Confirm your selection with the "Save" button." />
|
||||||
|
</children>
|
||||||
|
</TextFlow>
|
||||||
|
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||||
|
<ImageView fx:id="imgSelectDate" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
<opaqueInsets>
|
||||||
|
<Insets />
|
||||||
|
</opaqueInsets>
|
||||||
|
</VBox>
|
||||||
|
<VBox prefHeight="200.0" prefWidth="100.0">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Managing Your Tasks">
|
||||||
|
<font>
|
||||||
|
<Font size="24.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Separator prefWidth="200.0">
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets bottom="15.0" top="10.0" />
|
||||||
|
</VBox.margin>
|
||||||
|
</Separator>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="In the "My Schedule" tab, you can see all of the tasks you need to complete for a successful harvest.">
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets bottom="20.0" />
|
||||||
|
</VBox.margin>
|
||||||
|
</Text>
|
||||||
|
<HBox prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<TextFlow lineSpacing="4.0" prefHeight="90.0" prefWidth="500.0">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="You can view the tasks for a specific crop by selecting it from the left sidebar. To see all tasks again, click the "Clear Filter" button at the bottom." wrappingWidth="345.80316162109375" />
|
||||||
|
</children>
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets bottom="20.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
</TextFlow>
|
||||||
|
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||||
|
<ImageView fx:id="imgTaskList" fitHeight="98.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<TextFlow lineSpacing="4.0" prefHeight="200.0" prefWidth="500.0">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="You can also add your own custom tasks, by clicking the "Add Task" button. In the subsequently shown dialog, you can enter the corresponding details. Note: If you want to make a task recurring, you need to set both an interval (in days) AND an end date, so the task won't repeat for all eternity." />
|
||||||
|
</children>
|
||||||
|
</TextFlow>
|
||||||
|
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||||
|
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
|
||||||
|
</children></HBox>
|
||||||
|
</children>
|
||||||
|
<opaqueInsets>
|
||||||
|
<Insets />
|
||||||
|
</opaqueInsets>
|
||||||
</VBox>
|
</VBox>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
<BorderPane.margin>
|
||||||
|
<Insets />
|
||||||
|
</BorderPane.margin>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||||
|
</padding>
|
||||||
|
</StackPane>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
.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;
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ 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 {
|
||||||
@@ -101,5 +102,13 @@ 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,6 +15,7 @@ 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");
|
||||||
@@ -62,6 +63,8 @@ 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);
|
||||||
@@ -95,5 +98,16 @@ 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,6 +2,8 @@ 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;
|
||||||
@@ -14,6 +16,8 @@ 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 {
|
||||||
|
|
||||||
@@ -47,17 +51,16 @@ 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("01.05.2022", formatter), 1);
|
Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("2022-05-01", formatter), 1);
|
||||||
try {
|
try {
|
||||||
testDatabase.saveTask(task);
|
testDatabase.saveTask(task);
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
try {
|
try {
|
||||||
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
|
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
|
||||||
LocalDate.parse("31.05.2022", formatter));
|
LocalDate.parse("2022-05-31", formatter));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -72,8 +75,7 @@ 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)
|
Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1).withId(2);
|
||||||
.withId(2);
|
|
||||||
try {
|
try {
|
||||||
testDatabase.removeTask(task);
|
testDatabase.removeTask(task);
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
@@ -102,7 +104,7 @@ public class JsonTaskListTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Disabled until removing works")
|
|
||||||
@Test
|
@Test
|
||||||
void removeTasksForCrop() {
|
void removeTasksForCrop() {
|
||||||
List<Task> taskList;
|
List<Task> taskList;
|
||||||
@@ -115,4 +117,27 @@ 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
class GardenScheduleTest {
|
class GardenScheduleTest {
|
||||||
LocalDate exampleStartDate = LocalDate.of(2020, 02, 02);
|
LocalDate exampleStartDate = LocalDate.of(2020, 2, 2);
|
||||||
TaskList taskList;
|
TaskList taskList;
|
||||||
PlantList plantList;
|
PlantList plantList;
|
||||||
List<Plant> examplePlantList;
|
List<Plant> examplePlantList;
|
||||||
@@ -43,6 +43,7 @@ class GardenScheduleTest {
|
|||||||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||||
TaskList taskList = mock(JsonTaskList.class);
|
TaskList taskList = mock(JsonTaskList.class);
|
||||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||||
|
when(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7 - 1))).thenReturn(exampleTaskList);
|
||||||
|
|
||||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ class GardenScheduleTest {
|
|||||||
exampleTaskList.add(new Task("name", "description", LocalDate.now().plusDays(1), 2L));
|
exampleTaskList.add(new Task("name", "description", LocalDate.now().plusDays(1), 2L));
|
||||||
exampleTaskList.add(new Task("name", "description", LocalDate.now(), 1L));
|
exampleTaskList.add(new Task("name", "description", LocalDate.now(), 1L));
|
||||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(9019, 5, 5), 1L));
|
exampleTaskList.add(new Task("name", "description", LocalDate.of(9019, 5, 5), 1L));
|
||||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L));
|
exampleTaskList.add(new Task("name", "description", LocalDate.now().minusDays(10), LocalDate.now().plusDays(4),2, 2L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,19 +158,22 @@ class GardenScheduleTest {
|
|||||||
assertEquals(7, dayList.size());
|
assertEquals(7, dayList.size());
|
||||||
|
|
||||||
//Check day 0
|
//Check day 0
|
||||||
assertEquals(1, dayList.get(0).size());
|
assertEquals(2, dayList.get(0).size());
|
||||||
assertEquals(exampleTaskList.get(2), dayList.get(0).get(0));
|
assertTrue(dayList.get(0).contains(exampleTaskList.get(2)));
|
||||||
|
assertTrue(dayList.get(0).contains(exampleTaskList.get(4)));
|
||||||
|
|
||||||
//Check day 1
|
//Check day 1
|
||||||
assertEquals(1, dayList.get(1).size());
|
assertEquals(1, dayList.get(1).size());
|
||||||
assertEquals(exampleTaskList.get(1), dayList.get(1).get(0));
|
assertTrue(dayList.get(1).contains(exampleTaskList.get(1)));
|
||||||
|
|
||||||
//Check day 2
|
//Check day 2
|
||||||
assertEquals(0, dayList.get(2).size());
|
assertEquals(1, dayList.get(2).size());
|
||||||
|
assertTrue(dayList.get(2).contains(exampleTaskList.get(4)));
|
||||||
//Check day 3
|
//Check day 3
|
||||||
assertEquals(0, dayList.get(3).size());
|
assertEquals(0, dayList.get(3).size());
|
||||||
//Check day 4
|
//Check day 4
|
||||||
assertEquals(0, dayList.get(4).size());
|
assertEquals(1, dayList.get(4).size());
|
||||||
|
assertTrue(dayList.get(4).contains(exampleTaskList.get(4)));
|
||||||
//Check day 5
|
//Check day 5
|
||||||
assertEquals(0, dayList.get(5).size());
|
assertEquals(0, dayList.get(5).size());
|
||||||
//Check day 6
|
//Check day 6
|
||||||
@@ -184,6 +188,7 @@ 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);
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
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));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"plantId": 1,
|
||||||
|
"startDate": "2023-02-25",
|
||||||
|
"area": 0.5
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -4,8 +4,6 @@
|
|||||||
"name" : "sow plant",
|
"name" : "sow plant",
|
||||||
"description": "Plant the seeds, crops in de bed.",
|
"description": "Plant the seeds, crops in de bed.",
|
||||||
"startDate" : "2022-05-01",
|
"startDate" : "2022-05-01",
|
||||||
"nextExecution": "2022-05-01",
|
|
||||||
"nextNotification": "2022-05-01",
|
|
||||||
"endDate" : "2022-05-01",
|
"endDate" : "2022-05-01",
|
||||||
"interval" : 0,
|
"interval" : 0,
|
||||||
"cropId" : 0
|
"cropId" : 0
|
||||||
@@ -15,8 +13,6 @@
|
|||||||
"name" : "water plant",
|
"name" : "water plant",
|
||||||
"description": "water the plant, so that the soil is wet around the plant.",
|
"description": "water the plant, so that the soil is wet around the plant.",
|
||||||
"startDate" : "2022-05-01",
|
"startDate" : "2022-05-01",
|
||||||
"nextExecution": "2022-05-01",
|
|
||||||
"nextNotification": "2022-05-01",
|
|
||||||
"endDate" : "2022-09-01",
|
"endDate" : "2022-09-01",
|
||||||
"interval" : 2,
|
"interval" : 2,
|
||||||
"cropId" : 0
|
"cropId" : 0
|
||||||
@@ -26,8 +22,6 @@
|
|||||||
"name" : "fertilize plant",
|
"name" : "fertilize plant",
|
||||||
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
|
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
|
||||||
"startDate" : "2022-06-01",
|
"startDate" : "2022-06-01",
|
||||||
"nextExecution": "2022-05-01",
|
|
||||||
"nextNotification": "2022-05-01",
|
|
||||||
"endDate" : "2022-08-01",
|
"endDate" : "2022-08-01",
|
||||||
"interval" : 28,
|
"interval" : 28,
|
||||||
"cropId" : 0
|
"cropId" : 0
|
||||||
@@ -37,8 +31,6 @@
|
|||||||
"name" : "covering plant",
|
"name" : "covering plant",
|
||||||
"description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage",
|
"description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage",
|
||||||
"startDate" : "2022-07-01",
|
"startDate" : "2022-07-01",
|
||||||
"nextExecution": "2022-05-01",
|
|
||||||
"nextNotification": "2022-05-01",
|
|
||||||
"endDate" : "2022-07-01",
|
"endDate" : "2022-07-01",
|
||||||
"interval" : 0,
|
"interval" : 0,
|
||||||
"cropId" : 0
|
"cropId" : 0
|
||||||
@@ -48,8 +40,6 @@
|
|||||||
"name" : "look after plant",
|
"name" : "look after plant",
|
||||||
"description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil",
|
"description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil",
|
||||||
"startDate" : "2022-05-01",
|
"startDate" : "2022-05-01",
|
||||||
"nextExecution": "2022-05-01",
|
|
||||||
"nextNotification": "2022-05-01",
|
|
||||||
"endDate" : "2022-09-01",
|
"endDate" : "2022-09-01",
|
||||||
"interval" : 5,
|
"interval" : 5,
|
||||||
"cropId" : 0
|
"cropId" : 0
|
||||||
@@ -59,8 +49,6 @@
|
|||||||
"name" : "harvest plant",
|
"name" : "harvest plant",
|
||||||
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
||||||
"startDate" : "2022-09-01",
|
"startDate" : "2022-09-01",
|
||||||
"nextExecution": "2022-05-01",
|
|
||||||
"nextNotification": "2022-05-01",
|
|
||||||
"endDate" : "2022-09-01",
|
"endDate" : "2022-09-01",
|
||||||
"interval" : 0,
|
"interval" : 0,
|
||||||
"cropId" : 0
|
"cropId" : 0
|
||||||
|
|||||||
Reference in New Issue
Block a user