Search in sources :

Example 1 with QuestionEntity

use of org.mifos.platform.questionnaire.domain.QuestionEntity in project head by mifos.

the class QuestionnaireMapperImpl method mapToQuestion.

@Override
public QuestionEntity mapToQuestion(QuestionDto questionDto) {
    QuestionEntity questionEntity = new QuestionEntity();
    questionEntity.setQuestionText(questionDto.getText());
    questionEntity.setNickname(questionDto.getNickname());
    questionEntity.setAnswerType(mapToAnswerType(questionDto.getType()));
    questionEntity.setNumericMin(questionDto.getMinValue());
    questionEntity.setNumericMax(questionDto.getMaxValue());
    questionEntity.setQuestionState(questionDto.isActive() ? questionDto.isEditable() ? QuestionState.ACTIVE : QuestionState.ACTIVE_NOT_EDITABLE : questionDto.isEditable() ? QuestionState.INACTIVE : QuestionState.INACTIVE_NOT_EDITABLE);
    questionEntity.setChoices(mapToChoices(questionDto.getChoices()));
    return questionEntity;
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity)

Example 2 with QuestionEntity

use of org.mifos.platform.questionnaire.domain.QuestionEntity in project head by mifos.

the class QuestionnaireMapperImpl method mapToSectionDetail.

private SectionDetail mapToSectionDetail(Section section) {
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setId(section.getId());
    sectionDetail.setName(section.getName());
    if (section.getSequenceNumber() != null) {
        sectionDetail.setSequenceNumber(section.getSequenceNumber());
    }
    for (SectionQuestion sectionQuestion : section.getQuestions()) {
        QuestionEntity question = sectionQuestion.getQuestion();
        QuestionType type = mapToQuestionType(question.getAnswerTypeAsEnum());
        boolean required = sectionQuestion.isRequired();
        QuestionDetail questionDetail = mapToQuestionDetail(question, type);
        sectionDetail.addQuestion(mapToSectionQuestionDetail(sectionQuestion, required, sectionQuestion.isShowOnPage(), questionDetail));
    }
    return sectionDetail;
}
Also used : SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionType(org.mifos.platform.questionnaire.service.QuestionType) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 3 with QuestionEntity

use of org.mifos.platform.questionnaire.domain.QuestionEntity in project head by mifos.

the class QuestionnaireMapperTest method shouldMapQuestionDetailToQuestion.

@Test
public void shouldMapQuestionDetailToQuestion() {
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.FREETEXT);
    questionDefinition.setActive(false);
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), CoreMatchers.is(AnswerType.FREETEXT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getQuestionStateAsEnum(), is(QuestionState.INACTIVE));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 4 with QuestionEntity

use of org.mifos.platform.questionnaire.domain.QuestionEntity in project head by mifos.

the class QuestionnaireMapperTest method getQuestionEntity.

private QuestionEntity getQuestionEntity(int questionId, String questionText) {
    QuestionEntity questionEntity = new QuestionEntity();
    questionEntity.setQuestionId(questionId);
    questionEntity.setQuestionText(questionText);
    questionEntity.setAnswerType(AnswerType.FREETEXT);
    questionEntity.setQuestionState(QuestionState.ACTIVE);
    return questionEntity;
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity)

Example 5 with QuestionEntity

use of org.mifos.platform.questionnaire.domain.QuestionEntity in project head by mifos.

the class QuestionnaireMapperTest method getSection.

private Section getSection(String sectionName, int questionId) {
    Section section = new Section(sectionName);
    SectionQuestion sectionQuestion = new SectionQuestion();
    QuestionEntity question = new QuestionEntity();
    question.setQuestionId(questionId);
    question.setQuestionText(sectionName);
    question.setAnswerType(AnswerType.DATE);
    question.setChoices(new LinkedList<QuestionChoiceEntity>());
    sectionQuestion.setQuestion(question);
    section.setQuestions(asList(sectionQuestion));
    return section;
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) Section(org.mifos.platform.questionnaire.domain.Section)

Aggregations

QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)25 Test (org.junit.Test)16 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)9 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)7 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)7 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)5 Section (org.mifos.platform.questionnaire.domain.Section)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)3 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)3 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)2 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)1 QuestionType (org.mifos.platform.questionnaire.service.QuestionType)1