Search in sources :

Example 6 with SectionLinkDetail

use of org.mifos.platform.questionnaire.service.SectionLinkDetail in project head by mifos.

the class QuestionGroupForm method removeSection.

public void removeSection(String sectionName) {
    SectionDetail sectionToDelete = null;
    for (Iterator<SectionDetailForm> iterator = sections.iterator(); iterator.hasNext(); ) {
        SectionDetailForm section = iterator.next();
        if (StringUtils.equalsIgnoreCase(sectionName, section.getName())) {
            sectionToDelete = section.getSectionDetail();
            iterator.remove();
            break;
        }
    }
    if (sectionToDelete != null) {
        List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
        int sequence = 0;
        for (SectionDetailForm sectionDetailForm : sections) {
            SectionDetail sectionDetail = sectionDetailForm.getSectionDetail();
            sectionDetail.setSequenceNumber(sequence++);
            sectionDetails.add(sectionDetail);
        }
        markQuestionsOptionalAndReturnToPool(sectionToDelete);
        questionGroupDetail.setSectionDetails(sectionDetails);
        for (int i = 0; i < sectionsToAdd.size(); i++) {
            String name = sectionsToAdd.get(i);
            if (name.equals(sectionName)) {
                sectionsToAdd.remove(i);
                break;
            }
        }
        for (Iterator<SectionLinkDetail> iterator = sectionLinks.iterator(); iterator.hasNext(); ) {
            SectionLinkDetail sectionLinkDetail = iterator.next();
            if (sectionLinkDetail.getAffectedSection().getName().equals(sectionToDelete.getName()))
                iterator.remove();
            for (SectionQuestionDetail sectionQuestionDetail : sectionToDelete.getQuestionDetails()) {
                if (sectionLinkDetail.getSourceQuestion().getQuestionDetail().getId().equals(sectionQuestionDetail.getQuestionDetail().getId()))
                    iterator.remove();
            }
        }
        for (SectionQuestionDetail sectionQuestionDetail : sectionToDelete.getQuestionDetails()) {
            for (Iterator<QuestionLinkDetail> iterator = questionLinks.iterator(); iterator.hasNext(); ) {
                QuestionLinkDetail questionLinkDetail = iterator.next();
                if (questionLinkDetail.getSourceQuestion().getQuestionDetail().getId().equals(sectionQuestionDetail.getQuestionId()))
                    iterator.remove();
                if (questionLinkDetail.getAffectedQuestion().getQuestionDetail().getId().equals(sectionQuestionDetail.getQuestionId()))
                    iterator.remove();
            }
        }
    }
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) SectionLinkDetail(org.mifos.platform.questionnaire.service.SectionLinkDetail)

Example 7 with SectionLinkDetail

use of org.mifos.platform.questionnaire.service.SectionLinkDetail in project head by mifos.

the class QuestionGroupController method defineQuestionGroup.

@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;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail) SectionLinkDetail(org.mifos.platform.questionnaire.service.SectionLinkDetail)

Aggregations

SectionLinkDetail (org.mifos.platform.questionnaire.service.SectionLinkDetail)7 QuestionLinkDetail (org.mifos.platform.questionnaire.service.QuestionLinkDetail)3 ArrayList (java.util.ArrayList)2 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)2 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)2 SystemException (org.mifos.framework.exceptions.SystemException)1 SectionLink (org.mifos.platform.questionnaire.domain.SectionLink)1 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)1 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1