From 29b064ef973ca1227f18fb3832ed89cec5516837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Mon, 21 Oct 2024 13:52:55 +0200 Subject: [PATCH] Metadata status changes notification mails improvements: - Don't add saludation if the user to notify is the catalogue administrator (defined in settings), as only has the email address. - Filter out the users without mail when retrieving the users to notify --- .../kernel/metadata/DefaultStatusActions.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/kernel/metadata/DefaultStatusActions.java b/core/src/main/java/org/fao/geonet/kernel/metadata/DefaultStatusActions.java index 58cc82a4459..8c0c0ca2b33 100644 --- a/core/src/main/java/org/fao/geonet/kernel/metadata/DefaultStatusActions.java +++ b/core/src/main/java/org/fao/geonet/kernel/metadata/DefaultStatusActions.java @@ -48,6 +48,8 @@ import org.springframework.context.ApplicationContext; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.fao.geonet.kernel.setting.Settings.SYSTEM_FEEDBACK_EMAIL; import static org.fao.geonet.util.LocalizedEmailComponent.ComponentType.*; @@ -330,22 +332,24 @@ protected void notify(List userToNotify, MetadataStatus status) throws Exc ); } - LocalizedEmail localizedEmail = new LocalizedEmail(false); - localizedEmail.addComponents(emailSubjectComponent, emailMessageComponent, emailSalutationComponent); - - String subject = localizedEmail.getParsedSubject(feedbackLocales); - for (User user : userToNotify) { + LocalizedEmail localizedEmail = new LocalizedEmail(false); + String userName = Joiner.on(" ").skipNulls().join(user.getName(), user.getSurname()); //If we have a userName add the salutation String message; if (StringUtils.isEmpty(userName)) { + localizedEmail.addComponents(emailSubjectComponent, emailMessageComponent); + message = localizedEmail.getParsedMessage(feedbackLocales); } else { + localizedEmail.addComponents(emailSubjectComponent, emailMessageComponent, emailSalutationComponent); + Map replacements = new HashMap<>(); replacements.put("{{userName}}", userName); message = localizedEmail.getParsedMessage(feedbackLocales, replacements); } + String subject = localizedEmail.getParsedSubject(feedbackLocales); sendEmail(user.getEmail(), subject, message); } } @@ -449,7 +453,9 @@ public static List getUserToNotify(StatusValueNotificationLevel notificati } } } - return users; + + // Filter out users without email + return users.stream().filter(u -> StringUtils.isNotEmpty(u.getEmail())).collect(Collectors.toList()); } public static List getGroupToNotify(StatusValueNotificationLevel notificationLevel, List groupNames) {