class 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"}) public  QuestionGroupController();
    public  QuestionGroupController(QuestionnaireServiceFacade questionnaireServiceFacade);

}