-
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.
Show correct address in review screen and PDF
Co-authored-by: Ana Medrano <amedrano@codeforamerica.org>
- Loading branch information
Showing
6 changed files
with
102 additions
and
37 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
src/main/java/org/mdbenefits/app/preparers/HomeAddressPreparer.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,53 @@ | ||
package org.mdbenefits.app.preparers; | ||
|
||
import formflow.library.data.Submission; | ||
import formflow.library.pdf.PdfMap; | ||
import formflow.library.pdf.SingleField; | ||
import formflow.library.pdf.SubmissionField; | ||
import formflow.library.pdf.SubmissionFieldPreparer; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.mdbenefits.app.data.enums.CitizenshipStatus; | ||
import org.mdbenefits.app.data.enums.EthnicityType; | ||
import org.mdbenefits.app.data.enums.RaceType; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class HomeAddressPreparer implements SubmissionFieldPreparer { | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> results = new HashMap<>(); | ||
|
||
Map<String, Object> inputData = submission.getInputData(); | ||
|
||
boolean useSuggestedAddress = Boolean.parseBoolean( | ||
inputData.getOrDefault("useSuggestedAddress", "false").toString()); | ||
|
||
boolean homeAddressSameAsMailingAddress = Boolean.parseBoolean( | ||
inputData.getOrDefault("sameAsHomeAddress", "false").toString()); | ||
|
||
List<String> homeAddressParts = List.of("homeAddressStreetAddress1", "homeAddressStreetAddress2", | ||
"homeAddressCity", "homeAddressState", "homeAddressZipCode"); | ||
|
||
List<String> mailingAddressParts = List.of("mailingAddressStreetAddress1", "mailingAddressStreetAddress2", | ||
"mailingAddressCity", "mailingAddressState", "mailingAddressZipCode"); | ||
// We only ever validate the mailing address so we need to replace the home address with the validated | ||
// mailing address if they are the same | ||
if (useSuggestedAddress && homeAddressSameAsMailingAddress) { | ||
for (int i = 0; i < mailingAddressParts.size(); i++) { | ||
String mailingAddressPart = mailingAddressParts.get(i); | ||
if (inputData.containsKey(mailingAddressPart + "_validated")) { | ||
results.put(homeAddressParts.get(i), | ||
new SingleField(homeAddressParts.get(i), inputData.get(mailingAddressPart + "_validated").toString(), null)); | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
} |
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