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) {