Search in sources :

Example 51 with SectionDetail

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

the class SectionQuestionDaoIntegrationTest method getSection.

private SectionDetail getSection(String name) throws SystemException {
    SectionDetail section = new SectionDetail();
    section.setName(name);
    section.addQuestion(new SectionQuestionDetail(defineQuestion("Question1" + name + currentTimeMillis(), QuestionType.NUMERIC), true));
    section.addQuestion(new SectionQuestionDetail(defineQuestion("Question2" + name + currentTimeMillis(), QuestionType.DATE), true));
    section.addQuestion(new SectionQuestionDetail(defineQuestion("Question3" + name + currentTimeMillis(), QuestionType.FREETEXT), false));
    return section;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 52 with SectionDetail

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

the class QuestionGroupForm method initSections.

private List<SectionDetailForm> initSections() {
    List<SectionDetailForm> sectionDetailForms = new ArrayList<SectionDetailForm>();
    if (questionGroupDetail != null) {
        for (SectionDetail sectionDetail : questionGroupDetail.getSectionDetails()) {
            SectionDetailForm sectionDetailForm = new SectionDetailForm(sectionDetail);
            sectionDetailForm.setInitialCountOfQuestions(sectionDetail.getCountOfQuestions());
            sectionDetailForms.add(sectionDetailForm);
        }
    }
    this.initialCountOfSections = sectionDetailForms.size();
    return sectionDetailForms;
}
Also used : ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 53 with SectionDetail

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

the class QuestionGroupForm method addCurrentSectionToSections.

private void addCurrentSectionToSections() {
    for (SectionDetailForm section : sections) {
        if (StringUtils.equalsIgnoreCase(section.getName(), currentSection.getName())) {
            currentSection = section;
            return;
        }
    }
    List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
    for (SectionDetailForm sectionDetailForm : sections) {
        SectionDetail sectionDetail = sectionDetailForm.getSectionDetail();
        sectionDetail.setSequenceNumber(sectionDetail.getSequenceNumber() + 1);
        sectionDetails.add(sectionDetail);
    }
    currentSection.getSectionDetail().setSequenceNumber(0);
    sectionDetails.add(0, currentSection.getSectionDetail());
    sections.add(0, currentSection);
    questionGroupDetail.setSectionDetails(sectionDetails);
    sectionsToAdd.add(currentSection.getName());
}
Also used : ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 54 with SectionDetail

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

the class QuestionGroupForm method moveSectionDown.

public void moveSectionDown(String sectionName) {
    for (SectionDetailForm sectionForm : sections) {
        SectionDetail section = sectionForm.getSectionDetail();
        if (StringUtils.equalsIgnoreCase(sectionName, section.getName())) {
            int actualSeqNumber = section.getSequenceNumber();
            if (actualSeqNumber < sections.size() - 1) {
                SectionDetailForm sectionToSwap = sections.remove(actualSeqNumber + 1);
                section.setSequenceNumber(sectionToSwap.getSectionDetail().getSequenceNumber());
                sectionToSwap.getSectionDetail().setSequenceNumber(actualSeqNumber);
                sections.add(actualSeqNumber + 1, sectionForm);
                sections.set(actualSeqNumber, sectionToSwap);
                List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
                for (SectionDetailForm sectionDetailForm : sections) {
                    sectionDetails.add(sectionDetailForm.getSectionDetail());
                }
                questionGroupDetail.setSectionDetails(sectionDetails);
            }
            break;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 55 with SectionDetail

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

the class QuestionGroupForm method moveSectionUp.

public void moveSectionUp(String sectionName) {
    for (SectionDetailForm sectionForm : sections) {
        SectionDetail section = sectionForm.getSectionDetail();
        if (StringUtils.equalsIgnoreCase(sectionName, section.getName())) {
            int actualSeqNumber = section.getSequenceNumber();
            if (actualSeqNumber > 0) {
                SectionDetailForm sectionToSwap = sections.remove(actualSeqNumber - 1);
                section.setSequenceNumber(sectionToSwap.getSectionDetail().getSequenceNumber());
                sectionToSwap.getSectionDetail().setSequenceNumber(actualSeqNumber);
                sections.add(actualSeqNumber - 1, sectionForm);
                sections.set(actualSeqNumber, sectionToSwap);
                List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
                for (SectionDetailForm sectionDetailForm : sections) {
                    sectionDetails.add(sectionDetailForm.getSectionDetail());
                }
                questionGroupDetail.setSectionDetails(sectionDetails);
            }
            break;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

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