Skip to content

Commit

Permalink
Remove incomplete iterations from subflows (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
spokenbird authored Oct 17, 2024
1 parent 0e04bfb commit ad34c3c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.ilgcc.app.submission.actions;

import static java.util.Collections.emptyList;

import formflow.library.config.submission.Action;
import formflow.library.data.Submission;
import formflow.library.data.SubmissionRepositoryService;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoveIncompleteChildIterations implements Action {

private final SubmissionRepositoryService submissionRepositoryService;

public RemoveIncompleteChildIterations(SubmissionRepositoryService submissionRepositoryService) {
this.submissionRepositoryService = submissionRepositoryService;
}

@Override
public void run(Submission submission) {
var subflowData = (List<Map<String, Object>>) submission.getInputData().getOrDefault("children", emptyList());
if (!subflowData.isEmpty()) {
log.info("Removing incomplete child iterations from submission {}", submission.getId());
subflowData.removeIf(childIteration -> !(boolean) childIteration.getOrDefault("iterationIsComplete", false));
submissionRepositoryService.save(submission);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.ilgcc.app.submission.actions;

import static java.util.Collections.emptyList;

import formflow.library.config.submission.Action;
import formflow.library.data.Submission;
import formflow.library.data.SubmissionRepositoryService;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoveIncompleteJobIterations implements Action {

private final SubmissionRepositoryService submissionRepositoryService;

public RemoveIncompleteJobIterations(SubmissionRepositoryService submissionRepositoryService) {
this.submissionRepositoryService = submissionRepositoryService;
}

@Override
public void run(Submission submission) {
var subflowData = (List<Map<String, Object>>) submission.getInputData().getOrDefault("jobs", emptyList());
if (!subflowData.isEmpty()) {
log.info("Removing incomplete job iterations from submission {}", submission.getId());
subflowData.removeIf(job -> !(boolean) job.getOrDefault("iterationIsComplete", false));
submissionRepositoryService.save(submission);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.ilgcc.app.submission.actions;

import static java.util.Collections.emptyList;

import formflow.library.config.submission.Action;
import formflow.library.data.Submission;
import formflow.library.data.SubmissionRepositoryService;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoveIncompletePartnerJobIterations implements Action {

private final SubmissionRepositoryService submissionRepositoryService;

public RemoveIncompletePartnerJobIterations(SubmissionRepositoryService submissionRepositoryService) {
this.submissionRepositoryService = submissionRepositoryService;
}

@Override
public void run(Submission submission) {
var subflowData = (List<Map<String, Object>>) submission.getInputData().getOrDefault("partnerJobs", emptyList());
if (!subflowData.isEmpty()) {
log.info("Removing incomplete partner job iterations from submission {}", submission.getId());
subflowData.removeIf(partnerJob -> !(boolean) partnerJob.getOrDefault("iterationIsComplete", false));
submissionRepositoryService.save(submission);
}
}
}

5 changes: 3 additions & 2 deletions src/main/resources/flows-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ flow:
nextScreens:
- name: children-add
children-add:
beforeDisplayAction: RemoveIncompleteChildIterations
nextScreens:
- name: activities-parent-intro
children-info-basic:
Expand Down Expand Up @@ -162,7 +163,7 @@ flow:
condition: PartnerInSchool
- name: unearned-income-intro
activities-add-jobs:
subflow: jobs
beforeDisplayAction: RemoveIncompleteJobIterations
nextScreens:
- name: activities-add-ed-program
condition: LearningIsOneReasonForChildcareNeed
Expand Down Expand Up @@ -250,7 +251,7 @@ flow:
condition: PartnerInSchool
- name: unearned-income-intro
activities-partner-add-job:
subflow: partnerJobs
beforeDisplayAction: RemoveIncompletePartnerJobIterations
nextScreens:
- name: activities-partner-add-ed-program
condition: PartnerInSchool
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/ilgcc/app/journeys/GccFlowJourneyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,23 @@ void fullGccFlow() throws IOException {
testPage.clickYes();
//children-add (with children listed)
assertThat(testPage.getTitle()).isEqualTo(getEnMessage("children-add.title"));
// Add an incomplete iteration and assert that it is removed
testPage.clickButton(getEnMessage("children-add.add-button"));
testPage.enter("childFirstName", "ShouldBe");
testPage.enter("childLastName", "Removed");
testPage.enter("childDateOfBirthMonth", "1");
testPage.enter("childDateOfBirthDay", "1");
testPage.enter("childDateOfBirthYear", "2022");
testPage.selectFromDropdown("childRelationship", getEnMessage("children-ccap-info.relationship-option.child"));
testPage.selectRadio("needFinancialAssistanceForChild", "Yes");
testPage.clickContinue();
assertThat(testPage.getTitle()).isEqualTo(getEnMessage("children-ccap-info.title"));
// Go back to the children-add page and assert that the incomplete iteration is removed
testPage.goBack();
testPage.goBack();
assertThat(testPage.getTitle()).isEqualTo(getEnMessage("children-add.title"));
List<String> li = testPage.getTextBySelector(".child-name");
assertThat(li).doesNotContain("ShouldBe Removed");
assertThat(li).containsExactly("mugully glopklin", "child mcchild");
testPage.clickButton(getEnMessage("children-add.thats-all"));

Expand Down

0 comments on commit ad34c3c

Please sign in to comment.