Compare commits
No commits in common. "6d24687f7bb633d40b634965e49727e5340a293b" and "e22cb0b24d3745d988b2f6fcd80e84b40ff2d1b4" have entirely different histories.
6d24687f7b
...
e22cb0b24d
|
@ -87,7 +87,7 @@ public class CropDetailController {
|
|||
private ListView<Pest> pests_listView;
|
||||
|
||||
@FXML
|
||||
void addTask() throws IOException, HardinessZoneNotSetException {
|
||||
void addTask() throws IOException {
|
||||
createTaskDialog(true, null);
|
||||
}
|
||||
|
||||
|
@ -136,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);
|
||||
|
@ -255,7 +255,7 @@ public class CropDetailController {
|
|||
return (event) -> {
|
||||
try {
|
||||
createTaskDialog(false, task);
|
||||
} catch (IOException | HardinessZoneNotSetException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
@ -267,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:");
|
||||
|
@ -289,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 -> {
|
||||
|
@ -334,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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,9 +11,6 @@ import javafx.scene.image.Image;
|
|||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
@ -43,9 +40,6 @@ public class MainFXMLController {
|
|||
@FXML
|
||||
private Button tutorial_button;
|
||||
|
||||
private final Stage tutorialModal = new Stage();
|
||||
|
||||
|
||||
/**
|
||||
* go to home pane
|
||||
*/
|
||||
|
@ -101,23 +95,11 @@ public class MainFXMLController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Show the tutorial window
|
||||
* go to Tutorial pane
|
||||
*/
|
||||
public void showTutorial() {
|
||||
if (!tutorialModal.isShowing()) {
|
||||
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();
|
||||
public void goToTutorial() {
|
||||
showPaneAsMainView("Tutorial.fxml");
|
||||
styleChangeButton(tutorial_button);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,6 +132,7 @@ public class MainFXMLController {
|
|||
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
||||
appLoader.loadAndCacheFxml("MySchedule.fxml");
|
||||
appLoader.loadAndCacheFxml("Plants.fxml");
|
||||
appLoader.loadAndCacheFxml("Tutorial.fxml");
|
||||
}
|
||||
|
||||
private void styleChangeButton(Button button) {
|
||||
|
@ -170,14 +153,12 @@ public class MainFXMLController {
|
|||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, "Failed to load FXML-Pane!", e);
|
||||
}
|
||||
mainPane.getScene().getWindow().setOnCloseRequest(this::closeWindowHandler);
|
||||
setIconToButton(home_button, "homeIcon.png");
|
||||
setIconToButton(settings_button, "settingsIcon.png");
|
||||
tutorial_button.visibleProperty().bind(Settings.getInstance().getShowTutorialProperty());
|
||||
}
|
||||
|
||||
private void closeWindowHandler(WindowEvent windowEvent) {
|
||||
tutorialModal.close();
|
||||
Settings.getInstance().getShowTutorialProperty().addListener((observable, oldValue, newValue) -> {
|
||||
tutorial_button.setVisible(newValue);
|
||||
});
|
||||
tutorial_button.setVisible(Settings.getInstance().getShowTutorial());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -192,4 +173,7 @@ public class MainFXMLController {
|
|||
imageView.setPreserveRatio(true);
|
||||
button.setGraphic(imageView);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,61 +1,6 @@
|
|||
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 {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.net.URISyntaxException;
|
|||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -30,7 +29,6 @@ public class JsonTaskList implements TaskList {
|
|||
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
||||
|
||||
private Map<Long, Task> taskMap = Collections.emptyMap();
|
||||
private final List<TaskListObserver> subscribers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creating constant objects required to deserialize the {@link LocalDate} classes
|
||||
|
@ -89,7 +87,6 @@ public class JsonTaskList implements TaskList {
|
|||
loadTaskListFromFile();
|
||||
}
|
||||
taskMap.values().removeIf(task -> task.getCropId() == cropId);
|
||||
notifySubscribers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +107,6 @@ public class JsonTaskList implements TaskList {
|
|||
|
||||
taskMap.put(id, task.withId(id));
|
||||
writeTaskListToFile();
|
||||
notifySubscribers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,25 +126,6 @@ public class JsonTaskList implements TaskList {
|
|||
taskMap.remove(taskId);
|
||||
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,22 +51,4 @@ public interface TaskList {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.time.LocalDate;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GardenSchedule {
|
||||
|
@ -20,7 +19,6 @@ public class GardenSchedule {
|
|||
* Comparators to create sorted Task List
|
||||
*/
|
||||
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
||||
static final Comparator<Task> sortByNextExecution = Comparator.comparing(Task::getNextExecution);
|
||||
|
||||
/**
|
||||
* Constructor to create Database Objects.
|
||||
|
@ -48,8 +46,7 @@ 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());
|
||||
for (GrowthPhase growthPhase : plant.lifecycleForGroup(growPhaseGroup)) {
|
||||
for (GrowthPhase growthPhase : plant.lifecycle()) {
|
||||
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
|
||||
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
||||
}
|
||||
|
@ -138,22 +135,10 @@ public class GardenSchedule {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
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<>();
|
||||
for(int i = 0; i < listLength; i++) {
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
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)));
|
||||
});
|
||||
dayTaskList.add(taskList.getTaskList(date, date));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
@ -164,8 +149,11 @@ public class GardenSchedule {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
||||
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
|
||||
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
|
||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
||||
|
@ -177,7 +165,7 @@ public class GardenSchedule {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Task> getFilteredTaskList(LocalDate start, LocalDate end) throws IOException {
|
||||
return getSortedTaskList(taskList.getTaskList(start, end), sortByNextExecution);
|
||||
return getSortedTaskList(taskList.getTaskList(start, end), sortByStartDate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,16 +39,6 @@ public record Plant(
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getGrowphaseGroupForDate(LocalDate date) {
|
||||
for(GrowthPhase growthPhase : lifecycle){
|
||||
MonthDay plantingDate = MonthDay.of(date.getMonth().getValue(), date.getDayOfMonth());
|
||||
if(plantingDate.isAfter(growthPhase.startDate()) && plantingDate.isBefore(growthPhase.endDate())){
|
||||
return growthPhase.group();
|
||||
}
|
||||
}
|
||||
return 0; // TODO implement
|
||||
}
|
||||
|
||||
/**
|
||||
* get sow date from given harvest day from lifecycle group
|
||||
* @param harvestDate date of the harvest
|
||||
|
|
|
@ -10,13 +10,11 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -27,16 +25,12 @@ public class Task {
|
|||
name= "";
|
||||
description= "";
|
||||
startDate = LocalDate.now();
|
||||
endDate = startDate;
|
||||
nextExecution = startDate;
|
||||
}
|
||||
|
||||
public Task(String name, String description, LocalDate startDate, long cropId) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.startDate = startDate;
|
||||
this.endDate = startDate;
|
||||
nextExecution = startDate;
|
||||
this.cropId = cropId;
|
||||
}
|
||||
|
||||
|
@ -44,7 +38,6 @@ public class Task {
|
|||
this.name = name;
|
||||
this.description = description;
|
||||
this.startDate = startDate;
|
||||
nextExecution = startDate;
|
||||
this.endDate = endDate;
|
||||
this.interval = interval;
|
||||
this.cropId = cropId;
|
||||
|
@ -65,32 +58,10 @@ public class Task {
|
|||
}
|
||||
|
||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
||||
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||
}
|
||||
|
||||
public void done(){
|
||||
if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){
|
||||
nextExecution = nextExecution.plusDays(interval);
|
||||
} else {
|
||||
nextExecution = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone(){
|
||||
return nextExecution == null;
|
||||
}
|
||||
|
||||
public void setNextExecution(LocalDate nextExecution) {
|
||||
this.nextExecution = nextExecution;
|
||||
}
|
||||
|
||||
public void setNextNotification(LocalDate nextNotification) {
|
||||
this.nextNotification = nextNotification;
|
||||
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||
}
|
||||
|
||||
// Getters
|
||||
public LocalDate getNextNotification() { return nextNotification; }
|
||||
public LocalDate getNextExecution() { return nextExecution; }
|
||||
public Optional<Long> getId() { return Optional.ofNullable(id); }
|
||||
public String getName() { return name; }
|
||||
public String getDescription() { return description; }
|
||||
|
@ -103,14 +74,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ public class TaskTemplate {
|
|||
@JsonProperty
|
||||
private Integer interval;
|
||||
|
||||
// TODO: reconsider if we need this
|
||||
@JsonProperty
|
||||
private boolean isOptional = false;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
* (Used by deserializer)
|
||||
|
@ -42,7 +46,7 @@ public class TaskTemplate {
|
|||
}
|
||||
|
||||
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate.plusDays(0);
|
||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
|
||||
|
||||
if (interval == null) {
|
||||
this.interval = 0;
|
||||
|
|
|
@ -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="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" />
|
||||
<Button fx:id="tutorial_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToTutorial" prefHeight="38.0" prefWidth="121.0" text="Tutorial" />
|
||||
<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>
|
||||
|
|
|
@ -1,141 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?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.control.Label?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?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">
|
||||
<bottom>
|
||||
<HBox alignment="CENTER" prefHeight="0.0" prefWidth="724.0" BorderPane.alignment="CENTER">
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17"
|
||||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TutorialController">
|
||||
<children>
|
||||
<CheckBox mnemonicParsing="false" text="Don't show again" />
|
||||
<Separator prefWidth="50.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||
<ButtonBar prefHeight="40.0" prefWidth="200.0">
|
||||
<buttons>
|
||||
<Button cancelButton="true" contentDisplay="CENTER" graphicTextGap="5.0" mnemonicParsing="false" text="Close" onAction="#closeTutorial"/>
|
||||
<Button fx:id="previousPageButton" mnemonicParsing="false" text="Previous" onAction="#viewPreviousPage"/>
|
||||
<Button fx:id="nextPageButton" defaultButton="true" mnemonicParsing="false" text="Next" onAction="#viewNextPage" />
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
<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">
|
||||
<children>
|
||||
<Label text="Tutorial">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="To be added" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</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>
|
||||
</children>
|
||||
<BorderPane.margin>
|
||||
<Insets />
|
||||
</BorderPane.margin>
|
||||
<padding>
|
||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||
</padding>
|
||||
</StackPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</AnchorPane>
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -53,7 +54,8 @@
|
|||
"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
|
||||
"interval": 21,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -74,7 +76,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -103,7 +106,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": 0,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": null
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -126,7 +130,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": null,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": 15
|
||||
"interval": 15,
|
||||
"isOptional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -147,7 +152,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -186,7 +192,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": 0,
|
||||
"description": "Plant the sets about 5cm deep into the soil.",
|
||||
"interval": null
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -209,7 +216,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": null,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": 15
|
||||
"interval": 15,
|
||||
"isOptional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -231,7 +239,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -245,86 +254,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": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"startDate": "12-16",
|
||||
"endDate": "12-18",
|
||||
"type": "HARVEST",
|
||||
"zone": "ZONE_8A",
|
||||
"group": 0,
|
||||
"wateringCycle": {
|
||||
"litersPerSqM": 0,
|
||||
"interval": null,
|
||||
"notes": []
|
||||
},
|
||||
"taskTemplates": [
|
||||
{
|
||||
"name": "Harvest",
|
||||
"relativeStartDate": 0,
|
||||
"relativeEndDate": 4,
|
||||
"description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.",
|
||||
"interval": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -4,10 +4,8 @@
|
|||
"name": "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate": "2022-05-01",
|
||||
"nextExecution": "2022-05-01",
|
||||
"nextNotification": "2022-05-01",
|
||||
"endDate": "2022-05-01",
|
||||
"interval": null,
|
||||
"interval": 0,
|
||||
"cropId": 0
|
||||
},
|
||||
{
|
||||
|
@ -15,8 +13,6 @@
|
|||
"name": "water plant",
|
||||
"description": "water the plant, so that the soil is wet around the plant.",
|
||||
"startDate": "2022-05-01",
|
||||
"nextExecution": "2022-05-01",
|
||||
"nextNotification": "2022-05-01",
|
||||
"endDate": "2022-09-01",
|
||||
"interval": 2,
|
||||
"cropId": 0
|
||||
|
@ -26,8 +22,6 @@
|
|||
"name": "fertilize plant",
|
||||
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
|
||||
"startDate": "2022-06-01",
|
||||
"nextExecution": "2022-06-01",
|
||||
"nextNotification": "2022-06-01",
|
||||
"endDate": "2022-08-01",
|
||||
"interval": 28,
|
||||
"cropId": 0
|
||||
|
@ -37,10 +31,8 @@
|
|||
"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",
|
||||
"startDate": "2022-07-01",
|
||||
"nextExecution": "2022-07-01",
|
||||
"nextNotification": "2022-07-01",
|
||||
"endDate": "2022-07-01",
|
||||
"interval": null,
|
||||
"interval": 0,
|
||||
"cropId": 0
|
||||
},
|
||||
{
|
||||
|
@ -48,8 +40,6 @@
|
|||
"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",
|
||||
"startDate": "2022-05-01",
|
||||
"nextExecution": "2022-05-01",
|
||||
"nextNotification": "2022-05-01",
|
||||
"endDate": "2022-09-01",
|
||||
"interval": 5,
|
||||
"cropId": 0
|
||||
|
@ -59,10 +49,8 @@
|
|||
"name": "harvest plant",
|
||||
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
||||
"startDate": "2022-09-01",
|
||||
"nextExecution": "2022-09-01",
|
||||
"nextNotification": "2022-09-01",
|
||||
"endDate": "2022-09-01",
|
||||
"interval": null,
|
||||
"interval": 0,
|
||||
"cropId": 0
|
||||
}
|
||||
]
|
|
@ -1,49 +1,38 @@
|
|||
package ch.zhaw.gartenverwaltung.models;
|
||||
package ch.zhaw.gartenverwaltung.taskList;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.MonthDay;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class GardenScheduleTest {
|
||||
LocalDate exampleStartDate = LocalDate.of(2020, 2, 2);
|
||||
TaskList taskList;
|
||||
PlantList plantList;
|
||||
List<Plant> examplePlantList;
|
||||
List<Task> exampleTaskList;
|
||||
List<TaskTemplate> exampleTaskTemplateList;
|
||||
Map<Long, Plant> examplePlantMap;
|
||||
GardenSchedule model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException, HardinessZoneNotSetException {
|
||||
void setUp() throws IOException {
|
||||
createExampleTaskList();
|
||||
createExampleTaskTemplateList();
|
||||
createExamplePlantList();
|
||||
taskList = mockTaskDatabase(exampleTaskList);
|
||||
plantList = mockPlantDatabase(examplePlantList);
|
||||
plantList = mockPlantDatabase(examplePlantMap);
|
||||
model = new GardenSchedule(taskList, plantList);
|
||||
}
|
||||
|
||||
PlantList mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||
PlantList plantDatabase = mock(JsonPlantList.class);
|
||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList);
|
||||
when(plantDatabase.getPlantById(HardinessZone.ZONE_8A,20)).thenReturn(Optional.of(examplePlantList.get(0)));
|
||||
return plantDatabase;
|
||||
}
|
||||
|
||||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||
TaskList taskList = mock(JsonTaskList.class);
|
||||
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)));
|
||||
|
||||
|
@ -65,39 +54,18 @@ class GardenScheduleTest {
|
|||
return taskList;
|
||||
}
|
||||
|
||||
void createExampleTaskTemplateList(){
|
||||
exampleTaskTemplateList = new ArrayList<>();
|
||||
exampleTaskTemplateList.add(mock(TaskTemplate.class));
|
||||
exampleTaskTemplateList.add(mock(TaskTemplate.class));
|
||||
exampleTaskTemplateList.add(mock(TaskTemplate.class));
|
||||
exampleTaskTemplateList.add(mock(TaskTemplate.class));
|
||||
when(exampleTaskTemplateList.get(0).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(0));
|
||||
when(exampleTaskTemplateList.get(1).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(1));
|
||||
when(exampleTaskTemplateList.get(2).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(2));
|
||||
when(exampleTaskTemplateList.get(3).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(3));
|
||||
private PlantList mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
||||
return new PlantList() {
|
||||
@Override
|
||||
public List<Plant> getPlantList(HardinessZone zone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
void createExamplePlantList(){
|
||||
examplePlantList = new ArrayList<>();
|
||||
examplePlantList.add(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<>(),
|
||||
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, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, List.of(
|
||||
exampleTaskTemplateList.get(2),
|
||||
exampleTaskTemplateList.get(3)
|
||||
))
|
||||
)));
|
||||
@Override
|
||||
public Optional<Plant> getPlantById(HardinessZone zone, long id) {
|
||||
return Optional.ofNullable(examplePlantMap.get(id));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void createExampleTaskList() {
|
||||
|
@ -106,9 +74,15 @@ class GardenScheduleTest {
|
|||
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.of(9019, 5, 5), 1L));
|
||||
exampleTaskList.add(new Task("name", "description", LocalDate.now().minusDays(10), LocalDate.now().plusDays(4),2, 2L));
|
||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L));
|
||||
}
|
||||
|
||||
void createExamplePlantMap() {
|
||||
examplePlantMap = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
void addTask() throws IOException {
|
||||
Task taskToAdd = new Task("name", "description", LocalDate.now(), 1L);
|
||||
|
@ -158,22 +132,19 @@ class GardenScheduleTest {
|
|||
assertEquals(7, dayList.size());
|
||||
|
||||
//Check day 0
|
||||
assertEquals(2, dayList.get(0).size());
|
||||
assertTrue(dayList.get(0).contains(exampleTaskList.get(2)));
|
||||
assertTrue(dayList.get(0).contains(exampleTaskList.get(4)));
|
||||
assertEquals(1, dayList.get(0).size());
|
||||
assertEquals(exampleTaskList.get(2), dayList.get(0).get(0));
|
||||
|
||||
//Check day 1
|
||||
assertEquals(1, dayList.get(1).size());
|
||||
assertTrue(dayList.get(1).contains(exampleTaskList.get(1)));
|
||||
assertEquals(exampleTaskList.get(1), dayList.get(1).get(0));
|
||||
|
||||
//Check day 2
|
||||
assertEquals(1, dayList.get(2).size());
|
||||
assertTrue(dayList.get(2).contains(exampleTaskList.get(4)));
|
||||
assertEquals(0, dayList.get(2).size());
|
||||
//Check day 3
|
||||
assertEquals(0, dayList.get(3).size());
|
||||
//Check day 4
|
||||
assertEquals(1, dayList.get(4).size());
|
||||
assertTrue(dayList.get(4).contains(exampleTaskList.get(4)));
|
||||
assertEquals(0, dayList.get(4).size());
|
||||
//Check day 5
|
||||
assertEquals(0, dayList.get(5).size());
|
||||
//Check day 6
|
||||
|
@ -185,17 +156,4 @@ class GardenScheduleTest {
|
|||
model.removeTasksForCrop(1L);
|
||||
verify(taskList, times(1)).removeTasksForCrop(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
verify(exampleTaskTemplateList.get(2), times(1)).generateTask(exampleStartDate, 30);
|
||||
verify(exampleTaskTemplateList.get(3), times(1)).generateTask(exampleStartDate, 30);
|
||||
verify(taskList, times(1)).saveTask(exampleTaskList.get(0));
|
||||
verify(taskList, times(1)).saveTask(exampleTaskList.get(1));
|
||||
verify(taskList, times(1)).saveTask(exampleTaskList.get(2));
|
||||
verify(taskList, times(1)).saveTask(exampleTaskList.get(3));
|
||||
}
|
||||
}
|
|
@ -32,7 +32,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -53,7 +54,8 @@
|
|||
"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
|
||||
"interval": 21,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -74,7 +76,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -103,7 +106,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": 0,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": null
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -126,7 +130,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": null,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": 15
|
||||
"interval": 15,
|
||||
"isOptional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -147,7 +152,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -187,7 +193,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": 0,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": null
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -210,7 +217,8 @@
|
|||
"relativeStartDate": 0,
|
||||
"relativeEndDate": null,
|
||||
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||
"interval": 15
|
||||
"interval": 15,
|
||||
"isOptional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -233,7 +241,8 @@
|
|||
"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
|
||||
"interval": null,
|
||||
"isOptional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue