@Override protected PageStructure createPageStructure( RandomizationStrategy randomizationStrategy, List<SectionBreadcrumb> breadcrumbs, Map<String, Object> answers) { PageStructure nextPage = super.createPageStructure(randomizationStrategy, breadcrumbs, answers); Breadcrumb active = breadcrumbs.get(0); SectionBreadcrumb sectionBreadcrumb = (SectionBreadcrumb) active; Builder builder = Section.with(); if (!randomizationStrategy.equals(RandomizationStrategy.QUESTIONS_RANDOMIZATION)) { builder.id(sectionBreadcrumb.getSection().getId()); } Section section = builder.build(); for (QuestionBreadcrumb questionBreadcrumb : sectionBreadcrumb.getBreadcrumbs()) { section.addQuestion( Question.with() .id(questionBreadcrumb.getQuestion().getId()) .number(questionBreadcrumb.getQuestionNumber()) .build()); } nextPage.addSection(section); return nextPage; }
@Override protected List<SectionBreadcrumb> makeBreadcrumbs( QuestionnaireDefinition questionnaireDefinition, Questionnaire questionnaire) { List<SectionBreadcrumb> breadcrumbs = new ArrayList<>(); SectionBreadcrumb breadcrumb = null; Integer questionnaireDefinitionId = questionnaireDefinition.getId(); RandomizationStrategy randomizationStrategy = questionnaireDefinition.getRandomizationStrategy(); if (RandomizationStrategy.SECTIONS_RANDOMIZATION.equals(randomizationStrategy)) { List<Section> sections = sectionService.findByExample( Section.with() .questionnaireDefinition( QuestionnaireDefinition.with().id(questionnaireDefinitionId).build()) .build(), new SearchParameters()); Collections.shuffle(sections); for (Section section : sections) { breadcrumb = SectionBreadcrumb.with() .questionnaire(questionnaire) .section(section) .last(Boolean.FALSE) .renderingMode(RenderingMode.SECTION_BY_SECTION) .build(); breadcrumbs.add(breadcrumb); } populateQuestionsBreadcrumbs(breadcrumbs, QUESTION_NUMBER_START_COUNTER); } else if (RandomizationStrategy.QUESTIONS_RANDOMIZATION.equals(randomizationStrategy)) { List<Question> questions = questionnaireDefinitionService.getQuestions(questionnaireDefinitionId); Collections.shuffle(questions); Integer questionPerPage = questionnaireDefinition.getQuestionsPerPage(); int questionIdx = 0; Integer questionNumberCounter = QUESTION_NUMBER_START_COUNTER; for (Question question : questions) { if (questionIdx % questionPerPage == 0) { breadcrumb = SectionBreadcrumb.with() .questionnaire(questionnaire) .last(Boolean.FALSE) .renderingMode(RenderingMode.SECTION_BY_SECTION) .build(); breadcrumbs.add(breadcrumb); } breadcrumb.addBreadcrumb( QuestionBreadcrumb.with() .question(question) .last(Boolean.FALSE) .questionNumber(questionNumberCounter++) .build()); questionIdx++; } } else { Section section = sectionService.findOneByPositionInQuestionnaireDefinition( questionnaireDefinitionId, INITIAL_POSITION); breadcrumb = SectionBreadcrumb.with() .questionnaire(questionnaire) .section(section) .renderingMode(RenderingMode.SECTION_BY_SECTION) .build(); breadcrumbs.add(breadcrumb); populateQuestionsBreadcrumbs(breadcrumbs, QUESTION_NUMBER_START_COUNTER); } breadcrumbs.get(0).setLast(Boolean.TRUE); return breadcrumbs; }