Skip to content

Commit

Permalink
[BP] Send metadata mail notifications for public metadata when is re-…
Browse files Browse the repository at this point in the history
…approved - fill missing information for submitter, reviewer and publisher user (#7292)
  • Loading branch information
josegar74 committed Sep 29, 2023
1 parent 5229912 commit 4569d68
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,31 @@ public Map<Integer, StatusChangeType> setStatus(@Parameter(description = API_PAR
metadataNotificationInfo.setPublicationDateStamp(new ISODate());
metadataNotificationInfo.setReapproval(metadataIdApproved != metadata.getId());

metadataListToNotifyPublication.add(metadataNotificationInfo);

metadataPublicationMailNotifier.notifyPublication(messages, context.getLanguage(), metadataListToNotifyPublication);
// If the metadata workflow is enabled retrieve the submitter and reviewer users information
if (isMdWorkflowEnable) {
String sortField = SortUtils.createPath(MetadataStatus_.changeDate);
List<MetadataStatus> statusList = metadataStatusRepository.findAllByMetadataIdAndByType(metadata.getId(),
StatusValueType.workflow, Sort.by(Sort.Direction.DESC, sortField));

java.util.Optional<User> reviewerUser = userRepository.findById(metadataStatusValue.getUserId());
reviewerUser.ifPresent(user -> {
metadataNotificationInfo.setReviewerUser(user.getUsername());
// Set publisher to the reviewer user that approved the metadata
metadataNotificationInfo.setPublisherUser(user.getUsername());
});

java.util.Optional<MetadataStatus> submittedStatus = statusList.stream().filter(status1 ->
status1.getStatusValue().getId() == Integer.parseInt(StatusValue.Status.SUBMITTED)).findFirst();
if (submittedStatus.isPresent()) {
java.util.Optional<User> submitterUser = userRepository.findById(submittedStatus.get().getUserId());
submitterUser.ifPresent(user -> metadataNotificationInfo.setSubmitterUser(user.getUsername()));
}
}

metadataListToNotifyPublication.add(metadataNotificationInfo);

metadataPublicationMailNotifier.notifyPublication(messages, context.getLanguage(), metadataListToNotifyPublication);
}
return statusUpdate;
}
Expand Down

0 comments on commit 4569d68

Please sign in to comment.