Skip to content
Snippets Groups Projects
Commit ecfd378b authored by Lars Johansson's avatar Lars Johansson
Browse files

Update notification of names and structures

Update notification of names and structures to not rely on database table
for usernames to which to send notifications.
parent cf5677ec
No related branches found
No related tags found
1 merge request!10Update notification of names and structures
......@@ -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 |
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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}
......
......@@ -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}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment