Skip to content

Commit

Permalink
Metadata status changes notification mails improvements:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
josegar74 committed Oct 21, 2024
1 parent 5b01f64 commit 29b064e
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -330,22 +332,24 @@ protected void notify(List<User> 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<String, String> replacements = new HashMap<>();
replacements.put("{{userName}}", userName);
message = localizedEmail.getParsedMessage(feedbackLocales, replacements);
}
String subject = localizedEmail.getParsedSubject(feedbackLocales);
sendEmail(user.getEmail(), subject, message);
}
}
Expand Down Expand Up @@ -449,7 +453,9 @@ public static List<User> 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<Group> getGroupToNotify(StatusValueNotificationLevel notificationLevel, List<String> groupNames) {
Expand Down

0 comments on commit 29b064e

Please sign in to comment.