From 9b793d3e082ac811c5dd6db14d15eaf28424f093 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Mon, 16 Oct 2023 15:35:27 -0400 Subject: [PATCH] Populate submission as needed for notification --- .../pass/notification/service/Composer.java | 5 -- .../service/NotificationService.java | 42 +++++---- .../service/NotificationServiceIT.java | 88 +++++++++++++++++++ 3 files changed, 113 insertions(+), 22 deletions(-) diff --git a/pass-notification-service/src/main/java/org/eclipse/pass/notification/service/Composer.java b/pass-notification-service/src/main/java/org/eclipse/pass/notification/service/Composer.java index 4e6d0b37..75f6fc94 100644 --- a/pass-notification-service/src/main/java/org/eclipse/pass/notification/service/Composer.java +++ b/pass-notification-service/src/main/java/org/eclipse/pass/notification/service/Composer.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.HashMap; -import java.util.Objects; import java.util.function.BiFunction; import com.fasterxml.jackson.databind.ObjectMapper; @@ -79,11 +78,7 @@ public class Composer implements BiFunction receivedMessages = Arrays.asList(greenMail.getReceivedMessages()); + // 3 = 1 To + 1 CC + 1 BCC + assertEquals(3, receivedMessages.size()); + + MimeMessage message = receivedMessages.get(0); + assertTrue(message.getSubject().contains("PASS Submission Approval: Specific protein")); + assertEquals(SENDER, message.getFrom()[0].toString()); + assertEquals(CC, message.getRecipients(MimeMessage.RecipientType.CC)[0].toString()); + assertEquals(RECIPIENT, message.getRecipients(MimeMessage.RecipientType.TO)[0].toString()); + assertEquals(expectedBody, message.getContent().toString()); + } + private SubmissionEvent stagePassData() throws IOException { // This User prepares the submission on behalf of the Submission.submitter // Confusingly, this User has the ability to submit to PASS. The authorization-related role of @@ -185,4 +215,62 @@ private SubmissionEvent stagePassData() throws IOException { return event; } + + private SubmissionEvent stagePassDataSubmitter() throws IOException { + // This User prepares the submission on behalf of the Submission.submitter + // Confusingly, this User has the ability to submit to PASS. The authorization-related role of + // User.Role.SUBMITTER should not be confused with the the logical role as a preparer of a submission. + User preparer = new User(); + preparer.setEmail("emetsger@gmail.com"); + preparer.setDisplayName("Submission Preparer"); + preparer.setFirstName("Pre"); + preparer.setLastName("Parer"); + preparer.setRoles(List.of(UserRole.SUBMITTER)); + + passClient.createObject(preparer); + + User submitter = new User(); + submitter.setEmail(RECIPIENT); + submitter.setDisplayName("Submission Submitter"); + submitter.setFirstName("Sub"); + submitter.setLastName("Mitter"); + submitter.setRoles(List.of(UserRole.SUBMITTER)); + + passClient.createObject(submitter); + + // The Submission as prepared by the preparer. + // The preparer did not find the authorized submitter in PASS, so they filled in the email address of the + // authorized submitter. Therefore, the Submission.submitter field will be null (because that *must* be a URI + // to a User resource, and the User does not exist). The Submission.submitterEmail will be set to the email + // address of the authorized submitter + Submission submission = new Submission(); + submission.setMetadata(resourceToString("/" + PathUtil.packageAsPath(this.getClass()) + + "/submission-metadata.json", StandardCharsets.UTF_8)); + submission.setPreparers(List.of(preparer)); + submission.setSource(Source.PASS); + submission.setSubmitter(submitter); + + passClient.createObject(submission); + + // When this event is processed, the authorized submitter will recieve an email notification with a link that + // will invite them to use PASS, and link the Submission to their newly created User (created when they login + // to PASS for the first time) + SubmissionEvent event = new SubmissionEvent(); + event.setSubmission(submission); + event.setPerformerRole(PerformerRole.PREPARER); + event.setPerformedBy(preparer); + String comment = "How does this submission look?"; + event.setComment(comment); + event.setEventType(EventType.APPROVAL_REQUESTED_NEWUSER); + event.setPerformedDate(ZonedDateTime.now()); + + String submissionId = submission.getId(); + Link link = new Link(URI.create(submissionId + .replace("http://localhost", "https://pass.local")), SUBMISSION_REVIEW_INVITE); + event.setLink(link.getHref()); + + passClient.createObject(event); + + return event; + } }