From 73af3ed11731abaa90e39a02252e9d890694cdc0 Mon Sep 17 00:00:00 2001 From: Jayasudha Sundaram Date: Fri, 6 Dec 2024 10:28:55 -0500 Subject: [PATCH] CNDE - 1928 add the logic to handle muliple email address --- .../service/EmailService.java | 31 ++++++++++++++++--- .../src/main/resources/application.yaml | 2 ++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/DataCompareESender/src/main/java/gov/cdc/datacompareesender/service/EmailService.java b/DataCompareESender/src/main/java/gov/cdc/datacompareesender/service/EmailService.java index fd64d22..5f8a5a8 100644 --- a/DataCompareESender/src/main/java/gov/cdc/datacompareesender/service/EmailService.java +++ b/DataCompareESender/src/main/java/gov/cdc/datacompareesender/service/EmailService.java @@ -17,8 +17,9 @@ import software.amazon.awssdk.services.ses.model.*; import java.time.Duration; -import java.time.Instant; -import java.util.Date; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; @Service @Slf4j @@ -30,6 +31,9 @@ public class EmailService { @Value("${aws.ses.source-email}") private String sourceEmail; + @Value("${aws.ses.recipient-emails}") + private String recipientEmails; + @Value("${aws.s3.bucket-name}") private String bucketName; @@ -89,8 +93,7 @@ public void sendComparisonEmail(EmailEventModel emailEvent) { SendEmailRequest request = SendEmailRequest.builder() .source(sourceEmail) // Sender's email .destination(Destination.builder() - // TODO: REPLACE WITH ENVIRONMENT VARIABLE, something like RECIPIENT_EMAIL: {LIST of email such as "email1, email2, etc..."} - .toAddresses("ndduc1856@gmail.com") // Add recipient emails here + .toAddresses(getRecipientEmailList()) .build()) .message(Message.builder() .subject(Content.builder() @@ -142,4 +145,24 @@ private String buildEmailContent(EmailEventModel event, String reportUrl) { return content.toString(); } + + private List getRecipientEmailList() { + if (recipientEmails == null || recipientEmails.trim().isEmpty()) { + log.error("No recipient emails configured"); + throw new IllegalStateException("No recipient emails configured"); + } + + List emailList = Arrays.stream(recipientEmails.split(",")) + .map(String::trim) + .filter(email -> !email.isEmpty()) + .collect(Collectors.toList()); + + if (emailList.isEmpty()) { + log.error("No valid recipient emails found after parsing"); + throw new IllegalStateException("No valid recipient emails found after parsing"); + } + + log.debug("Processed {} recipient email(s)", emailList.size()); + return emailList; + } } \ No newline at end of file diff --git a/DataCompareESender/src/main/resources/application.yaml b/DataCompareESender/src/main/resources/application.yaml index 01c1a0b..4a60d89 100644 --- a/DataCompareESender/src/main/resources/application.yaml +++ b/DataCompareESender/src/main/resources/application.yaml @@ -23,3 +23,5 @@ aws: url-expiration-hours: 48 ses: source-email: support@datateam-cdc-nbs.eqsandbox.com + recipient-emails: ${RECIPIENT_EMAILS} +