Search in sources :

Example 26 with SectionQuestionDetail

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

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

the class QuestionGroupForm method moveQuestionDown.

public void moveQuestionDown(String sectionName, String questionId) {
    for (SectionDetailForm section : sections) {
        if (StringUtils.equalsIgnoreCase(sectionName, section.getName())) {
            List<SectionQuestionDetail> questions = section.getSectionQuestionDetails();
            for (SectionQuestionDetail question : questions) {
                if (Integer.parseInt(questionId) == question.getQuestionId()) {
                    int actualSeqNumber = question.getSequenceNumber();
                    if (actualSeqNumber < questions.size() - 1) {
                        SectionQuestionDetail questionToSwap = questions.get(actualSeqNumber + 1);
                        question.setSequenceNumber(questionToSwap.getSequenceNumber());
                        questionToSwap.setSequenceNumber(actualSeqNumber);
                        questions.set(actualSeqNumber, questionToSwap);
                        questions.set(actualSeqNumber + 1, question);
                    }
                    break;
                }
            }
            break;
        }
    }
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 28 with SectionQuestionDetail

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

the class QuestionGroupController method setQuestionLinkDetail.

public QuestionLinkDetail setQuestionLinkDetail(QuestionGroupForm questionGroupForm, String sourceQuestionId, String affectedQuestionId, String value, String additionalValue, String linkType, String linkTypeDisplay) {
    QuestionLinkDetail questionLinkDetail = new QuestionLinkDetail();
    SectionQuestionDetail sourceQuestion = findQuestionDetailById(questionGroupForm.getQuestionGroupDetail(), sourceQuestionId);
    questionLinkDetail.setSourceQuestion(sourceQuestion);
    SectionQuestionDetail affectedQuestion = findQuestionDetailById(questionGroupForm.getQuestionGroupDetail(), affectedQuestionId);
    questionLinkDetail.setAffectedQuestion(affectedQuestion);
    questionLinkDetail.setValue(value);
    questionLinkDetail.setLinkType(Integer.valueOf(linkType));
    questionLinkDetail.setLinkTypeDisplay(linkTypeDisplay);
    questionLinkDetail.setState(false);
    if (additionalValue != null)
        questionLinkDetail.setAdditionalValue(additionalValue);
    return questionLinkDetail;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail)

Example 29 with SectionQuestionDetail

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

the class QuestionnaireMapperImpl method mapToSectionQuestions.

private List<SectionQuestion> mapToSectionQuestions(List<SectionQuestionDetail> sectionQuestionDetails, Section section) {
    List<SectionQuestion> sectionQuestions = new ArrayList<SectionQuestion>();
    for (int i = 0, sectionQuestionDetailsSize = sectionQuestionDetails.size(); i < sectionQuestionDetailsSize; i++) {
        SectionQuestionDetail sectionQuestionDetail = sectionQuestionDetails.get(i);
        sectionQuestions.add(mapToSectionQuestion(sectionQuestionDetail, i, section));
    }
    return sectionQuestions;
}
Also used : SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList)

Example 30 with SectionQuestionDetail

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

the class ClientCustActionTest 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)

Aggregations

SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)44 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)25 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)21 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)7 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)6 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)3 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)2 QuestionLinkDetail (org.mifos.platform.questionnaire.service.QuestionLinkDetail)2 SectionLinkDetail (org.mifos.platform.questionnaire.service.SectionLinkDetail)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 HashSet (java.util.HashSet)1 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)1 AuditLog (org.mifos.framework.components.audit.business.AuditLog)1 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)1 ServiceException (org.mifos.framework.exceptions.ServiceException)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 QuestionGroupInstanceDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupInstanceDtoBuilder)1