Skip to content

Commit 62cd0ad

Browse files
authored
Add new recordProfileUserAdmin notification level (geonetwork#8779)
* Add new recordProfileUserAdmin notification level * Add null profile checks in case of a misconfigured notification level * Filter out records with no group from notification when a recordProfile notification level is set
1 parent 44cd1a5 commit 62cd0ad

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

core/src/main/java/org/fao/geonet/kernel/metadata/DefaultStatusActions.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,14 @@ public static List<User> getUserToNotify(StatusValueNotificationLevel notificati
412412
if (owner.isPresent()) {
413413
users.add(owner.get());
414414
}
415-
} else if (notificationLevel == StatusValueNotificationLevel.recordProfileReviewer) {
416-
List<Pair<Integer, User>> results = userRepository.findAllByGroupOwnerNameAndProfile(recordIds, Profile.Reviewer);
415+
} else if (notificationLevel.name().startsWith("recordProfile")) {
416+
String profileId = notificationLevel.name().replace("recordProfile", "");
417+
Profile profile = Profile.findProfileIgnoreCase(profileId);
418+
if (profile == null) {
419+
Log.error(Geonet.DATA_MANAGER, "Invalid notification level is configured '" + notificationLevel + "' The associated profile '" + profileId + "' does not exist.");
420+
return users;
421+
}
422+
List<Pair<Integer, User>> results = userRepository.findAllByGroupOwnerNameAndProfile(recordIds, profile);
417423
Collections.sort(results, Comparator.comparing(s -> s.two().getName()));
418424
for (Pair<Integer, User> p : results) {
419425
users.add(p.two());
@@ -441,6 +447,10 @@ public static List<User> getUserToNotify(StatusValueNotificationLevel notificati
441447
} else if (notificationLevel.name().startsWith("catalogueProfile")) {
442448
String profileId = notificationLevel.name().replace("catalogueProfile", "");
443449
Profile profile = Profile.findProfileIgnoreCase(profileId);
450+
if (profile == null) {
451+
Log.error(Geonet.DATA_MANAGER, "Invalid notification level is configured '" + notificationLevel + "' The associated profile '" + profileId + "' does not exist.");
452+
return users;
453+
}
444454
users = userRepository.findAllByProfile(profile);
445455
} else if (notificationLevel == StatusValueNotificationLevel.catalogueAdministrator) {
446456
SettingManager settingManager = ApplicationContextHolder.get().getBean(SettingManager.class);

domain/src/main/java/org/fao/geonet/domain/StatusValueNotificationLevel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public enum StatusValueNotificationLevel {
6363
* When assigned should notify the reviewers part of the record group owner.
6464
*/
6565
recordProfileReviewer,
66+
/**
67+
* When assigned should notify the user administrators part of the record group owner.
68+
*/
69+
recordProfileUserAdmin,
6670
/**
6771
* When assigned should notify the record author.
6872
*/

services/src/main/java/org/fao/geonet/util/MetadataPublicationMailNotifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ public void notifyPublication(Locale[] feedbackLocales,
7575
StatusValueNotificationLevel.valueOf(notificationSetting);
7676
if (notificationLevel != null) {
7777

78-
if (notificationLevel == StatusValueNotificationLevel.recordProfileReviewer) {
78+
if (notificationLevel.name().startsWith("recordProfile")) {
7979
Map<Integer, List<MetadataPublicationNotificationInfo>> metadataListToNotifyPublicationPerGroup =
8080
metadataListToNotifyPublication.stream()
81+
.filter(metadata -> metadata.getGroupId() != null)
8182
.collect(Collectors.groupingBy(MetadataPublicationNotificationInfo::getGroupId));
8283

8384
// Process the metadata published by group owner

web-ui/src/main/resources/catalog/locales/en-admin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,7 @@
15031503
"notificationLevel-catalogueProfileRegisteredUser": "Notify the catalogue registered user",
15041504
"notificationLevel-catalogueProfileGuest": "Notify the catalogue guest",
15051505
"notificationLevel-recordProfileReviewer": "Notify the reviewers part of the record group owner",
1506+
"notificationLevel-recordProfileUserAdmin": "Notify the user administrators part of the record group owner",
15061507
"notificationLevel-recordUserAuthor": "Notify the record author",
15071508
"notificationLevel-recordGroupEmail": "Notify the group(s) emails",
15081509
"confirmMapserverDelete": "Are you sure you want to delete this Map server?",

0 commit comments

Comments
 (0)