QuestionGroupController extends QuestionnaireController { @SuppressWarnings({"ThrowableInstanceNeverThrown"}) public String defineQuestionGroup(QuestionGroupForm questionGroupForm, RequestContext requestContext, boolean createMode) { String result = "success"; if (!questionGroupHasErrors(questionGroupForm, requestContext)) { QuestionGroupDetail questionGroupDetail = null; try { if (createMode) { questionGroupForm.setActive(true); } if (questionGroupForm.isActive()) { questionGroupDetail = questionnaireServiceFacade.createActiveQuestionGroup(questionGroupForm.getQuestionGroupDetail()); } else { questionGroupDetail = questionnaireServiceFacade.createQuestionGroup(questionGroupForm.getQuestionGroupDetail()); } if (containsCreateLoanEventSource(questionGroupForm.getEventSources()) && questionGroupForm.getApplyToAllLoanProducts()) { questionnaireServiceFacade.applyToAllLoanProducts(questionGroupDetail.getId()); } List<QuestionLinkDetail> questionLinkDetails = setFilledQuestionDetailForQuestionLinks(questionGroupForm.getQuestionLinks(), questionGroupDetail); List<SectionLinkDetail> sectionLinkDetails = setFilledSectionDetailForQuestionLinks(questionGroupForm.getSectionLinks(), questionGroupDetail); questionnaireServiceFacade.createQuestionLinks(questionLinkDetails); questionnaireServiceFacade.createSectionLinks(sectionLinkDetails); } catch (AccessDeniedException e) { constructAndLogSystemError(requestContext.getMessageContext(), new SystemException(QuestionnaireConstants.MISSING_PERMISSION_TO_ACTIVATE_QG, e)); result = "failure"; } catch (SystemException e) { constructAndLogSystemError(requestContext.getMessageContext(), e); result = "failure"; } } else { result = "failure"; } return result; } @SuppressWarnings({"UnusedDeclaration"})  QuestionGroupController();  QuestionGroupController(QuestionnaireServiceFacade questionnaireServiceFacade); @RequestMapping("/viewQuestionGroups.ftl") String getAllQuestionGroups(ModelMap model, HttpServletRequest request); @RequestMapping("/viewQuestionGroupDetail.ftl") String getQuestionGroup(ModelMap model, HttpServletRequest httpServletRequest); @RequestMapping(value="/getHiddenVisibleQuestions.ftl", method=RequestMethod.POST) @ResponseBody Map<String, Map<Integer, Boolean>> getHiddenVisibleQuestions(
            @RequestParam Integer questionId, @RequestParam String response); @RequestMapping(value="/hideAttachedQuestions.ftl", method=RequestMethod.POST) @ResponseBody Map<String, List<String>> hideAttachedQuestions(
            @RequestParam String questionsId, @RequestParam String sectionsId); @SuppressWarnings({"ThrowableInstanceNeverThrown"}) String defineQuestionGroup(QuestionGroupForm questionGroupForm, RequestContext requestContext, boolean createMode); Map<String, String> getAllQgEventSources(); QuestionLinkDetail setQuestionLinkDetail(QuestionGroupForm questionGroupForm, String sourceQuestionId, 
            String affectedQuestionId, String value, String additionalValue, String linkType, String linkTypeDisplay); SectionLinkDetail setSectionLinkDetail(QuestionGroupForm questionGroupForm, String sourceQuestionId, 
            String affectedSectionName, String value, String additionalValue, String linkType, String linkTypeDisplay); SectionQuestionDetail findQuestionDetailById(QuestionGroupDetail questionGroupDetail, String questionId); SectionQuestionDetail findQuestionDetailByNickname(QuestionGroupDetail questionGroupDetail, String nickname); SectionDetail findSectionDetailByName(QuestionGroupDetail questionGroupDetail, String sectionName); List<QuestionLinkDetail> setFilledQuestionDetailForQuestionLinks(List<QuestionLinkDetail> questionLinkDetails, QuestionGroupDetail questionGroupDetail); List<SectionLinkDetail> setFilledSectionDetailForQuestionLinks(List<SectionLinkDetail> sectionLinkDetails, QuestionGroupDetail questionGroupDetail); String addLink(QuestionGroupForm questionGroupForm,
            String sourceQuestionId, String linkType, String appliesTo,
            String affectedQuestionId, String affectedSectionName,
            String value, String additionalValue, Map<String, String> linkTypes, RequestContext requestContext); String removeLink(QuestionGroupForm questionGroupForm,
            String sourceQuestionId, String affectedQuestionId, String affectedSectionName, String value, String additionalValue, RequestContext requestContext); String addSection(QuestionGroupForm questionGroupForm, RequestContext requestContext); String deleteSection(QuestionGroupForm questionGroupForm, String sectionName); String deleteQuestion(QuestionGroupForm questionGroupForm, String sectionName, String questionId); String moveQuestionUp(QuestionGroupForm questionGroupForm, String sectionName, String questionId); String moveQuestionDown(QuestionGroupForm questionGroupForm, String sectionName, String questionId); String moveSectionUp(QuestionGroupForm questionGroupForm, String sectionName); String moveSectionDown(QuestionGroupForm questionGroupForm, String sectionName); List<SectionQuestionDetail> getAllSectionQuestions(); List<SectionQuestionDetail> getAllSectionQuestions(QuestionGroupForm questionGroupForm); Map<String, String> getAllLinkTypes(); String saveQuestionnaire(QuestionGroupDetails questionGroupDetails, int questionGroupIndex, RequestContext requestContext); String addQuestion(QuestionGroupForm questionGroupForm, RequestContext requestContext); String addSmartChoiceTag(QuestionGroupForm questionGroupForm, RequestContext requestContext, int choiceIndex);  }
@Test public void testCreateQuestionGroupSuccess() throws Exception { QuestionGroupForm questionGroup = getQuestionGroupForm(" " + TITLE + " ", "Create.Client", "S1", "S2"); String result = questionGroupController.defineQuestionGroup(questionGroup, requestContext, true); assertThat(result, Is.is("success")); QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(TITLE, "Create", "Client", "S1", "S2"); questionGroupDetail.setActive(true); verify(questionnaireServiceFacade).createActiveQuestionGroup(argThat(new QuestionGroupDetailMatcher(questionGroupDetail))); }
@Test public void testEditQuestionGroupSuccess() throws Exception { QuestionGroupForm questionGroup = getQuestionGroupForm(" " + TITLE + " ", "Create.Client", "S1", "S2"); String result = questionGroupController.defineQuestionGroup(questionGroup, requestContext, false); assertThat(result, Is.is("success")); QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(TITLE, "Create", "Client", "S1", "S2"); questionGroupDetail.setActive(false); verify(questionnaireServiceFacade).createQuestionGroup(argThat(new QuestionGroupDetailMatcher(questionGroupDetail))); }
@Test public void testCreateQuestionGroupForFailureWhenQuestionGroupTitleNotProvided() throws Exception { QuestionGroupForm questionGroupForm = getQuestionGroupForm(null, "Create.Client", "Section"); when(requestContext.getMessageContext()).thenReturn(messageContext); String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true); assertThat(result, Is.is(notNullValue())); assertThat(result, Is.is("failure")); verify(requestContext).getMessageContext(); verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.questionGroup.title.empty"))); }
@SuppressWarnings({"ThrowableInstanceNeverThrown"}) @Test public void testCreateQuestionGroupFailureWhenSectionsNotPresent() throws Exception { when(requestContext.getMessageContext()).thenReturn(messageContext); QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client"); String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true); assertThat(result, Is.is("failure")); verify(requestContext).getMessageContext(); verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.section.atLeastOne"))); }
@Test public void testCreateQuestionGroupForFailureWhenQuestionGroupAppliesToNotProvided() throws Exception { QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, QuestionnaireConstants.DEFAULT_APPLIES_TO_OPTION, "Section"); when(requestContext.getMessageContext()).thenReturn(messageContext); String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true); assertThat(result, Is.is(notNullValue())); assertThat(result, Is.is("failure")); verify(requestContext).getMessageContext(); verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.appliesTo.mandatory"))); }
@SuppressWarnings({"ThrowableInstanceNeverThrown"}) @Test public void testCreateQuestionGroupFailure() throws Exception { QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "S1", "S2"); when(requestContext.getMessageContext()).thenReturn(messageContext); doThrow(new SystemException("questionnaire.error.duplicate.question.found.in.section")).when(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject()); String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true); assertThat(result, Is.is("failure")); verify(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject()); verify(requestContext).getMessageContext(); verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.duplicate.question.found.in.section"))); }