-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
435 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.ilgcc.app.email; | ||
|
||
import lombok.Getter; | ||
import com.sendgrid.helpers.mail.objects.Content; | ||
import com.sendgrid.helpers.mail.objects.Email; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
public class ILGCCEmail { | ||
|
||
public static final String FROM_ADDRESS = "[email protected]"; | ||
public static final String EMAIL_SENDER_KEY = "email.general.sender-name"; | ||
|
||
private Email senderEmail; | ||
private String subject; | ||
private Content body; | ||
private EmailType emailType; | ||
private UUID submissionId; | ||
private Email recipientEmail; | ||
|
||
public ILGCCEmail(String senderName, String recipientAddress, String subject, Content body, EmailType emailType, | ||
UUID submissionId) { | ||
this.senderEmail = new Email(FROM_ADDRESS, senderName); | ||
this.recipientEmail = new Email(recipientAddress); | ||
this.subject = subject; | ||
this.body = body; | ||
this.emailType = emailType; | ||
this.submissionId = submissionId; | ||
} | ||
|
||
|
||
public static ILGCCEmail createProviderConfirmationEmail(String senderName, String recipientAddress, String subject, | ||
Content body, UUID submissionId) { | ||
return new ILGCCEmail(senderName, recipientAddress, subject, body, EmailType.PROVIDER_CONFIRMATION_EMAIL, submissionId); | ||
} | ||
|
||
@Getter | ||
public enum EmailType { | ||
FAMILY_CONFIRMATION_EMAIL("Family Confirmation Email"), FAMILY_CONFIRMATION_EMAIL_NO_PROVIDER( | ||
"No Provider Family Confirmation Email"), PROVIDER_AGREES_TO_CARE_FAMILY_EMAIL( | ||
"Provider Agrees to Care Family Email"), PROVIDER_CONFIRMATION_EMAIL("Provider confirmation email"); | ||
|
||
private final String description; | ||
|
||
EmailType(String description) { | ||
this.description = description; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/org/ilgcc/app/submission/actions/SendProviderConfirmationEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package org.ilgcc.app.submission.actions; | ||
|
||
import static org.ilgcc.app.utils.ProviderSubmissionUtilities.formatListIntoReadableString; | ||
import static org.ilgcc.app.utils.ProviderSubmissionUtilities.getCombinedDataForEmails; | ||
|
||
import com.sendgrid.helpers.mail.objects.Content; | ||
import formflow.library.config.submission.Action; | ||
import formflow.library.data.Submission; | ||
import formflow.library.data.SubmissionRepositoryService; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.ilgcc.app.email.ILGCCEmail; | ||
import org.ilgcc.app.utils.ProviderSubmissionUtilities; | ||
import org.ilgcc.jobs.SendEmailJob; | ||
import org.springframework.context.MessageSource; | ||
|
||
@Slf4j | ||
public class SendProviderConfirmationEmail implements Action { | ||
|
||
protected static String EMAIL_SENT_STATUS_INPUT_NAME = "providerConfirmationEmailSent"; | ||
protected static String RECIPIENT_EMAIL_INPUT_NAME = "providerResponseContactEmail"; | ||
|
||
protected static MessageSource messageSource; | ||
|
||
protected final SubmissionRepositoryService submissionRepositoryService; | ||
|
||
protected final SendEmailJob sendEmailJob; | ||
|
||
public SendProviderConfirmationEmail(SendEmailJob sendEmailJob, MessageSource messageSource, SubmissionRepositoryService submissionRepositoryService) { | ||
this.sendEmailJob = sendEmailJob; | ||
this.messageSource = messageSource; | ||
this.submissionRepositoryService = submissionRepositoryService; | ||
} | ||
|
||
@Override | ||
public void run(Submission submission) { | ||
if (!skipEmailSend(submission)) { | ||
Locale locale = | ||
submission.getInputData().getOrDefault("languageRead", "English").equals("Spanish") ? Locale.forLanguageTag( | ||
"es") : Locale.ENGLISH; | ||
Optional<Map<String, Object>> emailData = getEmailData(submission); | ||
|
||
if (emailData.isEmpty()) { | ||
return; | ||
} | ||
|
||
ILGCCEmail email = ILGCCEmail.createProviderConfirmationEmail(getSenderName(locale), getRecipientEmail(submission), | ||
setSubject(emailData.get(), locale), new Content("text/html", setBodyCopy(emailData.get(), locale)), | ||
submission.getId()); | ||
sendEmail(email, submission); | ||
} | ||
} | ||
|
||
protected Boolean skipEmailSend(Submission submission) { | ||
boolean emailSent = submission.getInputData().getOrDefault(EMAIL_SENT_STATUS_INPUT_NAME, "false").equals("true"); | ||
boolean providerAgreedToCare = submission.getInputData().getOrDefault("providerResponseAgreeToCare", "false") | ||
.equals("true"); | ||
|
||
return emailSent || !providerAgreedToCare; | ||
} | ||
|
||
protected Optional<Map<String, Object>> getEmailData(Submission providerSubmission) { | ||
Optional<Submission> familySubmission = getFamilyApplication(providerSubmission); | ||
if (familySubmission.isPresent()) { | ||
return Optional.of(getCombinedDataForEmails(providerSubmission, familySubmission.get())); | ||
} else { | ||
log.warn("Could not send Email. No family submission is associated with the providerSubmissionId: {}", | ||
providerSubmission.getId()); | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
protected static String getSenderName(Locale locale) { | ||
return messageSource.getMessage(ILGCCEmail.EMAIL_SENDER_KEY, null, locale); | ||
} | ||
|
||
protected static String getRecipientEmail(Submission submission) { | ||
return submission.getInputData().getOrDefault(RECIPIENT_EMAIL_INPUT_NAME, "").toString(); | ||
} | ||
|
||
protected String setSubject(Map<String, Object> emailData, Locale locale) { | ||
return messageSource.getMessage("email.family-confirmation.subject", new Object[]{emailData.get("confirmationCode")}, | ||
locale); | ||
} | ||
|
||
protected String setBodyCopy(Map<String, Object> emailData, Locale locale) { | ||
String p1 = messageSource.getMessage("email.provider-confirmation.p1", null, locale); | ||
String p2 = messageSource.getMessage("email.provider-confirmation.p2", new Object[]{emailData.get("ccrrName")}, | ||
locale); | ||
String p3 = messageSource.getMessage("email.provider-confirmation.p3", | ||
new Object[]{formatListIntoReadableString((List<String>) emailData.get("childrenInitialsList"), messageSource.getMessage("general.and", null, locale)), emailData.get("ccapStartDate")}, locale); | ||
String p4 = messageSource.getMessage("email.provider-confirmation.p4", | ||
new Object[]{emailData.get("confirmationCode")}, locale); | ||
String p5 = messageSource.getMessage("email.provider-confirmation.p5", | ||
new Object[]{emailData.get("ccrrName"), emailData.get("ccrrPhoneNumber")}, | ||
locale); | ||
String p6 = messageSource.getMessage("email.general.footer.automated-response", null, locale); | ||
String p7 = messageSource.getMessage("email.general.footer.cfa", null, locale); | ||
return p1 + p2 + p3 + p4 + p5 + p6 + p7; | ||
} | ||
|
||
protected void sendEmail(ILGCCEmail email, Submission submission) { | ||
sendEmailJob.enqueueSendEmailJob(email); | ||
updateEmailStatus(submission); | ||
} | ||
|
||
private void updateEmailStatus(Submission submission) { | ||
submission.getInputData().putIfAbsent(EMAIL_SENT_STATUS_INPUT_NAME, "true"); | ||
submissionRepositoryService.save(submission); | ||
} | ||
|
||
private Optional<Submission> getFamilyApplication(Submission providerSubmission) { | ||
Optional<UUID> familySubmissionId = ProviderSubmissionUtilities.getClientId(providerSubmission); | ||
if (familySubmissionId.isEmpty()) { | ||
log.warn("No family submission is associated with the provider submission with ID: {}", | ||
providerSubmission.getId()); | ||
return Optional.empty(); | ||
} | ||
|
||
return submissionRepositoryService.findById(familySubmissionId.get()); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.