use of services.applicant.RepeatedEntity in project civiform by seattle-uat.
the class ApplicantQuestionTest method questionTextAndHelpText_areContextualizedByRepeatedEntity.
@Test
public void questionTextAndHelpText_areContextualizedByRepeatedEntity() {
ApplicantData applicantData = new ApplicantData();
Path householdMembersPath = ApplicantData.APPLICANT_PATH.join(testQuestionBank.applicantHouseholdMembers().getQuestionDefinition().getQuestionPathSegment());
QuestionAnswerer.answerEnumeratorQuestion(applicantData, householdMembersPath, ImmutableList.of("Jonathan"));
Path householdMembersJobsPath = householdMembersPath.atIndex(0).join(testQuestionBank.applicantHouseholdMemberJobs().getQuestionDefinition().getQuestionPathSegment());
QuestionAnswerer.answerEnumeratorQuestion(applicantData, householdMembersJobsPath, ImmutableList.of("JonCo"));
RepeatedEntity jonathan = RepeatedEntity.createRepeatedEntities((EnumeratorQuestionDefinition) testQuestionBank.applicantHouseholdMembers().getQuestionDefinition(), applicantData).get(0);
RepeatedEntity jonCo = jonathan.createNestedRepeatedEntities((EnumeratorQuestionDefinition) testQuestionBank.applicantHouseholdMemberJobs().getQuestionDefinition(), applicantData).get(0);
ApplicantQuestion applicantQuestion = new ApplicantQuestion(testQuestionBank.applicantHouseholdMemberDaysWorked().getQuestionDefinition(), applicantData, Optional.of(jonCo));
assertThat(applicantQuestion.getQuestionText()).isEqualTo("How many days has Jonathan worked at JonCo?");
assertThat(applicantQuestion.getQuestionHelpText()).isEqualTo("How many days has Jonathan worked at JonCo?");
}
use of services.applicant.RepeatedEntity in project civiform by seattle-uat.
the class JsonPathPredicateGeneratorTest method fromLeafNode_predicateBasedOnSiblingRepeatedQuestion_generatesCorrectPath.
@Test
public void fromLeafNode_predicateBasedOnSiblingRepeatedQuestion_generatesCorrectPath() throws Exception {
ApplicantData applicantData = new ApplicantData();
EnumeratorQuestionDefinition enumerator = (EnumeratorQuestionDefinition) questionBank.applicantHouseholdMembers().getQuestionDefinition();
QuestionDefinition siblingQuestion = new QuestionDefinitionBuilder(questionBank.applicantHouseholdMemberName().getQuestionDefinition()).setEnumeratorId(Optional.of(enumerator.getId())).build();
// Put an entity at the enumerator path so we can generate repeated contexts.
ApplicantQuestion applicantEnumerator = new ApplicantQuestion(enumerator, applicantData, Optional.empty());
applicantData.putRepeatedEntities(applicantEnumerator.getContextualizedPath(), ImmutableList.of("Bernard", "Alice"));
// Just use a repeated entity for the first (index 0) entity.
ImmutableList<RepeatedEntity> repeatedEntities = RepeatedEntity.createRepeatedEntities(enumerator, applicantData);
Optional<RepeatedEntity> repeatedEntity = repeatedEntities.stream().findFirst();
generator = new JsonPathPredicateGenerator(ImmutableList.of(enumerator, siblingQuestion), repeatedEntity);
LeafOperationExpressionNode node = LeafOperationExpressionNode.create(// The predicate is based on the sibling "name" question.
siblingQuestion.getId(), Scalar.FIRST_NAME, Operator.EQUAL_TO, PredicateValue.of("Bernard"));
assertThat(generator.fromLeafNode(node)).isEqualTo(JsonPathPredicate.create("$.applicant.applicant_household_members[0].household_members_name" + "[?(@.first_name == \"Bernard\")]"));
}
use of services.applicant.RepeatedEntity in project civiform by seattle-uat.
the class ApplicantProgramSummaryView method render.
/**
* Renders a summary of all of the applicant's data for a specific application. Data includes:
*
* <p>Program Id, Applicant Id - Needed for link context (submit & edit)
*
* <p>Question Data for each question:
*
* <ul>
* <li>question text
* <li>answer text
* <li>block id (for edit link)
* </ul>
*/
public Content render(Params params) {
Messages messages = params.messages();
String pageTitle = params.inReview() ? messages.at(MessageKey.TITLE_PROGRAM_REVIEW.getKeyName()) : messages.at(MessageKey.TITLE_PROGRAM_PREVIEW.getKeyName());
HtmlBundle bundle = layout.getBundle().setTitle(String.format("%s — %s", pageTitle, params.programTitle()));
ContainerTag applicationSummary = div().withId("application-summary").withClasses(Styles.MB_8);
Optional<RepeatedEntity> previousRepeatedEntity = Optional.empty();
boolean isFirstUnanswered = true;
for (AnswerData answerData : params.summaryData()) {
Optional<RepeatedEntity> currentRepeatedEntity = answerData.repeatedEntity();
if (!currentRepeatedEntity.equals(previousRepeatedEntity) && currentRepeatedEntity.isPresent()) {
applicationSummary.with(renderRepeatedEntitySection(currentRepeatedEntity.get(), messages));
}
applicationSummary.with(renderQuestionSummary(answerData, messages, params.applicantId(), params.inReview(), isFirstUnanswered));
isFirstUnanswered = isFirstUnanswered && answerData.isAnswered();
previousRepeatedEntity = currentRepeatedEntity;
}
// Add submit action (POST).
String submitLink = routes.ApplicantProgramReviewController.submit(params.applicantId(), params.programId()).url();
Tag continueOrSubmitButton;
if (params.completedBlockCount() == params.totalBlockCount()) {
continueOrSubmitButton = submitButton(messages.at(MessageKey.BUTTON_SUBMIT.getKeyName())).withClasses(ReferenceClasses.SUBMIT_BUTTON, ApplicantStyles.BUTTON_SUBMIT_APPLICATION);
} else {
String applyUrl = routes.ApplicantProgramsController.edit(params.applicantId(), params.programId()).url();
continueOrSubmitButton = a().attr(HREF, applyUrl).withText(messages.at(MessageKey.BUTTON_CONTINUE.getKeyName())).withId("continue-application-button").withClasses(ReferenceClasses.CONTINUE_BUTTON, ApplicantStyles.BUTTON_SUBMIT_APPLICATION);
}
ContainerTag content = div().with(applicationSummary).with(form().withAction(submitLink).withMethod(Http.HttpVerbs.POST).with(makeCsrfTokenInputTag(params.request())).with(continueOrSubmitButton));
if (!params.banner().isEmpty()) {
bundle.addToastMessages(ToastMessage.error(params.banner()));
}
bundle.addMainContent(layout.renderProgramApplicationTitleAndProgressIndicator(params.programTitle(), params.completedBlockCount(), params.totalBlockCount(), true), h1(pageTitle).withClasses(ApplicantStyles.H1_PROGRAM_APPLICATION), content);
bundle.addMainStyles(ApplicantStyles.MAIN_PROGRAM_APPLICATION);
return layout.renderWithNav(params.request(), params.applicantName(), params.messages(), bundle);
}
use of services.applicant.RepeatedEntity in project civiform by seattle-uat.
the class JsonPathPredicateGeneratorTest method fromLeafNode_twoLevelsDeepRepeater_generatesCorrectPath.
@Test
public void fromLeafNode_twoLevelsDeepRepeater_generatesCorrectPath() throws Exception {
ApplicantData applicantData = new ApplicantData();
// household members
// \_ name (target), jobs
// \_ days worked (current block)
QuestionDefinition topLevelEnumerator = questionBank.applicantHouseholdMembers().getQuestionDefinition();
QuestionDefinition targetQuestion = questionBank.applicantHouseholdMemberName().getQuestionDefinition();
QuestionDefinition nestedEnumerator = questionBank.applicantHouseholdMemberJobs().getQuestionDefinition();
QuestionDefinition currentQuestion = questionBank.applicantHouseholdMemberDaysWorked().getQuestionDefinition();
// Put an entity at the enumerator path so we can generate repeated contexts.
ApplicantQuestion applicantEnumerator = new ApplicantQuestion(topLevelEnumerator, applicantData, Optional.empty());
applicantData.putRepeatedEntities(applicantEnumerator.getContextualizedPath(), ImmutableList.of("Bernard", "Alice"));
// Context for index 1 ('Alice')
Optional<RepeatedEntity> topLevelRepeatedEntity = RepeatedEntity.createRepeatedEntities((EnumeratorQuestionDefinition) topLevelEnumerator, applicantData).reverse().stream().findFirst();
// Create entities for the nested enumerator
ApplicantQuestion nestedApplicantEnumerator = new ApplicantQuestion(nestedEnumerator, applicantData, topLevelRepeatedEntity);
applicantData.putRepeatedEntities(nestedApplicantEnumerator.getContextualizedPath(), ImmutableList.of("Software Engineer"));
Optional<RepeatedEntity> currentContext = topLevelRepeatedEntity.get().createNestedRepeatedEntities((EnumeratorQuestionDefinition) nestedEnumerator, applicantData).stream().findFirst();
generator = new JsonPathPredicateGenerator(ImmutableList.of(topLevelEnumerator, nestedEnumerator, targetQuestion, currentQuestion), currentContext);
LeafOperationExpressionNode node = LeafOperationExpressionNode.create(// The predicate is based on the "name" question.
targetQuestion.getId(), Scalar.FIRST_NAME, Operator.EQUAL_TO, PredicateValue.of("Alice"));
assertThat(generator.fromLeafNode(node)).isEqualTo(JsonPathPredicate.create("$.applicant.applicant_household_members[1].household_members_name" + "[?(@.first_name == \"Alice\")]"));
}
use of services.applicant.RepeatedEntity in project civiform by seattle-uat.
the class JsonPathPredicateGeneratorTest method fromLeafNode_targetQuestionNotAncestorOfCurrentContext_throwsException.
@Test
public void fromLeafNode_targetQuestionNotAncestorOfCurrentContext_throwsException() throws Exception {
ApplicantData applicantData = new ApplicantData();
QuestionDefinition topLevelEnumerator = questionBank.applicantHouseholdMembers().getQuestionDefinition();
QuestionDefinition targetQuestion = new QuestionDefinitionBuilder(questionBank.applicantHouseholdMemberName().getQuestionDefinition()).setEnumeratorId(Optional.of(12345L)).build();
QuestionDefinition currentQuestion = questionBank.applicantHouseholdMemberJobs().getQuestionDefinition();
// Put an entity at the enumerator path so we can generate repeated contexts.
ApplicantQuestion applicantEnumerator = new ApplicantQuestion(topLevelEnumerator, applicantData, Optional.empty());
applicantData.putRepeatedEntities(applicantEnumerator.getContextualizedPath(), ImmutableList.of("Alice"));
// Context for 'Alice'
Optional<RepeatedEntity> currentContext = RepeatedEntity.createRepeatedEntities((EnumeratorQuestionDefinition) topLevelEnumerator, applicantData).reverse().stream().findFirst();
generator = new JsonPathPredicateGenerator(ImmutableList.of(targetQuestion, currentQuestion), currentContext);
LeafOperationExpressionNode node = LeafOperationExpressionNode.create(// The predicate is based on the "name" question.
targetQuestion.getId(), Scalar.FIRST_NAME, Operator.EQUAL_TO, PredicateValue.of("Alice"));
assertThatThrownBy(() -> generator.fromLeafNode(node)).isInstanceOf(InvalidPredicateException.class).hasMessageContaining("Enumerator 12345 is not an ancestor of the current repeated context");
}
Aggregations