Search in sources :

Example 1 with QuestionLinkDetail

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

the class QuestionnaireServiceImpl method createQuestionLinks.

public void createQuestionLinks(List<QuestionLinkDetail> questionLinks) {
    for (QuestionLinkDetail questionLinkDetail : questionLinks) {
        QuestionGroupLink questionGroupLink = questionnaireMapper.mapToQuestionGroupLink(questionLinkDetail, null);
        questionGroupLinkDao.saveOrUpdate(questionGroupLink);
        SectionQuestionLink sectionQuestionLink = questionnaireMapper.mapToQuestionLink(questionLinkDetail, questionGroupLink);
        sectionQuestionLinkDao.saveOrUpdate(sectionQuestionLink);
    }
}
Also used : QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail)

Example 2 with QuestionLinkDetail

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

the class QuestionnaireMapperImpl method mapToQuestionLinkDetails.

public List<QuestionLinkDetail> mapToQuestionLinkDetails(List<SectionQuestionLink> sectionQuestionLinks) {
    List<QuestionLinkDetail> questionLinkDetails = new ArrayList<QuestionLinkDetail>();
    for (SectionQuestionLink sectionQuestionLink : sectionQuestionLinks) {
        QuestionLinkDetail questionLinkDetail = new QuestionLinkDetail();
        questionLinkDetail.setValue(sectionQuestionLink.getQuestionGroupLink().getValue());
        questionLinkDetail.setAdditionalValue(sectionQuestionLink.getQuestionGroupLink().getAdditionalValue());
        questionLinkDetail.setLinkType(sectionQuestionLink.getQuestionGroupLink().getConditionTypeId());
        questionLinkDetail.setProperLinkTypeDisplay(sectionQuestionLink.getQuestionGroupLink().getConditionType());
        questionLinkDetail.setLinkId(sectionQuestionLink.getId());
        questionLinkDetail.setQuestionGroupLinkId(sectionQuestionLink.getQuestionGroupLink().getId());
        questionLinkDetail.setState(true);
        SectionQuestion sectionQuestion = sectionQuestionLink.getQuestionGroupLink().getSourceSectionQuestion();
        questionLinkDetail.setSourceQuestion(mapToSectionQuestionDetail(sectionQuestion, sectionQuestion.isRequired(), sectionQuestion.isShowOnPage(), (mapToQuestionDetail(sectionQuestion.getQuestion(), mapToQuestionType(sectionQuestion.getQuestion().getAnswerTypeAsEnum())))));
        sectionQuestion = sectionQuestionLink.getAffectedSectionQuestion();
        questionLinkDetail.setAffectedQuestion(mapToSectionQuestionDetail(sectionQuestion, sectionQuestion.isRequired(), sectionQuestion.isShowOnPage(), (mapToQuestionDetail(sectionQuestion.getQuestion(), mapToQuestionType(sectionQuestion.getQuestion().getAnswerTypeAsEnum())))));
        questionLinkDetails.add(questionLinkDetail);
    }
    return questionLinkDetails;
}
Also used : SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionQuestionLink(org.mifos.platform.questionnaire.domain.SectionQuestionLink) ArrayList(java.util.ArrayList) QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail)

Example 3 with QuestionLinkDetail

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

the class QuestionGroupController method setFilledQuestionDetailForQuestionLinks.

public List<QuestionLinkDetail> setFilledQuestionDetailForQuestionLinks(List<QuestionLinkDetail> questionLinkDetails, QuestionGroupDetail questionGroupDetail) {
    for (QuestionLinkDetail questionLinkDetail : questionLinkDetails) {
        questionLinkDetail.setSourceQuestion(findQuestionDetailByNickname(questionGroupDetail, String.valueOf(questionLinkDetail.getSourceQuestion().getQuestionDetail().getNickname())));
        questionLinkDetail.setAffectedQuestion(findQuestionDetailByNickname(questionGroupDetail, String.valueOf(questionLinkDetail.getAffectedQuestion().getQuestionDetail().getNickname())));
    }
    return questionLinkDetails;
}
Also used : QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail)

Example 4 with QuestionLinkDetail

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

the class QuestionGroupController method addLink.

public String addLink(QuestionGroupForm questionGroupForm, String sourceQuestionId, String linkType, String appliesTo, String affectedQuestionId, String affectedSectionName, String value, String additionalValue, Map<String, String> linkTypes, RequestContext requestContext) {
    String result = "success";
    if (!questionGroupLinkHasErrors(questionGroupForm, requestContext, sourceQuestionId, linkType, appliesTo, affectedQuestionId, affectedSectionName, value, additionalValue)) {
        if (appliesTo.equals("question")) {
            QuestionLinkDetail questionLink = setQuestionLinkDetail(questionGroupForm, sourceQuestionId, affectedQuestionId, value, additionalValue, linkType, linkTypes.get(linkType));
            questionGroupForm.getQuestionLinks().add(questionLink);
        } else {
            SectionLinkDetail sectionLink = setSectionLinkDetail(questionGroupForm, sourceQuestionId, affectedSectionName, value, additionalValue, linkType, linkTypes.get(linkType));
            questionGroupForm.getSectionLinks().add(sectionLink);
        }
    } else {
        result = "failure";
    }
    return result;
}
Also used : QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail) SectionLinkDetail(org.mifos.platform.questionnaire.service.SectionLinkDetail)

Example 5 with QuestionLinkDetail

use of org.mifos.platform.questionnaire.service.QuestionLinkDetail 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)

Aggregations

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