Compare commits
No commits in common. "2864c54c72e7b6c1645936d410f194173c762cc1" and "3bda390708a038c44df9bacbf689655c47236cef" have entirely different histories.
2864c54c72
...
3bda390708
|
@ -12,7 +12,6 @@ import ch.zhaw.gartenverwaltung.types.Crop;
|
|||
import ch.zhaw.gartenverwaltung.types.Pest;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
|
@ -134,14 +133,8 @@ public class CropDetailController {
|
|||
initializeTaskListProperty(crop);
|
||||
|
||||
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
||||
Platform.runLater(() -> {
|
||||
taskListProperty.clear();
|
||||
try {
|
||||
taskListProperty.addAll(gardenSchedule.getTaskListForCrop(crop.getCropId().get()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
};
|
||||
gardenSchedule.setTaskListObserver(taskListObserver);
|
||||
|
||||
|
|
|
@ -13,46 +13,30 @@ import javafx.stage.Stage;
|
|||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
|
||||
/**
|
||||
* Main class of the Application
|
||||
*/
|
||||
public class Main extends Application {
|
||||
Timer backGroundTaskTimer = new Timer();
|
||||
BackgroundTasks backgroundTasks;
|
||||
|
||||
/**
|
||||
* Method which is automatically called if Application is starting. It loads the scenes to stage and shows the stage.
|
||||
* It creates a new Instance of BackgroundTasks and schedules them with a Timer instance to execute them every minute.
|
||||
* @param stage Stage to show
|
||||
* @throws IOException If loading Scenes can not access the fxml Resource File
|
||||
*/
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
AppLoader appLoader = new AppLoader();
|
||||
|
||||
backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class));
|
||||
|
||||
appLoader.loadSceneToStage("MainFXML.fxml", stage);
|
||||
|
||||
stage.setTitle("Gartenverwaltung");
|
||||
stage.show();
|
||||
|
||||
backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class));
|
||||
backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 60000);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which is automatically called when application is stopped.
|
||||
* It cancels the timer to not execute the background tasks anymore.
|
||||
*/
|
||||
@Override
|
||||
public void stop(){
|
||||
backGroundTaskTimer.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Main method launches the application
|
||||
* @param args There are no arguments needed.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@ package ch.zhaw.gartenverwaltung;
|
|||
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
||||
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.io.TaskList;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
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.application.Platform;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
|
@ -24,7 +24,6 @@ import javafx.scene.layout.VBox;
|
|||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -52,15 +51,9 @@ public class MyScheduleController {
|
|||
@FXML
|
||||
private ListView<Crop> scheduledPlants_listview;
|
||||
|
||||
@FXML
|
||||
private void showAllTasks(ActionEvent actionEvent) throws IOException {
|
||||
gardenSchedule.getTasksUpcomingWeek();
|
||||
scheduledPlants_listview.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
@AfterInject
|
||||
@SuppressWarnings("unused")
|
||||
public void init() throws IOException {
|
||||
public void init() {
|
||||
setCellFactoryCropListView();
|
||||
setCellFactoryTaskListView();
|
||||
scheduledPlants_listview.itemsProperty().bind(garden.getPlantedCrops());
|
||||
|
@ -68,19 +61,6 @@ public class MyScheduleController {
|
|||
week_listView.itemsProperty().bind(taskListProperty);
|
||||
lookForSelectedListEntries();
|
||||
information_label.setText("");
|
||||
|
||||
gardenSchedule.getTasksUpcomingWeek();
|
||||
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
gardenSchedule.getTasksUpcomingWeek();
|
||||
scheduledPlants_listview.getSelectionModel().clearSelection();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
gardenSchedule.setTaskListObserver(taskListObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,8 +81,6 @@ public class MyScheduleController {
|
|||
* set cellFactory for the crops.
|
||||
*/
|
||||
private void setCellFactoryCropListView() {
|
||||
MultipleSelectionModel<Crop> selectionModel = scheduledPlants_listview.getSelectionModel();
|
||||
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
|
||||
scheduledPlants_listview.setCellFactory(param -> new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(Crop crop, boolean empty) {
|
||||
|
@ -155,6 +133,8 @@ public class MyScheduleController {
|
|||
} else {
|
||||
gardenSchedule.getTasksUpcomingWeek();
|
||||
}
|
||||
//taskListProperty.clear();
|
||||
//taskListProperty.addAll(taskLists);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,12 +189,6 @@ public class MyScheduleController {
|
|||
alert.setHeaderText("Are you sure you have completed this task?");
|
||||
alert.setContentText("Confirming that you have completed the task will remove it from the schedule.");
|
||||
|
||||
DialogPane dialogPane = alert.getDialogPane();
|
||||
|
||||
dialogPane.getStylesheets().add(
|
||||
Objects.requireNonNull(getClass().getResource("bootstrap/dialogStyle.css")).toExternalForm());
|
||||
dialogPane.getStyleClass().add("myDialog");
|
||||
|
||||
alert.showAndWait()
|
||||
.ifPresent(buttonType -> {
|
||||
if (buttonType == ButtonType.OK) {
|
||||
|
@ -228,4 +202,5 @@ public class MyScheduleController {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,58 +6,21 @@ import javafx.beans.property.BooleanProperty;
|
|||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Singleton Class to store default Settings and User Settings
|
||||
*/
|
||||
public class Settings {
|
||||
/*
|
||||
* The Class instance to use everywhere
|
||||
*/
|
||||
|
||||
private static final Settings instance;
|
||||
/**
|
||||
* The current Hardiness zone initialized as default value Zone_8A
|
||||
*/
|
||||
private HardinessZone currentHardinessZone = HardinessZone.ZONE_8A;
|
||||
/**
|
||||
* Setting to show or hide the Tutorial in Main Menu
|
||||
*/
|
||||
private final BooleanProperty showTutorial = new SimpleBooleanProperty(false);
|
||||
/**
|
||||
* The SMTP Credentials which are used to send E-Mail Notifications
|
||||
* The following Google Account is created for Testing:
|
||||
* E-Mail Address: pm3.hs22.it21b.win.team1@gmail.com
|
||||
* Account Password: Gartenverwaltung.PM3.2022
|
||||
* SMTP Password: bisefhhjtrrhtoqr
|
||||
*/
|
||||
private SmtpCredentials smtpCredentials = new SmtpCredentials("imap.gmail.com", "587", "pm3.hs22.it21b.win.team1@gmail.com", "pm3.hs22.it21b.win.team1@gmail.com", "bisefhhjtrrhtoqr", true);
|
||||
/**
|
||||
* List of Receivers for E-Mailnotifications. Multiple E-Mailadresses can be separated by ";"
|
||||
* Following Public E-mail address was used for Testing: pm3.hs22.it21b.win.team1@mailinator.com
|
||||
* The E-Mail inbox of this address can be found here: https://www.mailinator.com/v4/public/inboxes.jsp?to=pm3.hs22.it21b.win.team1
|
||||
*/
|
||||
// Gmail Address: pm3.hs22.it21b.win.team1@gmail.com
|
||||
// Gmail Passwort: Gartenverwaltung.PM3.2022
|
||||
// E-Mail Inbox: https://www.mailinator.com/v4/public/inboxes.jsp?to=pm3.hs22.it21b.win.team1
|
||||
private String mailNotificationReceivers = "pm3.hs22.it21b.win.team1@mailinator.com";
|
||||
/**
|
||||
* String Template to create E-Mail Subject for Notifications
|
||||
* Variables: Task Name
|
||||
*/
|
||||
private String mailNotificationSubjectTemplate = "Task %s is due!";
|
||||
/**
|
||||
* String Template to create E-Mail Text for Notifications
|
||||
* Variables: Task Name, plant Name, nextExecution, Task description
|
||||
*/
|
||||
private String mailNotificationTextTemplate = "Dear user\nYour gardentask %s for plant %s is due at %tF. Don't forget to confirm in your application if the task is done.\nTask description:\n%s";
|
||||
private String mailNotificationSubjectTemplate = "Task %s is due!"; // {0} = Task Name
|
||||
private String mailNotificationTextTemplate = "Dear user\nYour gardentask %s for plant %s is due at %tF. Don't forget to confirm in your application if the task is done.\nTask description:\n%s"; // {0} = Task Name, {1} = plantname, {2} = nextExecution, {3} = Task description
|
||||
|
||||
/**
|
||||
* Location of the garden can be set by user (Used for Weather Service)
|
||||
*/
|
||||
private String location = "";
|
||||
|
||||
/*
|
||||
Create Instance of Settings
|
||||
*/
|
||||
static {
|
||||
instance = new Settings();
|
||||
}
|
||||
|
@ -66,21 +29,14 @@ public class Settings {
|
|||
return Settings.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor to prevent Classes from creating more instances
|
||||
*/
|
||||
private Settings() {}
|
||||
|
||||
public HardinessZone getCurrentHardinessZone() {
|
||||
return currentHardinessZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the current Hardiness Zone. If no Hardiness Zone is given the default zone (ZONE_8A) will be used.
|
||||
* @param currentHardinessZone the new Hardiness Zone
|
||||
*/
|
||||
public void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
|
||||
this.currentHardinessZone = Objects.requireNonNullElse(currentHardinessZone, HardinessZone.ZONE_8A);
|
||||
this.currentHardinessZone = currentHardinessZone;
|
||||
}
|
||||
|
||||
public void setShowTutorial (boolean showTutorial) {
|
||||
|
|
|
@ -7,7 +7,6 @@ import javafx.scene.image.Image;
|
|||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Controller class for the Tutorial.fxml file
|
||||
|
@ -23,8 +22,6 @@ public class TutorialController {
|
|||
public ImageView imgAddNewPlant;
|
||||
public ImageView imgTaskList;
|
||||
public ImageView imgSelectDate;
|
||||
public ImageView imgAddTaskButton;
|
||||
public ImageView imgDetailDeleteButtons;
|
||||
|
||||
private int page = 0;
|
||||
|
||||
|
@ -33,27 +30,10 @@ public class TutorialController {
|
|||
switchViews();
|
||||
setButtonAbilities();
|
||||
|
||||
setImageView(imgAddNewPlant, "add-new-plant.png");
|
||||
setImageView(imgSelectDate, "select-sow-harvest.png");
|
||||
setImageView(imgDetailDeleteButtons, "details-delete.png");
|
||||
setImageView(imgTaskList, "schedule.png");
|
||||
setImageView(imgAddTaskButton, "add-task.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* update the given image view with screenshot or placeholder image.
|
||||
* @param imageView the image view to update
|
||||
* @param fileName the file name of the source
|
||||
*/
|
||||
private void setImageView(ImageView imageView, String fileName) {
|
||||
InputStream is = PlantsController.class.getResourceAsStream("screenshots/" + fileName);
|
||||
Image image;
|
||||
if (is != null) {
|
||||
image = new Image(String.valueOf(PlantsController.class.getResource("screenshots/" + fileName)));
|
||||
} else {
|
||||
image = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||
}
|
||||
imageView.setImage(image);
|
||||
Image placeholder = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||
imgAddNewPlant.setImage(placeholder);
|
||||
imgSelectDate.setImage(placeholder);
|
||||
imgTaskList.setImage(placeholder);
|
||||
}
|
||||
|
||||
public void viewNextPage() {
|
||||
|
|
|
@ -17,27 +17,14 @@ import java.util.TimerTask;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Class with tasks which must be executed periodic and not triggered by user. Method run must be called in a fix interval.
|
||||
*/
|
||||
public class BackgroundTasks extends TimerTask {
|
||||
private static final Logger LOG = Logger.getLogger(CropDetailController.class.getName());
|
||||
private final TaskList taskList;
|
||||
private final Notifier notifier;
|
||||
private final WeatherGradenTaskPlanner weatherGardenTaskPlaner;
|
||||
|
||||
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
|
||||
this.taskList = taskList;
|
||||
notifier = new Notifier(taskList, plantList, cropList);
|
||||
weatherGardenTaskPlaner = new WeatherGradenTaskPlanner(taskList, plantList, cropList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the field "nextExecution" of all tasks if it's in the past to the actual date as long as they are not done.
|
||||
* @throws IOException if the taskList can't be read.
|
||||
*/
|
||||
private void movePastTasks() throws IOException {
|
||||
List<Task> taskList = this.taskList.getTaskList(LocalDate.MIN.plusDays(1), LocalDate.now().minusDays(1));
|
||||
List<Task> taskList = this.taskList.getTaskList(LocalDate.MIN, LocalDate.now().minusDays(1));
|
||||
for (Task task : taskList) {
|
||||
if (!task.isDone()) {
|
||||
task.setNextExecution(LocalDate.now());
|
||||
|
@ -46,28 +33,31 @@ public class BackgroundTasks extends TimerTask {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to call if Tasks should be executed. It calls all Background tasks after each other.
|
||||
*/
|
||||
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
|
||||
this.taskList = taskList;
|
||||
notifier = new Notifier(taskList, plantList, cropList);
|
||||
weatherGardenTaskPlaner = new WeatherGradenTaskPlanner(taskList, plantList, cropList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
movePastTasks();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LOG.log(Level.WARNING, "Could not execute Background Task: move past Tasks ", e.getCause());
|
||||
LOG.log(Level.SEVERE, "Could not execute Background Task: move past Tasks ", e.getCause());
|
||||
}
|
||||
try {
|
||||
weatherGardenTaskPlaner.refreshTasks();
|
||||
} catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
LOG.log(Level.WARNING, "Could not execute Background Task: Refresh Tasks by WeatherGardenTaskPlaner ", e.getCause());
|
||||
LOG.log(Level.SEVERE, "Could not execute Background Task: Refresh Tasks by WeatherGardenTaskPlaner ", e.getCause());
|
||||
}
|
||||
try {
|
||||
notifier.sendNotifications();
|
||||
} catch (IOException | MessagingException | HardinessZoneNotSetException e) {
|
||||
e.printStackTrace();
|
||||
LOG.log(Level.WARNING, "Could not execute Background Task: send Notification for due Tasks", e.getCause());
|
||||
LOG.log(Level.SEVERE, "Could not execute Background Task: send Notification for due Tasks", e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,6 @@ import javax.mail.MessagingException;
|
|||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Class to send Notifications to the user
|
||||
*/
|
||||
public class Notifier {
|
||||
private final TaskList taskList;
|
||||
private final CropList cropList;
|
||||
|
@ -28,13 +25,6 @@ public class Notifier {
|
|||
this.plantList = plantList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to send a Notification to the user for e specific Task
|
||||
* @param task The task to use for notification
|
||||
* @throws IOException if tasklist can not be read
|
||||
* @throws MessagingException if E-Mail can not be sent for any reason
|
||||
* @throws HardinessZoneNotSetException if hardiness zone is not set in plant list.
|
||||
*/
|
||||
private void sendNotification(Task task) throws IOException, MessagingException, HardinessZoneNotSetException {
|
||||
String plantName = "unkown plant";
|
||||
if(cropList.getCropById((task.getCropId())).isPresent()){
|
||||
|
@ -48,12 +38,6 @@ public class Notifier {
|
|||
eMailSender.sendMails(Settings.getInstance().getMailNotificationReceivers(), messageSubject, messageText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a notification to the user for each task which is due and not done every day as long as it's not done.
|
||||
* @throws IOException if tasklist can not be read
|
||||
* @throws MessagingException if E-Mail can not be sent for any reason
|
||||
* @throws HardinessZoneNotSetException if hardiness zone is not set in plant list.
|
||||
*/
|
||||
public void sendNotifications() throws IOException, MessagingException, HardinessZoneNotSetException {
|
||||
for (Task task : taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)) {
|
||||
if (task.getNextNotification() != null && task.getNextNotification().isBefore(LocalDate.now().minusDays(1))) {
|
||||
|
|
|
@ -10,20 +10,16 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class to send E-Mails
|
||||
*/
|
||||
public class EMailSender {
|
||||
|
||||
/**
|
||||
* Method to send E-Mail to one or multiple recipients
|
||||
* @param recipients recipients E-Mail addresses separated by ";"
|
||||
* @param subject Subject of the E-Mail
|
||||
* @param text E-Mail message Text as rear text or html
|
||||
* @throws MessagingException If sending the E-Mail fails for any reason
|
||||
*/
|
||||
|
||||
public EMailSender(){
|
||||
|
||||
}
|
||||
|
||||
public void sendMails(String recipients, String subject, String text) throws MessagingException {
|
||||
printMail(recipients, subject, text);
|
||||
// TODO replace printMail with implementation
|
||||
printMail(recipients, subject, text); // TODO Remove Printing E-Mail to console to test it
|
||||
MimeMessage message = new MimeMessage(Settings.getInstance().getSmtpCredentials().getSession());
|
||||
message.addHeader("Content-type", "text/HTML; charset=UTF-8");
|
||||
message.addHeader("format", "flowed");
|
||||
|
|
|
@ -5,10 +5,6 @@ import javax.mail.Session;
|
|||
import java.net.Authenticator;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Class to store SMTP Credentials to send E-Mails and create
|
||||
* corresponding Session Object
|
||||
*/
|
||||
public record SmtpCredentials(
|
||||
String host,
|
||||
String port,
|
||||
|
@ -18,10 +14,6 @@ public record SmtpCredentials(
|
|||
boolean startTLS
|
||||
) {
|
||||
|
||||
/**
|
||||
* Creates a Properties Object with SMTP Server Information
|
||||
* @return the created Properties Object
|
||||
*/
|
||||
private Properties getProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("mail.smtp.host", host);
|
||||
|
@ -31,10 +23,6 @@ public record SmtpCredentials(
|
|||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a javax.mail.Authenticator Object with username and password for SMTP Server
|
||||
* @return the created javax.mail.Authenticator Object
|
||||
*/
|
||||
private javax.mail.Authenticator getAuthenticator() {
|
||||
return new javax.mail.Authenticator() {
|
||||
@Override
|
||||
|
@ -44,11 +32,10 @@ public record SmtpCredentials(
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the Session Instance with the given SMTP Credentials
|
||||
* @return the Session Instance
|
||||
*/
|
||||
public Session getSession() {
|
||||
return Session.getInstance(getProperties(), getAuthenticator());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package ch.zhaw.gartenverwaltung.backgroundtasks.weather;
|
||||
|
||||
/**
|
||||
* Enum of possible Weather events
|
||||
*/
|
||||
public enum SevereWeather {
|
||||
FROST,SNOW,HAIL,NO_SEVERE_WEATHER,RAIN
|
||||
}
|
||||
|
|
|
@ -10,10 +10,14 @@ import ch.zhaw.gartenverwaltung.types.*;
|
|||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
* The WeatherGardenTaskPlanner creates Tasks based on weather events and the rain amount from the last days
|
||||
*
|
||||
*/
|
||||
public class WeatherGradenTaskPlanner {
|
||||
private final TaskList taskList;
|
||||
|
@ -42,19 +46,12 @@ public class WeatherGradenTaskPlanner {
|
|||
|
||||
private void getSevereWeatherEvents() throws IOException {
|
||||
SevereWeather actualWeather = weatherService.causeSevereWeather(1);
|
||||
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
for (Crop crop : actualCrops) {
|
||||
|
||||
List<Task> actualCropTasks = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
|
||||
if (SevereWeather.HAIL.equals(actualWeather)) {
|
||||
createPreHailTask(crop, actualCropTasks);
|
||||
createPreHailTask();
|
||||
} else if (SevereWeather.FROST.equals(actualWeather)) {
|
||||
createPreFrostTask(crop, actualCropTasks);
|
||||
createPreFrostTask();
|
||||
} else if (SevereWeather.SNOW.equals(actualWeather)) {
|
||||
createPreSnowTask(crop, actualCropTasks);
|
||||
}
|
||||
createPreSnowTask();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,70 +61,88 @@ public class WeatherGradenTaskPlanner {
|
|||
}
|
||||
|
||||
/**
|
||||
* Method to create a PreHailTask and saves it in the tasklist
|
||||
* Method to create a PreHailTask
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private void createPreHailTask(Crop crop, List<Task> actualTasksForCrop) throws IOException {
|
||||
private void createPreHailTask() throws IOException {
|
||||
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
|
||||
for (Crop crop : actualCrops) {
|
||||
Task preHailTask = new Task("Hail",
|
||||
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
|
||||
dateSevereWeather,dateSevereWeather.plusDays(1L),crop.getCropId().orElse(-1L));
|
||||
|
||||
List<Task> hailTasks = actualTasksForCrop.stream().filter(task -> task.getName().equals("Hail")).toList();
|
||||
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
List<Task> hailTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Hail")).toList();
|
||||
|
||||
if(isNoSevereWeatherTaskAtDate(preHailTask, hailTasks) && hailTasks.isEmpty()){
|
||||
List<Task> hailTaskListAtDate = new ArrayList<>();
|
||||
for (Task task : hailTasklist) {
|
||||
if (task.getStartDate() == (preHailTask.getStartDate())) {
|
||||
hailTaskListAtDate.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
if(hailTaskListAtDate.isEmpty() && hailTasklist.isEmpty()){
|
||||
taskList.saveTask(preHailTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a PreFrosttask and saves it in the tasklist
|
||||
* Method to create a PreFrosttask
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private void createPreFrostTask(Crop crop, List<Task> actualTasksForCrop) throws IOException {
|
||||
private void createPreFrostTask() throws IOException {
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
for (Crop crop : actualCrops) {
|
||||
|
||||
Task preFrostTask = new Task("Frost",
|
||||
"The temperatur falls below zero degrees, cover especially the root with wool",
|
||||
dateSevereWeather,dateSevereWeather.plusDays(1L),crop.getCropId().orElse(-1L));
|
||||
|
||||
List<Task> frostTasks = actualTasksForCrop.stream().filter(task -> task.getName().equals("Frost")).toList();
|
||||
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
List<Task> frostTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Frost")).toList();
|
||||
|
||||
if(isNoSevereWeatherTaskAtDate(preFrostTask, frostTasks) && frostTasks.isEmpty()){
|
||||
List<Task> frostTaskListAtDate = new ArrayList<>();
|
||||
for (Task task : frostTasklist) {
|
||||
if (task.getStartDate() == preFrostTask.getStartDate()) {
|
||||
frostTaskListAtDate.add(task);
|
||||
}
|
||||
}
|
||||
if(frostTaskListAtDate.isEmpty() && frostTasklist.isEmpty()){
|
||||
taskList.saveTask(preFrostTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a PreSnowTask and saves it in the tasklist
|
||||
* Method to create a PreSnowTask
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private void createPreSnowTask(Crop crop, List<Task> actualTasksForCrop) throws IOException {
|
||||
private void createPreSnowTask() throws IOException {
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
for (Crop crop : actualCrops) {
|
||||
|
||||
Task preSnowTask = new Task("Snow",
|
||||
"The weather brings little snowfall. Cover your crops",
|
||||
dateSevereWeather, dateSevereWeather.plusDays(1L), crop.getCropId().orElse(-1L));
|
||||
|
||||
List<Task> snowTasklist = actualTasksForCrop.stream().filter(task -> task.getName().equals("Snow")).toList();
|
||||
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
List<Task> snowTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Snow")).toList();
|
||||
|
||||
if(isNoSevereWeatherTaskAtDate(preSnowTask, snowTasklist) && snowTasklist.isEmpty()){
|
||||
List<Task> snowTaskListAtDate = new ArrayList<>();
|
||||
for (Task task : snowTasklist) {
|
||||
if (task.getStartDate() == preSnowTask.getStartDate()) {
|
||||
snowTaskListAtDate.add(task);
|
||||
}
|
||||
}
|
||||
if(snowTaskListAtDate .isEmpty() && snowTasklist.isEmpty()){
|
||||
taskList.saveTask(preSnowTask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a PreSnowTask and saves it in the tasklist
|
||||
* @param preSevereWeatherTask the Task which would be added if there is not already
|
||||
* the same Type of severe weather task
|
||||
* @param severeWeatherTasks List of severe weather tasks from e specific severe weather
|
||||
* @return true If there is not already a severe weather task of the same type of preSevereWeatherTask
|
||||
* task at the date of the preSevereWeatherTask
|
||||
*/
|
||||
private boolean isNoSevereWeatherTaskAtDate(Task preSevereWeatherTask, List<Task> severeWeatherTasks) {
|
||||
List<Task> severeWeatherTasksAtDate = new ArrayList<>();
|
||||
for (Task task : severeWeatherTasks) {
|
||||
if (task.getStartDate() == preSevereWeatherTask.getStartDate()) {
|
||||
severeWeatherTasksAtDate.add(task);
|
||||
}
|
||||
}
|
||||
return severeWeatherTasksAtDate.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to adjust the water plant tasks
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ch.zhaw.gartenverwaltung.backgroundtasks.weather;
|
||||
/**
|
||||
* The WeatherService is a class to cause weather events for the WeatherGardenTaskPlanner
|
||||
*
|
||||
*/
|
||||
public class WeatherService {
|
||||
private static final int NO_RAIN = 0;
|
||||
|
@ -8,11 +9,6 @@ public class WeatherService {
|
|||
private static final int RAIN = 25;
|
||||
private static final int HEAVY_RAIN = 50;
|
||||
|
||||
/**
|
||||
* Method to simmulate a Weather Service for testing
|
||||
* @param randomWeather random int. Range: 1-3
|
||||
* @return the selected SevereWeather
|
||||
*/
|
||||
public SevereWeather causeSevereWeather(int randomWeather) {
|
||||
return switch (randomWeather) {
|
||||
case 1 -> SevereWeather.HAIL;
|
||||
|
@ -23,11 +19,6 @@ public class WeatherService {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to simulate a Weather Service for testing
|
||||
* @param randomRainAmount random int. Range: 1-4
|
||||
* @return the selected rain amount
|
||||
*/
|
||||
public int causeRainAmount(int randomRainAmount) {
|
||||
return switch (randomRainAmount) {
|
||||
case 1 -> NO_RAIN;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ch.zhaw.gartenverwaltung.bootstrap;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.CropDetailController;
|
||||
import ch.zhaw.gartenverwaltung.Main;
|
||||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
|
@ -18,15 +17,12 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Class responsible for bootstrapping the application wide dependencies
|
||||
* and injecting them into JavaFX Controllers.
|
||||
*/
|
||||
public class AppLoader {
|
||||
private static final Logger LOG = Logger.getLogger(CropDetailController.class.getName());
|
||||
/**
|
||||
* Caching the panes
|
||||
*/
|
||||
|
@ -150,17 +146,12 @@ public class AppLoader {
|
|||
try {
|
||||
afterInjectMethod.invoke(controller);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
LOG.log(Level.SEVERE, "Could not invoke afterInjectMethod", e.getCause());
|
||||
// TODO: Log
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get any AppDependency
|
||||
* @param type Class of Dependency
|
||||
* @return the App dependency
|
||||
*/
|
||||
public Object getAppDependency(Class<?> type) {
|
||||
return dependencies.get(type.getSimpleName());
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
/**
|
||||
* Exceptionm which is thrown if Hardiness zone is not set in plant list.
|
||||
*/
|
||||
public class HardinessZoneNotSetException extends Exception {
|
||||
public HardinessZoneNotSetException() {
|
||||
super("HardinessZone must be set to retrieve plants!");
|
||||
|
|
|
@ -2,9 +2,6 @@ package ch.zhaw.gartenverwaltung.io;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Excption which is thrown if a JSON file has a invalid File format.
|
||||
*/
|
||||
class InvalidJsonException extends IOException {
|
||||
public InvalidJsonException(String reason) {
|
||||
super(reason);
|
||||
|
|
|
@ -32,6 +32,16 @@ public class GardenSchedule {
|
|||
public GardenSchedule(TaskList taskList, PlantList plantList) throws IOException {
|
||||
this.taskList = taskList;
|
||||
this.plantList = plantList;
|
||||
TaskList.TaskListObserver taskListObserver = newTaskList -> {
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
getTasksUpcomingWeek();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
setTaskListObserver(taskListObserver);
|
||||
}
|
||||
|
||||
public ListProperty<List<Task>> getWeeklyTaskListProperty() {
|
||||
|
@ -166,12 +176,14 @@ public class GardenSchedule {
|
|||
dayTaskList.add(new ArrayList<>());
|
||||
final int finalI = i;
|
||||
weekTasks.forEach(task -> {
|
||||
if(task.getNextExecution() != null) {
|
||||
if (task.getNextExecution() == null) {
|
||||
task.isDone();
|
||||
} else {
|
||||
LocalDate checkDate = task.getNextExecution();
|
||||
|
||||
do {
|
||||
if (date.equals(task.getNextExecution()) || (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN)))) {
|
||||
if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) {
|
||||
dayTaskList.get(finalI).add(task);
|
||||
break;
|
||||
}
|
||||
checkDate = checkDate.plusDays(task.getInterval().orElse(0));
|
||||
} while (!(task.getInterval().orElse(0) == 0) && checkDate.isBefore(LocalDate.now().plusDays(listLength)));
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.Settings;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||
|
@ -17,6 +16,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class PlantListModel {
|
||||
private final PlantList plantList;
|
||||
private HardinessZone currentZone;
|
||||
|
||||
/**
|
||||
* Comparators to create sorted Plant List
|
||||
|
@ -33,15 +33,15 @@ public class PlantListModel {
|
|||
}
|
||||
|
||||
private void setDefaultZone() {
|
||||
Settings.getInstance().setCurrentHardinessZone(null);
|
||||
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Settings
|
||||
}
|
||||
|
||||
public void setCurrentZone(HardinessZone currentZone) {
|
||||
Settings.getInstance().setCurrentHardinessZone(currentZone);
|
||||
this.currentZone = currentZone;
|
||||
}
|
||||
|
||||
public HardinessZone getCurrentZone() {
|
||||
return Settings.getInstance().getCurrentHardinessZone();
|
||||
return currentZone;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
/**
|
||||
* Exception which is thrown if there is no plant in plant Database with the given id.
|
||||
*/
|
||||
public class PlantNotFoundException extends Exception {
|
||||
public PlantNotFoundException() {
|
||||
super("The selected Plant was not found in Database!");
|
||||
|
|
|
@ -40,6 +40,7 @@ public class Crop {
|
|||
public Optional<Long> getCropId() {
|
||||
return Optional.ofNullable(cropId);
|
||||
}
|
||||
|
||||
public long getPlantId() { return plantId; }
|
||||
public LocalDate getStartDate() { return startDate; }
|
||||
public double getArea() { return area; }
|
||||
|
|
|
@ -68,7 +68,7 @@ public record Plant(
|
|||
return growthPhase.group();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0; // TODO implement
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -108,7 +108,7 @@ public class Task {
|
|||
* @return Whether the Task is within the given range
|
||||
*/
|
||||
public boolean isInTimePeriod(LocalDate searchStartDate, LocalDate searchEndDate) {
|
||||
return (endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate)) || ((nextExecution != null && nextExecution.isBefore(searchEndDate.plusDays(1)) && nextExecution.isAfter(searchStartDate.minusDays(1))));
|
||||
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate) || (nextExecution != null && nextExecution.isBefore(searchEndDate) && nextExecution.isAfter(searchStartDate));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,9 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Class which represents a Task if the start and enddate is not known yet.
|
||||
*/
|
||||
public class TaskTemplate {
|
||||
@JsonProperty
|
||||
private final String name;
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<Insets bottom="10.0" />
|
||||
</VBox.margin>
|
||||
</ListView>
|
||||
<Button styleClass="button-class" fx:id="addTask_button" mnemonicParsing="false" onAction="#addTask" prefHeight="25.0" prefWidth="120.0" VBox.vgrow="NEVER" text="Add Task">
|
||||
<Button styleClass="button-class" fx:id="addTask_button" mnemonicParsing="false" onAction="#addTask" prefHeight="25.0" prefWidth="45.0" VBox.vgrow="NEVER">
|
||||
<VBox.margin>
|
||||
<Insets />
|
||||
</VBox.margin>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
@ -20,12 +19,11 @@
|
|||
</Label>
|
||||
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="541.0" prefWidth="867.0" spacing="10.0" VBox.vgrow="ALWAYS">
|
||||
<children>
|
||||
<VBox prefHeight="497.0" prefWidth="237.0" spacing="10.0" HBox.hgrow="NEVER">
|
||||
<children>
|
||||
<ListView fx:id="scheduledPlants_listview" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="522.0" prefWidth="271.0" VBox.vgrow="ALWAYS" />
|
||||
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#showAllTasks" styleClass="button-class" text="Show All Tasks" VBox.vgrow="NEVER" />
|
||||
</children>
|
||||
</VBox>
|
||||
<ListView fx:id="scheduledPlants_listview" maxWidth="1.7976931348623157E308" prefHeight="522.0" prefWidth="271.0" HBox.hgrow="NEVER">
|
||||
<HBox.margin>
|
||||
<Insets />
|
||||
</HBox.margin>
|
||||
</ListView>
|
||||
<VBox maxWidth="1.7976931348623157E308" prefHeight="537.0" prefWidth="650.0" spacing="10.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
<ListView fx:id="week_listView" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
<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" onAction="#closeTutorial" styleClass="button-class" text="Close" />
|
||||
<Button fx:id="previousPageButton" mnemonicParsing="false" onAction="#viewPreviousPage" styleClass="button-class" text="Previous" />
|
||||
<Button fx:id="nextPageButton" defaultButton="true" mnemonicParsing="false" onAction="#viewNextPage" styleClass="button-class" text="Next" />
|
||||
<Button styleClass="button-class" cancelButton="true" contentDisplay="CENTER" graphicTextGap="5.0" mnemonicParsing="false" text="Close" onAction="#closeTutorial"/>
|
||||
<Button styleClass="button-class" fx:id="previousPageButton" mnemonicParsing="false" text="Previous" onAction="#viewPreviousPage"/>
|
||||
<Button styleClass="button-class" fx:id="nextPageButton" defaultButton="true" mnemonicParsing="false" text="Next" onAction="#viewNextPage" />
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
</children>
|
||||
|
@ -38,7 +38,7 @@
|
|||
<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="Adding Crops">
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Managing Your Crops">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
|
@ -75,7 +75,7 @@
|
|||
</children>
|
||||
</TextFlow>
|
||||
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||
<ImageView fx:id="imgSelectDate" fitHeight="150.0" fitWidth="400.0" pickOnBounds="true" preserveRatio="true" />
|
||||
<ImageView fx:id="imgSelectDate" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
|
@ -83,50 +83,7 @@
|
|||
<Insets />
|
||||
</opaqueInsets>
|
||||
</VBox>
|
||||
<VBox layoutX="30.0" layoutY="30.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="Once you've added a crop to your garden, it will be displayed in the "My Garden" tab.">
|
||||
<VBox.margin>
|
||||
<Insets bottom="20.0" />
|
||||
</VBox.margin>
|
||||
</Text>
|
||||
<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="On the right hand side of the listing, you'll see two buttons. Button with the "trash can" icon lets you remove a crop from your garden plan. This will also delete all associated tasks. The button on the left will display the details of the crop in a new window." />
|
||||
</children>
|
||||
</TextFlow>
|
||||
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||
<ImageView fitHeight="70.0" fitWidth="100.0" pickOnBounds="true" preserveRatio="true" fx:id="imgDetailDeleteButtons"/>
|
||||
</children></HBox>
|
||||
<HBox layoutX="10.0" layoutY="105.0" 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="Here, 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="400.0" pickOnBounds="true" preserveRatio="true" fx:id="imgAddTaskButton"/>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
</VBox>
|
||||
<VBox opacity="0.0" prefHeight="200.0" prefWidth="100.0">
|
||||
<VBox prefHeight="200.0" prefWidth="100.0">
|
||||
<children>
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Managing Your Tasks">
|
||||
<font>
|
||||
|
@ -154,9 +111,19 @@
|
|||
</HBox.margin>
|
||||
</TextFlow>
|
||||
<Separator prefWidth="200.0" visible="false" HBox.hgrow="ALWAYS" />
|
||||
<ImageView fx:id="imgTaskList" fitHeight="200.0" fitWidth="400.0" pickOnBounds="true" preserveRatio="true" />
|
||||
<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 />
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 42 KiB |
Binary file not shown.
Before Width: | Height: | Size: 34 KiB |
|
@ -1,12 +1,7 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.application.Platform;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -18,7 +13,6 @@ import java.nio.file.Path;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -33,22 +27,6 @@ public class JsonTaskListTest {
|
|||
private final URL dbDataSource = this.getClass().getResource("test-taskdb.json");
|
||||
private final URL testFile = this.getClass().getResource("template-taskdb.json");
|
||||
|
||||
|
||||
@BeforeAll
|
||||
static void setUpAll() {
|
||||
try{
|
||||
Platform.startup(()->{});
|
||||
}catch (IllegalStateException ise){
|
||||
//ignore double launches
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDownAll() {
|
||||
//Dont do: Platform.exit();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void connectToDb() throws URISyntaxException, IOException {
|
||||
assertNotNull(testFile);
|
||||
|
@ -57,10 +35,6 @@ public class JsonTaskListTest {
|
|||
testDatabase = new JsonTaskList(dbDataSource);
|
||||
}
|
||||
|
||||
private void reloadDb() {
|
||||
testDatabase = new JsonTaskList(dbDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check if results are retrieved completely")
|
||||
void getTasks() {
|
||||
|
@ -73,8 +47,7 @@ public class JsonTaskListTest {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
List<Long> ids = taskList.stream().map(t -> t.getId().orElse(0L)).toList();
|
||||
Assertions.assertEquals(Arrays.asList(1L, 2L, 5L), ids);
|
||||
Assertions.assertEquals(3, taskList.size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -92,8 +65,7 @@ public class JsonTaskListTest {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
List<Long> ids = taskList.stream().map(t -> t.getId().orElse(0L)).toList();
|
||||
Assertions.assertEquals(Arrays.asList(1L, 2L, 5L, 9L), ids);
|
||||
Assertions.assertEquals(4, taskList.size());
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -111,8 +83,7 @@ public class JsonTaskListTest {
|
|||
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
|
||||
LocalDate.parse("2022-05-31", formatter));
|
||||
|
||||
List<Long> ids = taskList.stream().map(t -> t.getId().orElse(0L)).toList();
|
||||
Assertions.assertEquals(Arrays.asList(1L, 5L), ids);
|
||||
Assertions.assertEquals(2, taskList.size());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -129,8 +100,8 @@ public class JsonTaskListTest {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
List<Long> ids = taskList.stream().map(t -> t.getId().orElse(0L)).toList();
|
||||
Assertions.assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L), ids);
|
||||
Assertions.assertEquals(6, taskList.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,20 +116,10 @@ public class JsonTaskListTest {
|
|||
}
|
||||
|
||||
Assertions.assertEquals(0, taskList.size());
|
||||
|
||||
try {
|
||||
taskList = testDatabase.getTaskForCrop(1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
List<Long> ids = (taskList.stream().map( task -> task.getId().orElse(0L)).toList());
|
||||
Assertions.assertEquals(Arrays.asList(7L, 8L), ids);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultConstructor() {
|
||||
void testDefaultConstructor(){
|
||||
JsonTaskList db = new JsonTaskList();
|
||||
try {
|
||||
assertNotNull(db.getTaskForCrop(0));
|
||||
|
@ -177,43 +138,6 @@ public class JsonTaskListTest {
|
|||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ArgumentCaptor<List<Task>> captor = ArgumentCaptor.forClass(List.class);
|
||||
|
||||
verify(mockObs, times(1)).onChange(captor.capture());
|
||||
List<Long> ids = captor.getValue().stream().map(t -> t.getId().orElse(0L)).toList();
|
||||
Assertions.assertEquals(Arrays.asList(7L, 8L), ids);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("IntegrationTest")
|
||||
void testComplete() {
|
||||
JsonPlantList plantList = new JsonPlantList();
|
||||
try {
|
||||
testDatabase.removeTasksForCrop(0);
|
||||
testDatabase.removeTasksForCrop(1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
GardenSchedule gardenSchedule = null;
|
||||
try {
|
||||
gardenSchedule = new GardenSchedule(testDatabase, plantList);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Crop crop = new Crop(3L, LocalDate.parse("2022-12-01", formatter));
|
||||
|
||||
try {
|
||||
gardenSchedule.planTasksForCrop(crop);
|
||||
|
||||
reloadDb();
|
||||
|
||||
List<Task> tasks = gardenSchedule.getTaskList();
|
||||
List<String> tasknames = (tasks.stream().map( task -> task.getName().substring(0,3).toLowerCase()).toList());
|
||||
Assertions.assertEquals(Arrays.asList("ger","wat","hil","har"), tasknames);
|
||||
} catch (IOException | PlantNotFoundException | HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
verify(mockObs, times(1)).onChange(ArgumentMatchers.anyList());
|
||||
}
|
||||
}
|
|
@ -3,9 +3,6 @@ package ch.zhaw.gartenverwaltung.models;
|
|||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
import javafx.application.Platform;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -32,21 +29,6 @@ class GardenScheduleTest {
|
|||
List<TaskTemplate> exampleTaskTemplateList;
|
||||
GardenSchedule model;
|
||||
|
||||
@BeforeAll
|
||||
static void setUpAll() {
|
||||
try{
|
||||
Platform.startup(()->{});
|
||||
}catch (IllegalStateException ise){
|
||||
//ignore double launches
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDownAll() {
|
||||
//Dont do: Platform.exit();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException, HardinessZoneNotSetException {
|
||||
createExampleTaskList();
|
||||
|
@ -239,8 +221,5 @@ class GardenScheduleTest {
|
|||
testTaskList.getTaskList(LocalDate.MIN,LocalDate.MAX).get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPlantNotFoundException() throws HardinessZoneNotSetException, IOException {
|
||||
assertThrowsExactly(PlantNotFoundException.class, () -> { model.planTasksForCrop(new Crop(0, exampleStartDate)); });
|
||||
}
|
||||
|
||||
}
|
|
@ -101,7 +101,7 @@ class PlantListModelTest {
|
|||
|
||||
@Test
|
||||
void setCurrentZone() {
|
||||
checkCurrentZone(HardinessZone.ZONE_8A);
|
||||
checkCurrentZone(HardinessZone.ZONE_8A); // TODO change to get default zone from config
|
||||
model.setCurrentZone(HardinessZone.ZONE_1A);
|
||||
checkCurrentZone(HardinessZone.ZONE_1A);
|
||||
model.setCurrentZone(HardinessZone.ZONE_8A);
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
"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",
|
||||
"nextExecution": "2022-05-01",
|
||||
"nextNotification": "2022-05-01",
|
||||
"endDate" : "2022-08-01",
|
||||
"interval" : 28,
|
||||
"cropId" : 0
|
||||
|
@ -37,8 +37,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",
|
||||
"nextExecution": "2022-05-01",
|
||||
"nextNotification": "2022-05-01",
|
||||
"endDate" : "2022-07-01",
|
||||
"interval" : 0,
|
||||
"cropId" : 0
|
||||
|
@ -59,32 +59,10 @@
|
|||
"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",
|
||||
"nextExecution": "2022-05-01",
|
||||
"nextNotification": "2022-05-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 0,
|
||||
"cropId" : 0
|
||||
},
|
||||
{
|
||||
"id" : 7,
|
||||
"name" : "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate" : "2022-11-01",
|
||||
"nextExecution": "2022-11-01",
|
||||
"nextNotification": "2022-11-01",
|
||||
"endDate" : "2022-11-01",
|
||||
"interval" : 0,
|
||||
"cropId" : 1
|
||||
},
|
||||
{
|
||||
"id" : 8,
|
||||
"name" : "harvest plant",
|
||||
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
||||
"startDate" : "2022-12-01",
|
||||
"nextExecution": "2022-12-01",
|
||||
"nextNotification": "2022-12-01",
|
||||
"endDate" : "2022-12-01",
|
||||
"interval" : 0,
|
||||
"cropId" : 1
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue