Skip to content

Commit

Permalink
before save action cleans up data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana Medrano Fernandez authored and Ana Medrano Fernandez committed Oct 11, 2023
1 parent 5c2cc2b commit 5cb8b38
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class LaDigitalAssister extends FlowInputs {

// Sensitive Questions
private String householdHasPersonalSituations;
private String affectedByPersonalSituations;
private String uuidsByPersonalSituations;
private List<String> personalSituationsListed;
private String householdHasDomesticViolenceSituation;
private String householdHasCriminalJusticeSituation;
Expand Down
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;
};

}
1 change: 1 addition & 0 deletions src/main/resources/flows-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ flow:
condition: HouseholdHasPersonalSituations
- name: householdVictimOfDomesticViolence
householdPersonalSituationsWho:
beforeSaveAction: ReformatsUserDataBeforeDisplaying
nextScreens:
- name: householdWhichPersonalSituations
householdWhichPersonalSituations:
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,12 @@ personal-situations-who.title=Personal Situations Who
personal-situations-who.header=Who has a personal situation that makes it hard to work?

personal-situations-which.title=Which Personal Situations
personal-situations-which.header=Personal Situations
personal-situations-which.subheader=Which personal situations apply to {0}?
personal-situations.which.option1=Being homeless
personal-situations.which.option2=Struggling with drugs or alcohol
personal-situations.which.option3=Experiencing domestic abuses
personal-situations.which.option4=A physical, mental, or other personal issue or disability
personal-situations.which.option5=Other reason
personal-situations.other.helptext=In a few words, describe your other reason(s).

domestic-violence.title=Domestic Violence Victim
domestic-violence.header=Does anyone in your household need to get away from an abusive situation?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<th:block th:ref="formContents">
<div class="form-card__content">
<th:block th:replace="~{'fragments/inputs/householdCheckboxFieldset' ::
householdCheckboxFieldset(inputName='affectedByPersonalSituations')}"/>
householdCheckboxFieldset(inputName='uuidsByPersonalSituations')}"/>
</div>
<div class="form-card__footer">
<th:block th:replace="~{fragments/inputs/submitButton :: submitButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<div th:replace="~{fragments/goBack :: goBackLink}"></div>
<main id="content" role="main" class="form-card spacing-above-35">
<th:block th:replace="~{fragments/icons :: briefcase}"></th:block>
<th:block
th:replace="~{fragments/cardHeader :: cardHeader(header=#{personal-situations-which.header})}"/>
<th:block
th:replace="~{fragments/form :: form(action=${formAction}, content=~{::whichHouseholdSituations})}">
<th:block th:ref="whichHouseholdSituations">
Expand Down

0 comments on commit 5cb8b38

Please sign in to comment.