generated from codeforamerica/form-flow-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ana Medrano Fernandez
authored and
Ana Medrano Fernandez
committed
Oct 11, 2023
1 parent
5c2cc2b
commit 5cb8b38
Showing
6 changed files
with
65 additions
and
6 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
62 changes: 62 additions & 0 deletions
62
...main/java/org/ladocuploader/app/submission/actions/ReformatsUserDataBeforeDisplaying.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,62 @@ | ||
package org.ladocuploader.app.submission.actions; | ||
|
||
import formflow.library.config.submission.Action; | ||
import formflow.library.data.Submission; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* | ||
*/ | ||
@Component | ||
@Slf4j | ||
public class ReformatsUserDataBeforeDisplaying implements Action { | ||
|
||
@Override | ||
public void run(Submission submission) { | ||
Map<String, Object> inputData = submission.getInputData(); | ||
|
||
submission.getInputData().put("affectedByPersonalSituations[]", reformatPersonalSituations(inputData)); | ||
} | ||
|
||
private ArrayList<LinkedHashMap> reformatPersonalSituations(Map<String, Object> inputData) { | ||
ArrayList<LinkedHashMap> householdMembers = (ArrayList) inputData.get("household"); | ||
ArrayList<String> hasPersonalSituations = (ArrayList) inputData.get("uuidsByPersonalSituations[]"); | ||
ArrayList<LinkedHashMap> personalSituationsObject = new ArrayList<>(); | ||
|
||
hasPersonalSituations.forEach((String id) -> { | ||
LinkedHashMap user = new LinkedHashMap(); | ||
if (id.equals("you")) { | ||
user.put("uuid", id); | ||
user.put("firstName", inputData.get("firstName") + " (you)"); | ||
user.put("lastName", inputData.get("lastName")); | ||
personalSituationsObject.add(user); | ||
} else { | ||
personalSituationsObject.add(householdData(householdMembers, id)); | ||
} | ||
} | ||
); | ||
|
||
return personalSituationsObject; | ||
|
||
} | ||
|
||
private LinkedHashMap householdData(ArrayList<LinkedHashMap> household, String uuid) { | ||
LinkedHashMap user = new LinkedHashMap(); | ||
for (LinkedHashMap hhmember : household) { | ||
if (hhmember.get("uuid").equals(uuid)) { | ||
user.put("uuid", uuid); | ||
user.put("firstName", hhmember.get("householdMemberFirstName")); | ||
user.put("lastName", hhmember.get("householdMemberLastName")); | ||
continue; | ||
} | ||
} | ||
|
||
return user; | ||
}; | ||
|
||
} |
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