Search in sources :

Example 26 with SectionDetail

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

the class LoanAccountActionTest method getSectionDetail.

private SectionDetail getSectionDetail(String name, String title, List<String> answerChoices) {
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName(name);
    QuestionDetail questionDetail = new QuestionDetail(111, title, QuestionType.SINGLE_SELECT, true, true);
    List<ChoiceDto> choiceDtos = new ArrayList<ChoiceDto>();
    for (String answerChoice : answerChoices) {
        choiceDtos.add(new ChoiceDto(answerChoice));
    }
    questionDetail.setAnswerChoices(choiceDtos);
    sectionDetail.setQuestionDetails(asList(new SectionQuestionDetail(questionDetail, true)));
    return sectionDetail;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 27 with SectionDetail

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

the class QuestionnaireServiceImpl method removeInActiveSectionsAndQuestions.

private void removeInActiveSectionsAndQuestions(QuestionGroupDetail questionGroupDetail) {
    for (Iterator<SectionDetail> sectionDetailIterator = questionGroupDetail.getSectionDetails().iterator(); sectionDetailIterator.hasNext(); ) {
        SectionDetail sectionDetail = sectionDetailIterator.next();
        removeInActiveQuestions(sectionDetail);
        if (sectionDetail.hasNoActiveQuestions()) {
            sectionDetailIterator.remove();
        }
    }
}
Also used : SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 28 with SectionDetail

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

the class QuestionnaireMapperImpl method mapToQuestionGroupDetail.

@Override
public QuestionGroupDetail mapToQuestionGroupDetail(QuestionGroup questionGroup) {
    List<SectionDetail> sectionDetails = mapToSectionDetails(questionGroup.getSections());
    List<SectionLink> sectionLinks = new ArrayList<SectionLink>();
    List<SectionQuestionLink> sectionQuestionLinks = new ArrayList<SectionQuestionLink>();
    for (SectionDetail sectionDetail : sectionDetails) {
        for (SectionQuestionDetail sectionQuestionDetail : sectionDetail.getQuestionDetails()) {
            if (!sectionLinkDao.retrieveDependentSectionLinksFromQuestion(sectionQuestionDetail.getId()).isEmpty())
                sectionLinks.addAll(sectionLinkDao.retrieveDependentSectionLinksFromQuestion(sectionQuestionDetail.getId()));
            if (!sectionQuestionLinkDao.retrieveDependentSectionQuestionLinksFromQuestion(sectionQuestionDetail.getId()).isEmpty())
                sectionQuestionLinks.addAll(sectionQuestionLinkDao.retrieveDependentSectionQuestionLinksFromQuestion(sectionQuestionDetail.getId()));
        }
    }
    List<EventSourceDto> eventSourceDtos = mapToEventSource(questionGroup.getEventSources());
    return new QuestionGroupDetail(questionGroup.getId(), questionGroup.getTitle(), eventSourceDtos, sectionDetails, questionGroup.isEditable(), QuestionGroupState.ACTIVE.equals(questionGroup.getState()), questionGroup.isPpi(), mapToQuestionLinkDetails(sectionQuestionLinks), mapToSectionLinkDetails(sectionLinks));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestionLink(org.mifos.platform.questionnaire.domain.SectionQuestionLink) SectionLink(org.mifos.platform.questionnaire.domain.SectionLink) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 29 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail 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 30 with SectionDetail

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

the class QuestionnaireFlowAdapterTest method getQuestionGroups.

private List<QuestionGroupDetail> getQuestionGroups() {
    List<QuestionDetail> questions = Arrays.asList(new QuestionDetail(12, "Question1", QuestionType.FREETEXT, true, true));
    List<SectionDetail> section = Arrays.asList(getSectionDetailWithQuestions("Section1", questions, null, true));
    QuestionGroupDetail questionGroup = getQuestionGroupDetail("Group1", "Create", "Loan", section);
    return Arrays.asList(questionGroup);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Aggregations

SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)56 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)34 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)25 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)24 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)20 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)13 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)12 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)5 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 ValidationException (org.mifos.platform.validations.ValidationException)5 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 Section (org.mifos.platform.questionnaire.domain.Section)3 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)3 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)3 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)2 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2