Skip to content

Commit

Permalink
Fixes formatting and SkipEmail logic
Browse files Browse the repository at this point in the history
  • Loading branch information
analoo committed Feb 19, 2025
1 parent ab8be73 commit 4bee67f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/ilgcc/app/email/SendGridEmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public Response sendEmail(String recipientAddress, String senderName, String sub
}

public Response sendEmail(ILGCCEmail ilgccEmail) throws IOException {
Mail mail = new Mail(ilgccEmail.getSenderEmail(), ilgccEmail.getSubject(), ilgccEmail.getRecipientEmail(), ilgccEmail.getBody());
Mail mail = new Mail(ilgccEmail.getSenderEmail(), ilgccEmail.getSubject(), ilgccEmail.getRecipientEmail(),
ilgccEmail.getBody());
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void run(Submission submission) {
"es") : Locale.ENGLISH;
Optional<Map<String, String>> emailData = getEmailData(submission);

if(emailData.isEmpty()){
if (emailData.isEmpty()) {
return;
}

Expand All @@ -56,24 +56,18 @@ public void run(Submission submission) {

protected Boolean skipEmailSend(Submission submission) {
boolean emailSent = submission.getInputData().getOrDefault(EMAIL_SENT_STATUS_INPUT_NAME, "false").equals("true");
if(emailSent){
return true;
} else {
boolean providerAgreedToCare = submission.getInputData().getOrDefault("providerResponseAgreeToCare", "false").equals("true");
if(providerAgreedToCare){
return true;
} else {
return false;
}
}
boolean providerAgreedToCare = submission.getInputData().getOrDefault("providerResponseAgreeToCare", "false")
.equals("true");

return emailSent || !providerAgreedToCare;
}

protected Optional<Map<String, String>> 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 familSubmissionID: {}",
log.warn("Could not send Email. No family submission is associated with the providerSubmissionId: {}",
providerSubmission.getId());
return Optional.empty();
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/org/ilgcc/app/utils/ProviderSubmissionUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@Component
@Slf4j
public class ProviderSubmissionUtilities {

private final static Map<String, Integer> DAY_OF_WEEK_WITH_BUSINESS_DAYS_OFFSET = Map.of(
"MONDAY", 3, "TUESDAY", 3, "WEDNESDAY", 5, "THURSDAY", 5, "FRIDAY", 5, "SATURDAY", 4, "SUNDAY", 3);

Expand Down Expand Up @@ -90,7 +91,6 @@ public static Map<String, String> getCombinedDataForEmails(Submission providerSu
Map<String, String> applicationData = new HashMap<>();

applicationData.put("providerName", getProviderResponseName(providerSubmission));

applicationData.put("ccrrName", (String) familySubmission.getInputData().getOrDefault("ccrrName", ""));
applicationData.put("ccrrPhoneNumber", (String) familySubmission.getInputData().getOrDefault("ccrrPhoneNumber", ""));
applicationData.put("childrenInitials", ProviderSubmissionUtilities.getChildrenInitialsFromApplication(familySubmission));
Expand Down Expand Up @@ -120,7 +120,7 @@ public static List<Map<String, String>> getChildrenDataForProviderResponse(Submi
}
return children;
}

public static String formatChildNamesAsCommaSeperatedList(Submission applicantSubmission) {
List<Map<String, Object>> children = SubmissionUtilities.getChildrenNeedingAssistance(applicantSubmission);
List<String> childNames = new ArrayList<>();
Expand Down Expand Up @@ -212,13 +212,15 @@ public static boolean providerApplicationHasExpired(Submission submission, Zoned
todaysDate) > 0;
}

public static String getCCAPStartDateFromProviderOrFamilyChildcareStartDate(Submission familySubmission, Submission providerSubmission) {
public static String getCCAPStartDateFromProviderOrFamilyChildcareStartDate(Submission familySubmission,
Submission providerSubmission) {
String providerCareStartDate = (String) providerSubmission.getInputData().getOrDefault("providerCareStartDate", "");

if (!providerCareStartDate.isBlank()) {
return DateUtilities.convertDateToFullWordMonthPattern(providerCareStartDate);
}else {
String familyEarliestChildcareStartDate = (String) familySubmission.getInputData().getOrDefault("earliestChildcareStartDate", "");
} else {
String familyEarliestChildcareStartDate = (String) familySubmission.getInputData()
.getOrDefault("earliestChildcareStartDate", "");
return DateUtilities.convertDateToFullWordMonthPattern(familyEarliestChildcareStartDate);
}
}
Expand Down Expand Up @@ -246,8 +248,10 @@ public static String getChildrenInitialsFromApplication(Submission familySubmiss
return String.join(", ", childrenInitials) + " and " + last; // Join remaining with commas, append 'and last'
}
}

public static String getProviderResponseName(Submission providerSubmission) {
String providerResponseBusinessName = (String) providerSubmission.getInputData().getOrDefault("providerResponseBusinessName", "");
String providerResponseBusinessName = (String) providerSubmission.getInputData()
.getOrDefault("providerResponseBusinessName", "");
if (!providerResponseBusinessName.isEmpty()) {
return providerResponseBusinessName;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ email.response-email-for-family.provider-agrees.p5=<p><strong>Next steps:</stron
email.provider-confirmation.p1=<p>Hello,</p>
email.provider-confirmation.p2=<p>Thank you for completing a family''s Child Care Assistance Program (CCAP) application. Your response has been submitted to {0} for processing.</p>
email.provider-confirmation.p3=<p><strong>Response:</strong> You agreed to care for {0} with a start date of {1} or pending approval.
email.provider-confirmation.p4=<p><strong>Confirmation code:</strong>{0}</p>
email.provider-confirmation.p4=<p><strong>Confirmation code:</strong> {0}</p>
email.provider-confirmation.p5=<p><strong>Next steps:You will receive a letter or email about the status of the family''s application within 13-15 business days. If you want an update on the application, call {0} at <a href="tel:{1}">{1}</a>.</p>

errors.provide-first-name=Enter a first name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void setUp() {
.withSubmittedAtDate(OffsetDateTime.now())
.withCCRR()
.withShortCode("ABC123")
.with("providerResponseAgreeToCare", "true")
.build();

submissionRepositoryService.save(familySubmission);
Expand All @@ -63,6 +62,7 @@ void setUp() {
.with("providerResponseLastName", "ProviderLast")
.with("providerResponseBusinessName", "BusinessName")
.with("providerCareStartDate", "01/10/2025")
.with("providerResponseAgreeToCare", "true")
.build();

submissionRepositoryService.save(providerSubmission);
Expand Down

0 comments on commit 4bee67f

Please sign in to comment.