generated from codeforamerica/form-flow-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snap expedited application #547
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/main/java/org/ladocuploader/app/preparers/ExpeditedSnapPreparer.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,83 @@ | ||
package org.ladocuploader.app.preparers; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
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.Map; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ExpeditedSnapPreparer implements SubmissionFieldPreparer { | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> results = new HashMap<>(); | ||
|
||
String isEligibleForExpeditedSnap = submission.getInputData().get("isEligibleForExpeditedSnap").toString(); | ||
if (isEligibleForExpeditedSnap.equals("true")) { | ||
String householdIncomeLast30Days=submission.getInputData().getOrDefault("householdIncomeLast30Days", "0").toString(); | ||
results.put("expeditedSnapIncome", new SingleField("expeditedSnapIncome", householdIncomeLast30Days, null)); | ||
|
||
String moneyOnHandString = submission.getInputData().getOrDefault("expeditedMoneyOnHandAmount", "0").toString(); | ||
results.put("expeditedSnapMoneyOnHand", new SingleField("expeditedSnapMoneyOnHand", moneyOnHandString, null)); | ||
|
||
String householdRentAmount = submission.getInputData().getOrDefault("householdRentAmount", "0").toString(); | ||
results.put("expeditedSnapHousingCost", new SingleField("expeditedSnapHousingCost", householdRentAmount, null)); | ||
|
||
var utilities = processUtilitiesExpenses(submission); | ||
boolean hasHouseholdExpenses = utilities.get("expenses"); | ||
boolean hasHeatingExpenses = utilities.get("acOrCooling"); | ||
|
||
results.put("expeditedSnapHouseholdExpensesBool", new SingleField("expeditedSnapHouseholdExpensesBool", hasHouseholdExpenses ? "Yes" : "No", null)); | ||
results.put("expeditedSnapHeatingBool", new SingleField("expeditedSnapHeatingBool", hasHeatingExpenses ? "Yes" : "No", null)); | ||
|
||
String householdPhoneExpenses = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_phone", "0").toString(); | ||
boolean hasPhoneExpenses = !householdPhoneExpenses.equals("0"); | ||
results.put("expeditedSnapPhoneExpensesBool", new SingleField("expeditedSnapPhoneExpensesBool", hasPhoneExpenses ? "Yes" : "No", null)); | ||
|
||
String isMigrantOrSeasonalFarmWorker = submission.getInputData().get("migrantOrSeasonalFarmWorkerInd").toString(); | ||
results.put("expeditedMigrantOrSeasonalWorkerBool", new SingleField("expeditedMigrantOrSeasonalWorkerBool", isMigrantOrSeasonalFarmWorker.equals("true") ? "Yes" : "No", null)); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
private int parseInt(String intAsString) { | ||
try { | ||
return Integer.parseInt(intAsString); | ||
} catch (NumberFormatException e) { | ||
return 0; | ||
} | ||
} | ||
|
||
private Map<String, Boolean> processUtilitiesExpenses(Submission submission) { | ||
Map<String, Boolean> results = new HashMap<>(); | ||
boolean expenses; | ||
boolean acOrCooling; | ||
|
||
String electricity = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_electricity", "0").toString(); | ||
String water = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_water", "0").toString(); | ||
String garbage = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_garbage", "0").toString(); | ||
String sewer = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_sewer", "0").toString(); | ||
String cookingFuel = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_cookingFuel", "0").toString(); | ||
String otherUtilitiesExpenses = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_otherUtilitiesExpenses", "0").toString(); | ||
|
||
expenses = (parseInt(electricity) + parseInt(water) + parseInt(garbage) + parseInt(sewer) + parseInt(cookingFuel) + parseInt(otherUtilitiesExpenses) > 0); | ||
|
||
var heating = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_heating", "0").toString(); | ||
var cooling = submission.getInputData().getOrDefault("householdUtilitiesExpenseAmount_wildcard_cooling", "0").toString(); | ||
|
||
acOrCooling = (parseInt(heating) + parseInt(cooling) > 0); | ||
|
||
results.put("expenses", expenses); | ||
results.put("acOrCooling", acOrCooling); | ||
|
||
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
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be slightly more readable to separate these into their own methods that return just the boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! Will work on this