diff --git a/CONFIGURATION.md b/CONFIGURATION.md index f167e222d345095983f8047a80e218ee9f070c9a..f9902829c30320e2841bc85385858bd9651b9690 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -15,6 +15,7 @@ Configuration may be set using SpringBoot's configuration file (`application.pro | NAMING_LOGGING_STACKTRACE_LENGTH | 20 | max number of stack trace elements to log, negative value will log entire stack trace | | NAMING_MAIL_ADMINISTRATOR | | comma-separated list of administrator email addresses | | NAMING_MAIL_NOTIFICATION | false | true/false if mail notications are to be sent | +| NAMING_MAIL_NOTIFICATION_NAMES | | comma-separated list of email addresses to which to send notications about changes for names | | 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 | diff --git a/src/main/java/org/openepics/names/service/NotificationService.java b/src/main/java/org/openepics/names/service/NotificationService.java index fc6213460319a725f6a18f5ecba156060af38bc2..a0fde73c11f130001c28bf4826347bd55a0ce009 100644 --- a/src/main/java/org/openepics/names/service/NotificationService.java +++ b/src/main/java/org/openepics/names/service/NotificationService.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.lang3.StringUtils; +import org.apache.commons.compress.utils.Lists; import org.openepics.names.util.NameCommand; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.ValidateUtil; @@ -60,10 +60,13 @@ public class NotificationService { private static final String ADD_FOOTER = "addfooter"; private static final String BACKEND_URL = "backendurl"; - private static final String COMMA = ","; @Value("${naming.mail.administrator}") - String namingMailAdministrator; + List<String> namingMailAdministrator; + @Value("${naming.mail.notification.names}") + List<String> namingMailNotificationNames; + @Value("${naming.mail.notification.structures}") + List<String> namingMailNotificationStructures; @Value("${naming.swagger.url}") String namingSwaggerUrl; @@ -76,7 +79,7 @@ public class NotificationService { } /** - * Send notifications for names to affected users and administrators by email. + * Send notifications for names to administrators and affected users by email. * * @param notifications list of name notifications * @param nameCommand name command @@ -92,7 +95,7 @@ public class NotificationService { } /** - * Send notifications for names to affected users and administrators by email. + * Send notifications for names to administrators and affected users by email. * * @param created list of notifications for created names * @param updated list of notifications for updated names @@ -134,19 +137,27 @@ public class NotificationService { ctx.setVariable(BACKEND_URL, namingSwaggerUrl); TemplateEngine engine = generateTemplateEngine(); + // email addresses for notification + // administrators + // set of users - about changes for names + List<String> toEmailAddresses = Lists.newArrayList(); + if (!namingMailAdministrator.isEmpty()) { + toEmailAddresses.addAll(namingMailAdministrator); + } + if (!namingMailNotificationNames.isEmpty()) { + toEmailAddresses.addAll(namingMailNotificationNames); + } + // send notification - String[] toEmailAddresses = !StringUtils.isEmpty(namingMailAdministrator) - ? namingMailAdministrator.split(COMMA) - : null; String[] ccEmailAddresses = null; String[] replyToEmailAddresses = null; String subject = CHANGES_NOTIFICATION_NAMES + " - " + namingSwaggerUrl; - mailService.sendEmail(toEmailAddresses, ccEmailAddresses, replyToEmailAddresses, + mailService.sendEmail(toEmailAddresses.toArray(new String[0]), ccEmailAddresses, replyToEmailAddresses, subject, engine.process("templates/notification_names.html", ctx), false, null, null); } /** - * Send notifications for structures to affected users and administrators by email. + * Send notifications for structures to administrators and affected users by email. * * @param notifications list of structure notifications * @param structureCommand structure command @@ -162,7 +173,7 @@ public class NotificationService { } /** - * Send notifications for structures to affected users and administrators by email. + * Send notifications for structures to administrators and affected users by email. * * @param created list of notifications for created structures * @param updated list of notifications for updated structures @@ -204,14 +215,22 @@ public class NotificationService { ctx.setVariable(BACKEND_URL, namingSwaggerUrl); TemplateEngine engine = generateTemplateEngine(); + // email addresses for notification + // administrators + // set of users - about changes for structures + List<String> toEmailAddresses = Lists.newArrayList(); + if (!namingMailAdministrator.isEmpty()) { + toEmailAddresses.addAll(namingMailAdministrator); + } + if (!namingMailNotificationStructures.isEmpty()) { + toEmailAddresses.addAll(namingMailNotificationStructures); + } + // send notification - String[] toEmailAddresses = !StringUtils.isEmpty(namingMailAdministrator) - ? namingMailAdministrator.split(COMMA) - : null; String[] ccEmailAddresses = null; String[] replyToEmailAddresses = null; String subject = CHANGES_NOTIFICATION_STRUCTURES + " - " + namingSwaggerUrl; - mailService.sendEmail(toEmailAddresses, ccEmailAddresses, replyToEmailAddresses, + mailService.sendEmail(toEmailAddresses.toArray(new String[0]), ccEmailAddresses, replyToEmailAddresses, subject, engine.process("templates/notification_structures.html", ctx), false, null, null); } 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 ccebc8d047080956354cfbe67ddaad0be95b17e3..1d99d0e9ba85258acf4dd013d214353eda6c66d2 100644 --- a/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java +++ b/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java @@ -66,24 +66,23 @@ public class NotificationScheduler { } /** - * Notify administrators about changes for names and structures. + * Notify administrators and affected users about changes for names and structures. * Intention is to inform about changes for names (create, update, delete). * It is to be checked once a day, and notifications to be generated with emails. - * Emails is to have limited size of entries and another email is to be generated with if size is greater than limit. * * <br/><br/> * Scheduling is handled with cron expression. */ @Scheduled(cron = "${naming.notify.schedule}") - public void notifyAdministrators() { - notifyAdministratorsForNames(); + public void notifyForNames() { + prepareAndNotifyForNames(); } /** * Find out which names that are created, updated or deleted the previous day - * and send notification to administrators for those names. + * and send notification to administrators and affected users for those names. */ - private void notifyAdministratorsForNames() { + private void prepareAndNotifyForNames() { // prepare // find names for previous day // find changes for names diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 96d6f369a1434179f8c1060a66ea7e2360f12d4c..7655d823cc097f1c3522300c22f53f23f814f69f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,11 +18,14 @@ logging.level.org.hibernate.SQL=INFO spring.http.log-request-details=true # mail, notification -# administrator mail is comma-separated list of email addresses +# administrator mail - comma-separated list of email addresses +# notification mail - 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.notification.names=${NAMING_MAIL_NOTIFICATION_NAMES:} +naming.mail.notification.structures=${NAMING_MAIL_NOTIFICATION_STRUCTURES:} naming.mail.from=${NAMING_MAIL_FROM:jboss@ess.eu} naming.smtp.host=${NAMING_SMTP_HOST:mail.esss.lu.se} naming.smtp.port=${NAMING_SMTP_PORT:587} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 5370eee31767f7d0c5e2d841e639caa6a3750a59..fc49f4c13c7a21160da0ed3b37bbbb9a41703334 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -18,11 +18,14 @@ logging.level.org.hibernate.SQL=INFO spring.http.log-request-details=true # mail, notification -# administrator mail is comma-separated list of email addresses +# administrator mail - comma-separated list of email addresses +# notification mail - 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.notification.names=${NAMING_MAIL_NOTIFICATION_NAMES:} +naming.mail.notification.structures=${NAMING_MAIL_NOTIFICATION_STRUCTURES:} naming.mail.from=${NAMING_MAIL_FROM:jboss@ess.eu} naming.smtp.host=${NAMING_SMTP_HOST:mail.esss.lu.se} naming.smtp.port=${NAMING_SMTP_PORT:587}