From 933346e5fa286fbe30d926d458b361dc6b9e2395 Mon Sep 17 00:00:00 2001
From: Lars Johansson <lars.johansson@ess.eu>
Date: Mon, 15 Jan 2024 13:51:49 +0100
Subject: [PATCH] Refactor notification scheduling to read schedule from
 configuration

---
 CONFIGURATION.md                              | 27 ++++++++++---------
 .../notification/NotificationScheduler.java   |  2 +-
 src/main/resources/application.properties     |  4 ++-
 src/test/resources/application.properties     |  4 ++-
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index fd31a790..47c45f5b 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -4,16 +4,17 @@ Configuration may be set using SpringBoot's configuration file (`application.pro
 
 ##### Environment variables
 
-| Variable                   | Default                                     | Description                                           |
-|----------------------------|---------------------------------------------|-------------------------------------------------------|
-| NAMING_BACKEND_SWAGGER_URL | http://localhost:8080/swagger-ui.html       | default url for Swagger UI                            |
-| NAMING_DATABASE_URL        | jdbc:postgresql://postgres:5432/discs_names | JDBC URL for the database connection                  |
-| NAMING_DATABASE_USERNAME   | discs_names                                 | user name for the database connection                 |
-| NAMING_DATABASE_PASSWORD   | discs_names                                 | password for the database connection                  |
-| NAMING_LOGGING_LEVEL       | INFO                                        | log level for application                             |
-| NAMING_MAIL_ADMINISTRATOR  |                                             | comma-separated list of administrator email addresses |
-| NAMING_MAIL_NOTIFICATION   | false                                       | true/false if mail notications are to be sent         |
-| NAMING_SMTP_HOST           | mail.esss.lu.se                             | DNS name of server that accepts connections for SMTP  |
-| NAMING_SMTP_PORT           | 587                                         | port to use for SMTP, 587 for SMTP Secure             |
-| NAMING_SMTP_USERNAME       |                                             | username for SMTP server                              |
-| NAMING_SMTP_PASSWORD       |                                             | password for SMTP server                              |
+| Variable                   | Default                                     | Description                                                                                                            |
+|----------------------------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
+| NAMING_BACKEND_SWAGGER_URL | http://localhost:8080/swagger-ui.html       | default url for Swagger UI                                                                                             |
+| NAMING_DATABASE_URL        | jdbc:postgresql://postgres:5432/discs_names | JDBC URL for the database connection                                                                                   |
+| NAMING_DATABASE_USERNAME   | discs_names                                 | user name for the database connection                                                                                  |
+| NAMING_DATABASE_PASSWORD   | discs_names                                 | password for the database connection                                                                                   |
+| NAMING_LOGGING_LEVEL       | INFO                                        | log level for application                                                                                              |
+| NAMING_MAIL_ADMINISTRATOR  |                                             | comma-separated list of administrator email addresses                                                                  |
+| NAMING_MAIL_NOTIFICATION   | false                                       | true/false if mail notications are to be sent                                                                          |
+| NAMING_NOTIFY_SCHEDULE     | 0 0 5 * * *                                 | schedule for notification job, cron expression with six or seven fields to describe individual details of the schedule |
+| NAMING_SMTP_HOST           | mail.esss.lu.se                             | DNS name of server that accepts connections for SMTP                                                                   |
+| NAMING_SMTP_PORT           | 587                                         | port to use for SMTP, 587 for SMTP Secure                                                                              |
+| NAMING_SMTP_USERNAME       |                                             | username for SMTP server                                                                                               |
+| NAMING_SMTP_PASSWORD       |                                             | password for SMTP server                                                                                               |
diff --git a/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java b/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java
index 3258e727..2124ae3c 100644
--- a/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java
+++ b/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java
@@ -68,7 +68,7 @@ public class NotificationScheduler {
      * <br/><br/>
      * Scheduling is handled with cron expression.
      */
-    @Scheduled(cron = "0 0 5 * * *")
+    @Scheduled(cron = "${naming.notify.schedule}")
     public void notifyAdministrators() {
         notifyAdministratorsForNames();
     }
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index aabb0d7a..2a346043 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -12,8 +12,10 @@ logging.level.org.springframework.web=INFO
 logging.level.org.hibernate.SQL=INFO
 spring.http.log-request-details=true
 
-# mail
+# mail, notification
 #     administrator mail is comma-separated list of email addresses
+#     notification job scheduled at 5 am every day by default
+naming.notify.schedule=${NAMING_NOTIFY_SCHEDULE:0 0 5 * * *}
 naming.mail.administrator=${NAMING_MAIL_ADMINISTRATOR:}
 naming.mail.notification=${NAMING_MAIL_NOTIFICATION:false}
 naming.mail.from=${NAMING_MAIL_FROM:jboss@ess.eu}
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index cd149334..fc88cf5c 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -12,8 +12,10 @@ logging.level.org.springframework.web=INFO
 logging.level.org.hibernate.SQL=INFO
 spring.http.log-request-details=true
 
-# mail
+# mail, notification
 #     administrator mail is comma-separated list of email addresses
+#     notification job scheduled at 5 am every day by default
+naming.notify.schedule=${NAMING_NOTIFY_SCHEDULE:0 0 5 * * *}
 naming.mail.administrator=${NAMING_MAIL_ADMINISTRATOR:}
 naming.mail.notification=${NAMING_MAIL_NOTIFICATION:false}
 naming.mail.from=${NAMING_MAIL_FROM:jboss@ess.eu}
-- 
GitLab