From 0074d4336472e72d753c8b16700d26f197d8bfc2 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 10 Dec 2022 13:52:33 +0100 Subject: [PATCH 1/7] fixed problem "showing task multiple times in in schedule" --- .../java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index 74d67dd..dfd69ba 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -181,6 +181,7 @@ public class GardenSchedule { do { if (date.equals(task.getNextExecution()) || (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))); From 3ebbb0e0e33f555c91e75c40abe21ea65f4d10e7 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 11 Dec 2022 07:19:06 +0100 Subject: [PATCH 2/7] small fixes --- .../MyScheduleController.java | 7 +++++ .../gartenverwaltung/TutorialController.java | 31 +++++++++++++------ .../ch/zhaw/gartenverwaltung/Tutorial.fxml | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java index 43eeb4c..df31cb9 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java @@ -24,6 +24,7 @@ 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; @@ -208,6 +209,12 @@ 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) { diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TutorialController.java b/src/main/java/ch/zhaw/gartenverwaltung/TutorialController.java index 2e0b1db..521a3bc 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TutorialController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TutorialController.java @@ -7,6 +7,7 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; import javafx.stage.Stage; +import java.io.File; /** * Controller class for the Tutorial.fxml file @@ -32,17 +33,27 @@ public class TutorialController { switchViews(); setButtonAbilities(); - Image addNewPlantImage = new Image(String.valueOf(PlantsController.class.getResource("add-new-plant.png"))); - Image selectSowHarvestImage = new Image(String.valueOf(PlantsController.class.getResource("select-sow-harvest.png"))); - Image scheduleImage = new Image(String.valueOf(PlantsController.class.getResource("schedule.png"))); - Image detailDeleteButtonsImage = new Image(String.valueOf(PlantsController.class.getResource("details-delete.png"))); - Image addTaskImage = new Image(String.valueOf(PlantsController.class.getResource("add-task.png"))); + 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"); + } - imgAddNewPlant.setImage(addNewPlantImage); - imgSelectDate.setImage(selectSowHarvestImage); - imgDetailDeleteButtons.setImage(detailDeleteButtonsImage); - imgAddTaskButton.setImage(addTaskImage); - imgTaskList.setImage(scheduleImage); + /** + * 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) { + File file = new File(String.valueOf(PlantsController.class.getResource(fileName))); + Image image; + if (file.exists()) { + image = new Image(String.valueOf(PlantsController.class.getResource(fileName))); + } else { + image = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png"))); + } + imageView.setImage(image); } public void viewNextPage() { diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/Tutorial.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/Tutorial.fxml index 93bb2d0..ae25ce8 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/Tutorial.fxml +++ b/src/main/resources/ch/zhaw/gartenverwaltung/Tutorial.fxml @@ -14,7 +14,7 @@ - + From 39bff805acb81fcc7727da3f0f319145dbce4548 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 11 Dec 2022 07:44:03 +0100 Subject: [PATCH 3/7] small fixes --- .../zhaw/gartenverwaltung/CropDetailController.java | 11 +++++++++-- src/main/java/ch/zhaw/gartenverwaltung/Main.java | 2 +- .../backgroundtasks/BackgroundTasks.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index 826e5b9..52fbfb2 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -12,6 +12,7 @@ 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; @@ -133,8 +134,14 @@ public class CropDetailController { initializeTaskListProperty(crop); TaskList.TaskListObserver taskListObserver = newTaskList -> { - taskListProperty.clear(); - taskListProperty.addAll(gardenSchedule.getTaskListForCrop(crop.getCropId().get())); + Platform.runLater(() -> { + taskListProperty.clear(); + try { + taskListProperty.addAll(gardenSchedule.getTaskListForCrop(crop.getCropId().get())); + } catch (IOException e) { + e.printStackTrace(); + } + }); }; gardenSchedule.setTaskListObserver(taskListObserver); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Main.java b/src/main/java/ch/zhaw/gartenverwaltung/Main.java index f757926..94390db 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Main.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Main.java @@ -28,7 +28,7 @@ public class Main extends Application { stage.setTitle("Gartenverwaltung"); stage.show(); - backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 60000); + backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 10000); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java index eea692a..ae56dab 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java @@ -24,7 +24,7 @@ public class BackgroundTasks extends TimerTask { private final WeatherGradenTaskPlanner weatherGardenTaskPlaner; private void movePastTasks() throws IOException { - List taskList = this.taskList.getTaskList(LocalDate.MIN, LocalDate.now().minusDays(1)); + List taskList = this.taskList.getTaskList(LocalDate.MIN.plusDays(1), LocalDate.now().minusDays(1)); for (Task task : taskList) { if (!task.isDone()) { task.setNextExecution(LocalDate.now()); From dc0830120fc20c96fb1c97fc883e5c9690a64f76 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 11 Dec 2022 07:59:34 +0100 Subject: [PATCH 4/7] small fixes --- src/main/java/ch/zhaw/gartenverwaltung/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Main.java b/src/main/java/ch/zhaw/gartenverwaltung/Main.java index 94390db..f757926 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Main.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Main.java @@ -28,7 +28,7 @@ public class Main extends Application { stage.setTitle("Gartenverwaltung"); stage.show(); - backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 10000); + backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 60000); } From 27b8d1754e9938d6f2b01d9dcbdc131b53b352ce Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 11 Dec 2022 14:25:57 +0100 Subject: [PATCH 5/7] Javadocs and code cleanup --- .../backgroundtasks/BackgroundTasks.java | 22 ++++++++++++++----- .../backgroundtasks/Notifier.java | 16 ++++++++++++++ .../backgroundtasks/email/EMailSender.java | 18 +++++++++------ .../email/SmtpCredentials.java | 19 +++++++++++++--- .../weather/SevereWeather.java | 3 +++ .../weather/WeatherGradenTaskPlanner.java | 1 - .../weather/WeatherService.java | 11 +++++++++- .../gartenverwaltung/bootstrap/AppLoader.java | 5 +++++ .../io/HardinessZoneNotSetException.java | 3 +++ .../io/InvalidJsonException.java | 3 +++ .../models/PlantNotFoundException.java | 3 +++ .../ch/zhaw/gartenverwaltung/types/Crop.java | 1 - .../gartenverwaltung/types/TaskTemplate.java | 3 +++ 13 files changed, 89 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java index ae56dab..261f675 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java @@ -17,12 +17,25 @@ 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 taskList = this.taskList.getTaskList(LocalDate.MIN.plusDays(1), LocalDate.now().minusDays(1)); for (Task task : taskList) { @@ -33,12 +46,9 @@ public class BackgroundTasks extends TimerTask { } } - public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) { - this.taskList = taskList; - notifier = new Notifier(taskList, plantList, cropList); - weatherGardenTaskPlaner = new WeatherGradenTaskPlanner(taskList, plantList, cropList); - } - + /** + * Method to call if Tasks should be executed. It calls all Background tasks after each other. + */ @Override public void run() { try { diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java index 072cd25..c28a4b8 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/Notifier.java @@ -13,6 +13,9 @@ 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; @@ -25,6 +28,13 @@ 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()){ @@ -38,6 +48,12 @@ 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))) { diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/EMailSender.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/EMailSender.java index 1fa470c..d77f918 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/EMailSender.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/EMailSender.java @@ -10,16 +10,20 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +/** + * Class to send E-Mails + */ public class EMailSender { - - public 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 void sendMails(String recipients, String subject, String text) throws MessagingException { - // TODO replace printMail with implementation - printMail(recipients, subject, text); // TODO Remove Printing E-Mail to console to test it + printMail(recipients, subject, text); MimeMessage message = new MimeMessage(Settings.getInstance().getSmtpCredentials().getSession()); message.addHeader("Content-type", "text/HTML; charset=UTF-8"); message.addHeader("format", "flowed"); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/SmtpCredentials.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/SmtpCredentials.java index 5e066ec..b2b8737 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/SmtpCredentials.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/email/SmtpCredentials.java @@ -5,6 +5,10 @@ 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, @@ -14,6 +18,10 @@ 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); @@ -23,6 +31,10 @@ 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 @@ -32,10 +44,11 @@ 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()); } - - - } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/SevereWeather.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/SevereWeather.java index fa075e7..a52ffc4 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/SevereWeather.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/SevereWeather.java @@ -1,5 +1,8 @@ package ch.zhaw.gartenverwaltung.backgroundtasks.weather; +/** + * Enum of possible Weather events + */ public enum SevereWeather { FROST,SNOW,HAIL,NO_SEVERE_WEATHER,RAIN } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherGradenTaskPlanner.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherGradenTaskPlanner.java index 4141bea..6f2a38c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherGradenTaskPlanner.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherGradenTaskPlanner.java @@ -17,7 +17,6 @@ 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; diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherService.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherService.java index d189f11..0bbd051 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherService.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/weather/WeatherService.java @@ -1,7 +1,6 @@ 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; @@ -9,6 +8,11 @@ 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; @@ -19,6 +23,11 @@ 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; diff --git a/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java b/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java index 2499d8b..9397a3c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java @@ -152,6 +152,11 @@ public class AppLoader { }); } + /** + * Method to get any AppDependency + * @param type Class of Dependency + * @return the App dependency + */ public Object getAppDependency(Class type) { return dependencies.get(type.getSimpleName()); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/HardinessZoneNotSetException.java b/src/main/java/ch/zhaw/gartenverwaltung/io/HardinessZoneNotSetException.java index cbb7015..1c730ad 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/HardinessZoneNotSetException.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/HardinessZoneNotSetException.java @@ -1,5 +1,8 @@ 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!"); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/InvalidJsonException.java b/src/main/java/ch/zhaw/gartenverwaltung/io/InvalidJsonException.java index 9c3b8dc..2547ff1 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/InvalidJsonException.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/InvalidJsonException.java @@ -2,6 +2,9 @@ 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); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/PlantNotFoundException.java b/src/main/java/ch/zhaw/gartenverwaltung/models/PlantNotFoundException.java index 62035a8..c180005 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/PlantNotFoundException.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/PlantNotFoundException.java @@ -1,5 +1,8 @@ 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!"); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Crop.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Crop.java index e5ea19b..96a78e6 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Crop.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Crop.java @@ -40,7 +40,6 @@ public class Crop { public Optional getCropId() { return Optional.ofNullable(cropId); } - public long getPlantId() { return plantId; } public LocalDate getStartDate() { return startDate; } public double getArea() { return area; } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java index 6e5fc7a..d79b454 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java @@ -4,6 +4,9 @@ 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; From 7741569659a62161bb87c57301c82b3b863f8941 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 11 Dec 2022 14:57:59 +0100 Subject: [PATCH 6/7] Javadocs and code cleanup --- .../java/ch/zhaw/gartenverwaltung/Main.java | 20 +++++++++++++++++-- .../backgroundtasks/BackgroundTasks.java | 6 +++--- .../gartenverwaltung/bootstrap/AppLoader.java | 6 +++++- .../models/PlantListModel.java | 8 ++++---- .../ch/zhaw/gartenverwaltung/types/Plant.java | 2 +- .../models/PlantListModelTest.java | 2 +- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Main.java b/src/main/java/ch/zhaw/gartenverwaltung/Main.java index f757926..65aed31 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Main.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Main.java @@ -13,30 +13,46 @@ 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(); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java index 261f675..e0071a0 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java @@ -55,19 +55,19 @@ public class BackgroundTasks extends TimerTask { movePastTasks(); } catch (IOException e) { e.printStackTrace(); - LOG.log(Level.SEVERE, "Could not execute Background Task: move past Tasks ", e.getCause()); + LOG.log(Level.WARNING, "Could not execute Background Task: move past Tasks ", e.getCause()); } try { weatherGardenTaskPlaner.refreshTasks(); } catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) { e.printStackTrace(); - LOG.log(Level.SEVERE, "Could not execute Background Task: Refresh Tasks by WeatherGardenTaskPlaner ", e.getCause()); + LOG.log(Level.WARNING, "Could not execute Background Task: Refresh Tasks by WeatherGardenTaskPlaner ", e.getCause()); } try { notifier.sendNotifications(); } catch (IOException | MessagingException | HardinessZoneNotSetException e) { e.printStackTrace(); - LOG.log(Level.SEVERE, "Could not execute Background Task: send Notification for due Tasks", e.getCause()); + LOG.log(Level.WARNING, "Could not execute Background Task: send Notification for due Tasks", e.getCause()); } } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java b/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java index 9397a3c..b6c8d6a 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java @@ -1,5 +1,6 @@ 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; @@ -17,12 +18,15 @@ 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 */ @@ -146,7 +150,7 @@ public class AppLoader { try { afterInjectMethod.invoke(controller); } catch (IllegalAccessException | InvocationTargetException e) { - // TODO: Log + LOG.log(Level.SEVERE, "Could not invoke afterInjectMethod", e.getCause()); e.printStackTrace(); } }); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java index 19cce96..33627c9 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java @@ -1,5 +1,6 @@ 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; @@ -16,7 +17,6 @@ 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() { - currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Settings + Settings.getInstance().setCurrentHardinessZone(null); } public void setCurrentZone(HardinessZone currentZone) { - this.currentZone = currentZone; + Settings.getInstance().setCurrentHardinessZone(currentZone); } public HardinessZone getCurrentZone() { - return currentZone; + return Settings.getInstance().getCurrentHardinessZone(); } /** diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java index dd92412..d1a0905 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java @@ -68,7 +68,7 @@ public record Plant( return growthPhase.group(); } } - return 0; // TODO implement + return 0; } /** diff --git a/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java b/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java index 5f71e1f..19b68e8 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java @@ -101,7 +101,7 @@ class PlantListModelTest { @Test void setCurrentZone() { - checkCurrentZone(HardinessZone.ZONE_8A); // TODO change to get default zone from config + checkCurrentZone(HardinessZone.ZONE_8A); model.setCurrentZone(HardinessZone.ZONE_1A); checkCurrentZone(HardinessZone.ZONE_1A); model.setCurrentZone(HardinessZone.ZONE_8A); From 6aeda395c32260397fae5cc9d03f97287b6b02d2 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 11 Dec 2022 14:58:15 +0100 Subject: [PATCH 7/7] Javadocs and code cleanup --- .../ch/zhaw/gartenverwaltung/Settings.java | 66 +++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Settings.java b/src/main/java/ch/zhaw/gartenverwaltung/Settings.java index 8433dce..491db5d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Settings.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Settings.java @@ -6,21 +6,58 @@ 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 { - private static final Settings instance; - private HardinessZone currentHardinessZone = HardinessZone.ZONE_8A; - private final BooleanProperty showTutorial = new SimpleBooleanProperty(false); - 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); - // 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"; - 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 + /* + * 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 + */ + 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"; + + /** + * Location of the garden can be set by user (Used for Weather Service) + */ private String location = ""; + /* + Create Instance of Settings + */ static { instance = new Settings(); } @@ -29,14 +66,21 @@ 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 = currentHardinessZone; + this.currentHardinessZone = Objects.requireNonNullElse(currentHardinessZone, HardinessZone.ZONE_8A); } public void setShowTutorial (boolean showTutorial) {