Search in sources :

Example 16 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion 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 17 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion 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 18 with SectionQuestion

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

the class QuestionnaireMapperTest method assertQuestionGroupEntity.

private void assertQuestionGroupEntity(QuestionGroup questionGroup) {
    assertThat(questionGroup, is(notNullValue()));
    assertThat(questionGroup.getTitle(), is("QG1"));
    Set<EventSourceEntity> eventSources = questionGroup.getEventSources();
    assertThat(eventSources, is(notNullValue()));
    assertThat(eventSources.size(), is(1));
    EventSourceEntity eventSourceEntity = eventSources.toArray(new EventSourceEntity[eventSources.size()])[0];
    assertThat(eventSourceEntity.getEvent().getName(), is("Create"));
    assertThat(eventSourceEntity.getSource().getEntityType(), is("Client"));
    assertThat(questionGroup.getState(), is(QuestionGroupState.ACTIVE));
    List<Section> sections = questionGroup.getSections();
    assertThat(sections, is(notNullValue()));
    assertThat(sections.size(), is(1));
    Section section = sections.get(0);
    assertThat(section.getName(), is("Sec1"));
    List<SectionQuestion> questions = section.getQuestions();
    assertThat(questions, is(notNullValue()));
    assertThat(questions.size(), is(2));
    SectionQuestion sectionQuestion1 = questions.get(0);
    assertThat(sectionQuestion1.getSequenceNumber(), is(1));
    assertThat(sectionQuestion1.getSection(), is(notNullValue()));
    assertThat(sectionQuestion1.getSection().getName(), is("Sec1"));
    assertThat(sectionQuestion1.getSection().getSequenceNumber(), is(1));
    assertThat(sectionQuestion1.getQuestion(), is(notNullValue()));
    assertThat(sectionQuestion1.getQuestion().getQuestionText(), is("Ques1"));
    assertThat(sectionQuestion1.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.FREETEXT));
    SectionQuestion sectionQuestion2 = questions.get(1);
    assertThat(sectionQuestion2.getSequenceNumber(), is(2));
    assertThat(sectionQuestion2.getSection(), is(notNullValue()));
    assertThat(sectionQuestion2.getSection().getName(), is("Sec1"));
    assertThat(sectionQuestion2.getSection().getSequenceNumber(), is(1));
    assertThat(sectionQuestion2.getQuestion(), is(notNullValue()));
    assertThat(sectionQuestion2.getQuestion().getQuestionText(), is("Ques2"));
    assertThat(sectionQuestion2.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.SINGLESELECT));
    assertThat(sectionQuestion2.getQuestion().getChoices(), is(notNullValue()));
    assertThat(sectionQuestion2.getQuestion().getChoices().size(), is(3));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceText(), is("Ch1"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceOrder(), is(1));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceText(), is("Ch2"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceOrder(), is(2));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceText(), is("Ch3"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceOrder(), is(3));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) Section(org.mifos.platform.questionnaire.domain.Section)

Example 19 with SectionQuestion

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstances.

@Test
public void shouldMapToQuestionGroupInstances() {
    QuestionGroup questionGroup1 = new QuestionGroup();
    questionGroup1.setId(10);
    when(questionGroupDao.getDetails(10)).thenReturn(questionGroup1);
    QuestionGroup questionGroup2 = new QuestionGroup();
    questionGroup2.setId(11);
    when(questionGroupDao.getDetails(11)).thenReturn(questionGroup2);
    SectionQuestion sectionQuestion1 = new SectionQuestion();
    sectionQuestion1.setId(14);
    when(sectionQuestionDao.getDetails(14)).thenReturn(sectionQuestion1);
    SectionQuestion sectionQuestion2 = new SectionQuestion();
    sectionQuestion2.setId(15);
    when(sectionQuestionDao.getDetails(15)).thenReturn(sectionQuestion2);
    QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
    questionGroupInstance.setVersionNum(3);
    when(questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 10)).thenReturn(asList(questionGroupInstance));
    when(questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 11)).thenReturn(asList(questionGroupInstance));
    List<QuestionDetail> questionDetails1 = asList(new QuestionDetail(12, "Question 1", QuestionType.FREETEXT, true, true));
    List<SectionDetail> sectionDetails1 = asList(getSectionDetailWithQuestions(14, "Sec1", questionDetails1, "value", null));
    QuestionGroupDetail questionGroupDetail1 = new QuestionGroupDetail(10, "QG1", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails1, true);
    List<QuestionDetail> questionDetails2 = asList(new QuestionDetail(13, "Question 2", QuestionType.DATE, true, true));
    List<SectionDetail> sectionDetails2 = asList(getSectionDetailWithQuestions(15, "Sec2", questionDetails2, null, null));
    QuestionGroupDetail questionGroupDetail2 = new QuestionGroupDetail(11, "QG2", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails2, true);
    QuestionDetail questionDetail1 = new QuestionDetail(13, "Question 3", QuestionType.MULTI_SELECT, true, true);
    questionDetail1.setAnswerChoices(asList(getChoiceDto("a1"), getChoiceDto("a2"), getChoiceDto("a3")));
    List<QuestionDetail> questionDetails3 = asList(questionDetail1);
    List<SectionDetail> sectionDetails3 = asList(getSectionDetailWithQuestions(15, "Sec2", questionDetails3, null, asList("a2", "a3")));
    QuestionGroupDetail questionGroupDetail3 = new QuestionGroupDetail(11, "QG2", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails3, true);
    QuestionDetail questionDetail2 = new QuestionDetail(13, "Question 4", QuestionType.SMART_SELECT, true, true);
    questionDetail2.setAnswerChoices(asList(getChoiceDto("a1", "Tag1", "Tag2"), getChoiceDto("a2", "Tag11", "Tag22"), getChoiceDto("a3", "Tag111", "Tag222")));
    questionDetails3 = asList(questionDetail2);
    sectionDetails3 = asList(getSectionDetailWithQuestions(15, "Sec2", questionDetails3, asList(getSelectionDetail("a1", "Tag2"), getSelectionDetail("a3", "Tag111"))));
    QuestionGroupDetail questionGroupDetail4 = new QuestionGroupDetail(11, "QG2", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails3, true);
    List<QuestionGroupInstance> questionGroupInstances = questionnaireMapper.mapToQuestionGroupInstances(new QuestionGroupDetails(101, 201, 1, asList(questionGroupDetail1, questionGroupDetail2, questionGroupDetail3, questionGroupDetail4)));
    assertThat(questionGroupInstances, is(notNullValue()));
    assertThat(questionGroupInstances.size(), is(4));
    QuestionGroupInstance questionGroupInstance1 = questionGroupInstances.get(0);
    assertThat(questionGroupInstance1.getQuestionGroup().getId(), is(10));
    assertThat(questionGroupInstance1.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance1.getCreatorId(), is(101));
    assertThat(questionGroupInstance1.getDateConducted(), is(notNullValue()));
    assertThat(questionGroupInstance1.getEntityId(), is(201));
    assertThat(questionGroupInstance1.getVersionNum(), is(4));
    List<QuestionGroupResponse> questionGroupResponses1 = questionGroupInstance1.getQuestionGroupResponses();
    assertThat(questionGroupResponses1, is(notNullValue()));
    assertThat(questionGroupResponses1.size(), is(1));
    QuestionGroupResponse questionGroupResponse = questionGroupResponses1.get(0);
    assertThat(questionGroupResponse.getResponse(), is("value"));
    assertThat(questionGroupResponse.getSectionQuestion().getId(), is(14));
    QuestionGroupInstance questionGroupInstance2 = questionGroupInstances.get(1);
    assertThat(questionGroupInstance2.getQuestionGroup().getId(), is(11));
    assertThat(questionGroupInstance2.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance2.getCreatorId(), is(101));
    assertThat(questionGroupInstance2.getDateConducted(), is(notNullValue()));
    assertThat(questionGroupInstance2.getEntityId(), is(201));
    assertThat(questionGroupInstance2.getVersionNum(), is(4));
    List<QuestionGroupResponse> questionGroupResponses2 = questionGroupInstance2.getQuestionGroupResponses();
    assertThat(questionGroupResponses2, is(notNullValue()));
    assertThat(questionGroupResponses2.size(), is(0));
    QuestionGroupInstance questionGroupInstance3 = questionGroupInstances.get(2);
    assertThat(questionGroupInstance3.getQuestionGroup().getId(), is(11));
    assertThat(questionGroupInstance3.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance3.getCreatorId(), is(101));
    assertThat(questionGroupInstance3.getDateConducted(), is(notNullValue()));
    assertThat(questionGroupInstance3.getEntityId(), is(201));
    assertThat(questionGroupInstance3.getVersionNum(), is(4));
    List<QuestionGroupResponse> questionGroupResponses3 = questionGroupInstance3.getQuestionGroupResponses();
    assertThat(questionGroupInstance3, is(notNullValue()));
    assertThat(questionGroupResponses3.size(), is(2));
    assertThat(questionGroupResponses3.get(0).getResponse(), is("a2"));
    assertThat(questionGroupResponses3.get(1).getResponse(), is("a3"));
    QuestionGroupInstance questionGroupInstance4 = questionGroupInstances.get(3);
    List<QuestionGroupResponse> questionGroupResponses4 = questionGroupInstance4.getQuestionGroupResponses();
    assertThat(questionGroupInstance4, is(notNullValue()));
    assertThat(questionGroupResponses4.size(), is(2));
    assertThat(questionGroupResponses4.get(0).getResponse(), is("a1"));
    assertThat(questionGroupResponses4.get(0).getTag(), is("Tag2"));
    assertThat(questionGroupResponses4.get(1).getResponse(), is("a3"));
    assertThat(questionGroupResponses4.get(1).getTag(), is("Tag111"));
    verify(questionGroupInstanceDao, times(1)).retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 10);
    verify(questionGroupInstanceDao, times(3)).retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 11);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroupDetails(org.mifos.platform.questionnaire.service.QuestionGroupDetails) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) Test(org.junit.Test)

Example 20 with SectionQuestion

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupToExistingQuestionGroupWhileAddingQuestionToOldSection.

@Test
public void shouldMapQuestionGroupToExistingQuestionGroupWhileAddingQuestionToOldSection() {
    Integer questionGroupId = 123;
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName("Misc");
    SectionQuestionDetail sectionQuestionDetail1 = getSectionQuestionDetail(111, 999, "Ques1");
    SectionQuestionDetail sectionQuestionDetail2 = getSectionQuestionDetail(0, 0, "Ques2");
    sectionDetail.setQuestionDetails(asList(sectionQuestionDetail1, sectionQuestionDetail2));
    List<SectionDetail> sectionDetails = asList(sectionDetail);
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(questionGroupId, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true, true);
    SectionQuestion sectionQuestion = getSectionQuestion(getQuestionEntity(999, "Ques1"), 333);
    Section section = getSection(sectionQuestion, 222, "Misc");
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("Misc", 123)).thenReturn(asList(section));
    when(questionGroupDao.getDetails(questionGroupId)).thenReturn(getQuestionGroup(questionGroupId, "QG Title", section));
    when(sectionQuestionDao.retrieveFromQuestionIdSectionId(222, 999)).thenReturn(asList(sectionQuestion));
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroupForExistingQuestion(questionGroup, QuestionGroupState.ACTIVE);
    verify(questionGroupDao).retrieveSectionByNameAndQuestionGroupId("Misc", 123);
    verify(questionGroupDao).getDetails(questionGroupId);
    verify(sectionQuestionDao).retrieveFromQuestionIdSectionId(222, 999);
    verify(eventSourceDao).retrieveByEventAndSource(anyString(), anyString());
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Aggregations

SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)20 Section (org.mifos.platform.questionnaire.domain.Section)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)4 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)4 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)3 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Transactional (org.springframework.transaction.annotation.Transactional)2 LinkedList (java.util.LinkedList)1 SectionLink (org.mifos.platform.questionnaire.domain.SectionLink)1 SectionQuestionLink (org.mifos.platform.questionnaire.domain.SectionQuestionLink)1 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)1