Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0959f535b |
@@ -87,7 +87,7 @@ public class CropDetailController {
|
|||||||
private ListView<Pest> pests_listView;
|
private ListView<Pest> pests_listView;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void addTask() throws IOException, HardinessZoneNotSetException {
|
void addTask() throws IOException {
|
||||||
createTaskDialog(true, null);
|
createTaskDialog(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ public class CropDetailController {
|
|||||||
if (plant.image() != null) {
|
if (plant.image() != null) {
|
||||||
imageView.setImage(plant.image());
|
imageView.setImage(plant.image());
|
||||||
}
|
}
|
||||||
area_label.setText(String.valueOf(crop.getArea()));
|
area_label.setText("");
|
||||||
location_label.setText("");
|
location_label.setText("");
|
||||||
|
|
||||||
setTaskListProperty(crop);
|
setTaskListProperty(crop);
|
||||||
@@ -255,7 +255,7 @@ public class CropDetailController {
|
|||||||
return (event) -> {
|
return (event) -> {
|
||||||
try {
|
try {
|
||||||
createTaskDialog(false, task);
|
createTaskDialog(false, task);
|
||||||
} catch (IOException | HardinessZoneNotSetException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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<Task> dialog = new Dialog<>();
|
||||||
dialog.setTitle("Set Task");
|
dialog.setTitle("Set Task");
|
||||||
dialog.setHeaderText("Add/Edit Task:");
|
dialog.setHeaderText("Add/Edit Task:");
|
||||||
@@ -289,7 +289,7 @@ public class CropDetailController {
|
|||||||
if (!newTask) {
|
if (!newTask) {
|
||||||
controller.setTaskValue(givenTask);
|
controller.setTaskValue(givenTask);
|
||||||
}
|
}
|
||||||
dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult(this.crop) : null);
|
dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult() : null);
|
||||||
|
|
||||||
dialog.showAndWait()
|
dialog.showAndWait()
|
||||||
.ifPresent(task -> {
|
.ifPresent(task -> {
|
||||||
@@ -334,11 +334,8 @@ public class CropDetailController {
|
|||||||
//ToDo method to set location
|
//ToDo method to set location
|
||||||
location_label.setText(string);
|
location_label.setText(string);
|
||||||
} else {
|
} else {
|
||||||
try {
|
System.out.println(string);
|
||||||
garden.updateCrop(this.crop.withArea(Double.parseDouble(string)));
|
//ToDo method to set area of crop in garden
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
area_label.setText(string);
|
area_label.setText(string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
|
|
||||||
public class HelloController {
|
|
||||||
@FXML
|
|
||||||
private Label welcomeText;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected void onHelloButtonClick() {
|
|
||||||
welcomeText.setText("Welcome to JavaFX Application!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -51,6 +51,7 @@ public class MyGardenController {
|
|||||||
@AfterInject
|
@AfterInject
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void init() {
|
public void init() {
|
||||||
|
System.out.println("once");
|
||||||
setIconToButton(addPlant_button, "addIcon.png");
|
setIconToButton(addPlant_button, "addIcon.png");
|
||||||
myGarden_listView.itemsProperty().bind(garden.getPlantedCrops());
|
myGarden_listView.itemsProperty().bind(garden.getPlantedCrops());
|
||||||
setCellFactory();
|
setCellFactory();
|
||||||
|
|||||||
@@ -1,35 +1,23 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
|
import javafx.beans.binding.Binding;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.BooleanBinding;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class TaskFormularController implements Initializable {
|
public class TaskFormularController implements Initializable {
|
||||||
private Crop crop;
|
private Crop crop;
|
||||||
private Plant plant;
|
|
||||||
private Task task = null;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private GardenSchedule gardenSchedule;
|
|
||||||
@Inject
|
|
||||||
private Garden garden;
|
|
||||||
@Inject
|
|
||||||
private PlantList plantList;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea description_area;
|
private TextArea description_area;
|
||||||
@@ -46,28 +34,19 @@ public class TaskFormularController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private TextField taskName_field;
|
private TextField taskName_field;
|
||||||
|
|
||||||
@AfterInject
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
|
|
||||||
public Task returnResult(Crop crop) {
|
public Task returnResult() {
|
||||||
int interval = 0;
|
|
||||||
if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) {
|
|
||||||
interval = Integer.parseInt(interval_field.getText());
|
|
||||||
}
|
|
||||||
Task task = new Task(taskName_field.getText(), description_area.getText(),
|
Task task = new Task(taskName_field.getText(), description_area.getText(),
|
||||||
start_datePicker.getValue(), end_datePicker.getValue(),
|
start_datePicker.getValue(), end_datePicker.getValue(),
|
||||||
interval, crop.getCropId().get());
|
Integer.parseInt(interval_field.getText()), crop.getCropId().get());
|
||||||
if (this.task != null) return this.task.updateTask(task);
|
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCorp(Crop crop) throws HardinessZoneNotSetException, IOException {
|
public void setCorp(Crop crop) {
|
||||||
this.crop = crop;
|
this.crop = crop;
|
||||||
this.plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTaskValue(Task task) {
|
public void setTaskValue(Task task) {
|
||||||
this.task = task;
|
|
||||||
taskName_field.setText(task.getName());
|
taskName_field.setText(task.getName());
|
||||||
description_area.setText(task.getDescription());
|
description_area.setText(task.getDescription());
|
||||||
start_datePicker.setValue(task.getStartDate());
|
start_datePicker.setValue(task.getStartDate());
|
||||||
@@ -90,7 +69,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
setDisable(true);
|
setDisable(true);
|
||||||
setStyle("-fx-background-color: #ffc0cb;");
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
|
||||||
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) {
|
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
@@ -114,7 +93,7 @@ public class TaskFormularController implements Initializable {
|
|||||||
setDisable(true);
|
setDisable(true);
|
||||||
setStyle("-fx-background-color: #ffc0cb;");
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
|
||||||
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) {
|
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
@@ -135,8 +114,12 @@ public class TaskFormularController implements Initializable {
|
|||||||
});
|
});
|
||||||
|
|
||||||
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
||||||
|
.or(end_datePicker.valueProperty().isNull())
|
||||||
.or(taskName_field.textProperty().isEmpty())
|
.or(taskName_field.textProperty().isEmpty())
|
||||||
.or(description_area.textProperty().isEmpty()));
|
.or(description_area.textProperty().isEmpty())
|
||||||
|
.or(interval_field.textProperty().isEmpty()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,15 +27,6 @@ public class TextFieldFormularController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initSaveButton(Button button) {
|
public void initSaveButton(Button button) {
|
||||||
text_area.textProperty().addListener((observable, oldValue, newValue) -> {
|
|
||||||
if (newValue.matches("\\d*\\.?\\d*")) {
|
|
||||||
text_area.setText(newValue);
|
|
||||||
} else {
|
|
||||||
text_area.setText(oldValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotates a method to be executed after all dependencies annotates with {@link Inject}
|
* Annotates a method to be executed after all dependencies annotated with {@link Inject}
|
||||||
* have been injected.
|
* have been injected.
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class responsible for bootstrapping the application wide dependencies
|
||||||
|
* and injecting them into JavaFX Controllers.
|
||||||
|
*/
|
||||||
public class AppLoader {
|
public class AppLoader {
|
||||||
/**
|
/**
|
||||||
* Caching the panes
|
* Caching the panes
|
||||||
@@ -32,17 +36,24 @@ public class AppLoader {
|
|||||||
/**
|
/**
|
||||||
* Application-wide dependencies
|
* Application-wide dependencies
|
||||||
*/
|
*/
|
||||||
private final PlantList plantList = new JsonPlantList();
|
private final Map<String, Object> dependencies = new HashMap<>();
|
||||||
private final CropList cropList = new JsonCropList();
|
|
||||||
private final TaskList taskList = new JsonTaskList();
|
|
||||||
|
|
||||||
private final GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
|
|
||||||
private final Garden garden = new Garden(gardenSchedule, cropList);
|
|
||||||
|
|
||||||
|
|
||||||
public AppLoader() throws IOException {
|
public AppLoader() throws IOException {
|
||||||
}
|
PlantList plantList = new JsonPlantList();
|
||||||
|
CropList cropList = new JsonCropList();
|
||||||
|
TaskList taskList = new JsonTaskList();
|
||||||
|
GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
|
||||||
|
|
||||||
|
dependencies.put(PlantList.class.getSimpleName(), plantList);
|
||||||
|
dependencies.put(CropList.class.getSimpleName(), cropList);
|
||||||
|
dependencies.put(TaskList.class.getSimpleName(), taskList);
|
||||||
|
|
||||||
|
dependencies.put(PlantListModel.class.getSimpleName(), new PlantListModel(plantList));
|
||||||
|
|
||||||
|
dependencies.put(GardenSchedule.class.getSimpleName(), gardenSchedule);
|
||||||
|
dependencies.put(Garden.class.getSimpleName(), new Garden(gardenSchedule, cropList));
|
||||||
|
dependencies.put(AppLoader.class.getSimpleName(), this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and returns a {@link Pane} (cached).
|
* Loads and returns a {@link Pane} (cached).
|
||||||
@@ -135,26 +146,18 @@ public class AppLoader {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Arrays.stream(controller.getClass().getMethods())
|
Arrays.stream(controller.getClass().getMethods())
|
||||||
.filter(method -> method.isAnnotationPresent(AfterInject.class))
|
.filter(method -> method.isAnnotationPresent(AfterInject.class) && method.getParameterCount() == 0)
|
||||||
.forEach(afterInjectMethod -> {
|
.forEach(afterInjectMethod -> {
|
||||||
if (afterInjectMethod.getParameterCount() == 0) {
|
try {
|
||||||
try {
|
afterInjectMethod.invoke(controller);
|
||||||
afterInjectMethod.invoke(controller);
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
// TODO: Log
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getAppDependency(Class<?> type) {
|
private Object getAppDependency(Class<?> type) {
|
||||||
return switch (type.getSimpleName()) {
|
return dependencies.get(type.getSimpleName());
|
||||||
case "Garden" -> garden;
|
|
||||||
case "PlantList" -> plantList;
|
|
||||||
case "PlantListModel" -> new PlantListModel(plantList);
|
|
||||||
case "GardenSchedule" -> gardenSchedule;
|
|
||||||
case "AppLoader" -> this;
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,20 @@ package ch.zhaw.gartenverwaltung.bootstrap;
|
|||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.event.EventType;
|
import javafx.event.EventType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an event that should lead to a view being changed.
|
||||||
|
*/
|
||||||
public class ChangeViewEvent extends Event {
|
public class ChangeViewEvent extends Event {
|
||||||
private final String view;
|
private final String view;
|
||||||
|
|
||||||
public static final EventType<ChangeViewEvent> CHANGE_MAIN_VIEW = new EventType<>("CHANGE_MAIN_VIEW");
|
public static final EventType<ChangeViewEvent> CHANGE_MAIN_VIEW = new EventType<>("CHANGE_MAIN_VIEW");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an Event that should lead to the main view being changed.
|
||||||
|
*
|
||||||
|
* @param eventType The {@link EventType<ChangeViewEvent>} specifying which view should be changed.
|
||||||
|
* @param view The filename of the View to be changed to
|
||||||
|
*/
|
||||||
public ChangeViewEvent(EventType<? extends Event> eventType, String view) {
|
public ChangeViewEvent(EventType<? extends Event> eventType, String view) {
|
||||||
super(eventType);
|
super(eventType);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotates a Field to be injected from the application-dependencies
|
* Annotates a Field to be injected from the application-dependencies.
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a List of {@link Crop}s.
|
||||||
|
* The interface specifies the operations to add/update and remove entries.
|
||||||
|
*/
|
||||||
public interface CropList {
|
public interface CropList {
|
||||||
/**
|
/**
|
||||||
* Yields a list of all {@link Crop}s in the database.
|
* Yields a list of all {@link Crop}s in the database.
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package ch.zhaw.gartenverwaltung.io;
|
package ch.zhaw.gartenverwaltung.io;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an sequential ID starting from the given initial Value.
|
||||||
|
*/
|
||||||
public class IdProvider {
|
public class IdProvider {
|
||||||
private long currentId;
|
private long currentId;
|
||||||
public IdProvider(long initialValue) {
|
public IdProvider(long initialValue) {
|
||||||
currentId = initialValue;
|
currentId = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yields the next ID in the sequence.
|
||||||
|
* @return The next ID
|
||||||
|
*/
|
||||||
public long incrementAndGet() {
|
public long incrementAndGet() {
|
||||||
return ++currentId;
|
return ++currentId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the {@link CropList} interface for reading and writing {@link Crop} objects
|
||||||
|
* from and to a local JSON file.
|
||||||
|
* The reads are cached to minimize file-io operations.
|
||||||
|
*/
|
||||||
public class JsonCropList implements CropList {
|
public class JsonCropList implements CropList {
|
||||||
private final URL dataSource;
|
private final URL dataSource;
|
||||||
|
|
||||||
@@ -40,7 +45,7 @@ public class JsonCropList implements CropList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor. Uses a file from the app resources.
|
||||||
*/
|
*/
|
||||||
public JsonCropList() {
|
public JsonCropList() {
|
||||||
this.dataSource = getClass().getResource("user-crops.json");
|
this.dataSource = getClass().getResource("user-crops.json");
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link PlantList} interface for loading {@link Plant} objects
|
* Implements the {@link PlantList} interface for reading {@link Plant} objects
|
||||||
* from a JSON file.
|
* from a local JSON file.
|
||||||
* The reads are cached to minimize file-io operations.
|
* The reads are cached to minimize file-io operations.
|
||||||
*/
|
*/
|
||||||
public class JsonPlantList implements PlantList {
|
public class JsonPlantList implements PlantList {
|
||||||
@@ -44,9 +44,17 @@ public class JsonPlantList implements PlantList {
|
|||||||
imageModule.addDeserializer(Image.class, new PlantImageDeserializer());
|
imageModule.addDeserializer(Image.class, new PlantImageDeserializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor. Uses a file from the app resources.
|
||||||
|
*/
|
||||||
public JsonPlantList() {
|
public JsonPlantList() {
|
||||||
this.dataSource = getClass().getResource("plantdb.json");
|
this.dataSource = getClass().getResource("plantdb.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to use a specified {@link URL} as a {@link #dataSource}
|
||||||
|
* @param dataSource A {@link URL} to the file to be used as a data source
|
||||||
|
*/
|
||||||
public JsonPlantList(URL dataSource) {
|
public JsonPlantList(URL dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
@@ -67,7 +75,7 @@ public class JsonPlantList implements PlantList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see PlantList#getPlantById(long)
|
* @see PlantList#getPlantById(HardinessZone, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws HardinessZoneNotSetException, IOException {
|
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws HardinessZoneNotSetException, IOException {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link TaskList} interface for loading and writing {@link Task} objects
|
* Implements the {@link TaskList} interface for reading and writing {@link Task} objects
|
||||||
* from and to a JSON file.
|
* from and to a local JSON file.
|
||||||
* The reads are cached to minimize file-io operations.
|
* The reads are cached to minimize file-io operations.
|
||||||
*/
|
*/
|
||||||
public class JsonTaskList implements TaskList {
|
public class JsonTaskList implements TaskList {
|
||||||
@@ -45,9 +45,17 @@ public class JsonTaskList implements TaskList {
|
|||||||
timeModule.addSerializer(LocalDate.class, dateSerializer);
|
timeModule.addSerializer(LocalDate.class, dateSerializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor. Uses a file from the app resources.
|
||||||
|
*/
|
||||||
public JsonTaskList() {
|
public JsonTaskList() {
|
||||||
this.dataSource = getClass().getResource("taskdb.json");
|
this.dataSource = getClass().getResource("taskdb.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to use a specified {@link URL} as a {@link #dataSource}
|
||||||
|
* @param dataSource A {@link URL} to the file to be used as a data source
|
||||||
|
*/
|
||||||
public JsonTaskList(URL dataSource) {
|
public JsonTaskList(URL dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A database of {@link Plant}s.
|
* A List of {@link Plant}s.
|
||||||
* The interface specifies the minimal required operations.
|
* The interface specifies the minimal required operations.
|
||||||
*/
|
*/
|
||||||
public interface PlantList {
|
public interface PlantList {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import java.time.LocalDate;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A database of {@link Task}s.
|
* Represents a List of {@link Task}s.
|
||||||
* The interface specifies the minimal required operations.
|
* The interface specifies the operations to add/update and remove entries.
|
||||||
*/
|
*/
|
||||||
public interface TaskList {
|
public interface TaskList {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the Jackson Library to deserialize a String to a {@link GrowthPhaseType}
|
||||||
|
*/
|
||||||
public class GrowthPhaseTypeDeserializer extends StdDeserializer<GrowthPhaseType> {
|
public class GrowthPhaseTypeDeserializer extends StdDeserializer<GrowthPhaseType> {
|
||||||
public GrowthPhaseTypeDeserializer(Class<?> vc) {
|
public GrowthPhaseTypeDeserializer(Class<?> vc) {
|
||||||
super(vc);
|
super(vc);
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the Jackson Library to deserialize a String to a {@link HardinessZone}
|
||||||
|
*/
|
||||||
public class HardinessZoneDeserializer extends StdDeserializer<HardinessZone> {
|
public class HardinessZoneDeserializer extends StdDeserializer<HardinessZone> {
|
||||||
public HardinessZoneDeserializer(Class<?> vc) {
|
public HardinessZoneDeserializer(Class<?> vc) {
|
||||||
super(vc);
|
super(vc);
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import java.io.InputStream;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the Jackson Library to deserialize a String to a {@link Image}
|
||||||
|
*/
|
||||||
public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -70,19 +70,6 @@ public class Garden {
|
|||||||
plantedCrops.clear();
|
plantedCrops.clear();
|
||||||
plantedCrops.addAll(cropList.getCrops());
|
plantedCrops.addAll(cropList.getCrops());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the {@link Crop} from the file and the cache
|
|
||||||
*
|
|
||||||
* @param crop The crop which is being updated
|
|
||||||
* @throws IOException If the database cannot be accessed
|
|
||||||
*/
|
|
||||||
public void updateCrop(Crop crop) throws IOException {
|
|
||||||
cropList.saveCrop(crop);
|
|
||||||
plantedCrops.clear();
|
|
||||||
plantedCrops.addAll(cropList.getCrops());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public class Task {
|
public class Task {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private final String name;
|
||||||
private String description;
|
private final String description;
|
||||||
private LocalDate startDate;
|
private final LocalDate startDate;
|
||||||
private Integer interval;
|
private Integer interval;
|
||||||
private LocalDate endDate;
|
private LocalDate endDate;
|
||||||
private LocalDate nextExecution;
|
private LocalDate nextExecution;
|
||||||
@@ -103,14 +103,4 @@ public class Task {
|
|||||||
public Optional<LocalDate> getEndDate() {
|
public Optional<LocalDate> getEndDate() {
|
||||||
return Optional.ofNullable(endDate);
|
return Optional.ofNullable(endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task updateTask(Task task) {
|
|
||||||
this.name = task.getName();
|
|
||||||
this.description = task.getDescription();
|
|
||||||
this.startDate = task.getStartDate();
|
|
||||||
this.endDate = task.getEndDate().orElse(null);
|
|
||||||
this.interval = task.getInterval().orElse(0);
|
|
||||||
this.cropId = task.getCropId();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class TaskTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Task generateTask(LocalDate realStartDate, long cropId) {
|
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate.plusDays(0);
|
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
|
||||||
|
|
||||||
if (interval == null) {
|
if (interval == null) {
|
||||||
this.interval = 0;
|
this.interval = 0;
|
||||||
|
|||||||
@@ -245,86 +245,5 @@
|
|||||||
"measures": "less water"
|
"measures": "less water"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Test Potato",
|
|
||||||
"description": "The potato is a tuber, round or oval, with small white roots called 'eyes', that are growth buds. The size varies depending on the variety; the colour of the skin can be white, yellow or even purple.",
|
|
||||||
"light": 6,
|
|
||||||
"spacing": "35",
|
|
||||||
"soil": "sandy",
|
|
||||||
"image": "potato.jpg",
|
|
||||||
"pests": [
|
|
||||||
{
|
|
||||||
"name": "Rot",
|
|
||||||
"description": "Rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.",
|
|
||||||
"measures": "Less water."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"lifecycle": [
|
|
||||||
{
|
|
||||||
"startDate": "12-01",
|
|
||||||
"endDate": "12-02",
|
|
||||||
"type": "SOW",
|
|
||||||
"zone": "ZONE_8A",
|
|
||||||
"group": 0,
|
|
||||||
"wateringCycle": {
|
|
||||||
"litersPerSqM": 0,
|
|
||||||
"interval": null,
|
|
||||||
"notes": []
|
|
||||||
},
|
|
||||||
"taskTemplates": [
|
|
||||||
{
|
|
||||||
"name": "Germinate",
|
|
||||||
"relativeStartDate": -3,
|
|
||||||
"relativeEndDate": 0,
|
|
||||||
"description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.",
|
|
||||||
"interval": null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"startDate": "12-03",
|
|
||||||
"endDate": "12-15",
|
|
||||||
"type": "PLANT",
|
|
||||||
"zone": "ZONE_8A",
|
|
||||||
"group": 0,
|
|
||||||
"wateringCycle": {
|
|
||||||
"litersPerSqM": 25,
|
|
||||||
"interval": 7,
|
|
||||||
"notes": []
|
|
||||||
},
|
|
||||||
"taskTemplates": [
|
|
||||||
{
|
|
||||||
"name": "hilling",
|
|
||||||
"relativeStartDate": 0,
|
|
||||||
"relativeEndDate": 10,
|
|
||||||
"description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.",
|
|
||||||
"interval": 3
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"startDate": "12-16",
|
|
||||||
"endDate": "12-18",
|
|
||||||
"type": "HARVEST",
|
|
||||||
"zone": "ZONE_8A",
|
|
||||||
"group": 0,
|
|
||||||
"wateringCycle": {
|
|
||||||
"litersPerSqM": 0,
|
|
||||||
"interval": null,
|
|
||||||
"notes": []
|
|
||||||
},
|
|
||||||
"taskTemplates": [
|
|
||||||
{
|
|
||||||
"name": "Harvest",
|
|
||||||
"relativeStartDate": 0,
|
|
||||||
"relativeEndDate": 4,
|
|
||||||
"description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.",
|
|
||||||
"interval": null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user