Search in sources :

Example 11 with QuestionGroup

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

the class QuestionnaireMapperImpl method mapToQuestionGroup.

@Override
public QuestionGroup mapToQuestionGroup(QuestionGroupDto questionGroupDto) {
    QuestionGroup questionGroup = new QuestionGroup();
    questionGroup.setEditable(questionGroupDto.isEditable());
    questionGroup.setDateOfCreation(getCurrentDateTime());
    questionGroup.setPpi(questionGroupDto.isPpi());
    questionGroup.setEventSources(mapEventSourceDtoToEntity(questionGroupDto.getEventSourceDtos()));
    questionGroup.setTitle(questionGroupDto.getTitle());
    questionGroup.setState(questionGroupDto.isActive() ? QuestionGroupState.ACTIVE : QuestionGroupState.INACTIVE);
    questionGroup.setSections(mapToSectionsFromDtos(questionGroupDto.getSections()));
    questionGroup.setActivityId(questionGroupDto.getActivityId());
    return questionGroup;
}
Also used : QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup)

Example 12 with QuestionGroup

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstanceDetails.

@Test
public void shouldMapToQuestionGroupInstanceDetails() {
    QuestionGroupInstance questionGroupInstance1 = getQuestionGroupInstance("QG1", 2010, 7, 25);
    QuestionGroupInstance questionGroupInstance2 = getQuestionGroupInstance("QG3", 2009, 2, 12);
    QuestionGroup questionGroup = getQuestionGroup(1991, "QG5", getSectionWithOneMultiSelectQuestion(222, "Section3", "Question3", "Choice1", "Choice2", "Choice3", "Choice4"));
    QuestionGroupInstance questionGroupInstance3 = getQuestionGroupInstanceWithSingleMultiSelectQuestion(101, 3, questionGroup, "Choice1", "Choice3", "Choice4");
    List<QuestionGroupInstance> questionGroupInstances = asList(questionGroupInstance1, questionGroupInstance2, questionGroupInstance3);
    List<QuestionGroupInstanceDetail> questionGroupInstanceDetails = questionnaireMapper.mapToQuestionGroupInstanceDetails(questionGroupInstances);
    assertThat(questionGroupInstanceDetails, is(notNullValue()));
    assertThat(questionGroupInstanceDetails.size(), is(3));
    assertQuestionGroupInstanceDetail(questionGroupInstanceDetails.get(0), "QG1", 2010, 7, 25);
    assertQuestionGroupInstanceDetail(questionGroupInstanceDetails.get(1), "QG3", 2009, 2, 12);
    QuestionGroupInstanceDetail detail = questionGroupInstanceDetails.get(2);
    assertThat(detail.getQuestionGroupTitle(), is("QG5"));
    List<SelectionDetail> values = detail.getQuestionGroupDetail().getSectionDetail(0).getQuestionDetail(0).getSelections();
    assertThat(values, is(notNullValue()));
    assertThat(values.size(), is(3));
    assertThat(values.get(0).getSelectedChoice(), is("Choice1"));
    assertThat(values.get(1).getSelectedChoice(), is("Choice3"));
    assertThat(values.get(2).getSelectedChoice(), is("Choice4"));
}
Also used : SelectionDetail(org.mifos.platform.questionnaire.service.SelectionDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Example 13 with QuestionGroup

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupDefinitionToExistingQuestionGroup.

@Test
public void shouldMapQuestionGroupDefinitionToExistingQuestionGroup() {
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    when(questionDao.getDetails(12)).thenReturn(new QuestionEntity());
    Section section = getSection("S1");
    when(questionGroupDao.getDetails(123)).thenReturn(getQuestionGroup(123, "QG Title", section));
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S1", 123)).thenReturn(asList(section));
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    List<SectionDetail> sectionDetails = asList(getSectionDefinition("S1", 12, TITLE), getSectionDefinition("S2", 0, TITLE));
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true);
    questionGroupDetail.setActive(false);
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroup(questionGroup, QuestionGroupState.INACTIVE);
    assertThat(questionGroup.isEditable(), is(true));
    verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
    verify(questionDao, times(1)).getDetails(12);
    verify(questionGroupDao, times(1)).getDetails(123);
    verify(questionGroupDao, times(1)).retrieveSectionByNameAndQuestionGroupId("S1", 123);
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) 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)

Example 14 with QuestionGroup

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

the class QuestionnaireMapperTest method getQuestionGroup.

private QuestionGroup getQuestionGroup(int id, String title, String event, String source, QuestionGroupState state, boolean editable, Section... sections) {
    QuestionGroup questionGroup = new QuestionGroup();
    questionGroup.setId(id);
    questionGroup.setTitle(title);
    questionGroup.setSections(asList(sections));
    questionGroup.setState(state);
    questionGroup.setEditable(editable);
    questionGroup.setEventSources(getEventSources(event, source));
    return questionGroup;
}
Also used : QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup)

Example 15 with QuestionGroup

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupToQuestionGroupDetail.

@Test
public void shouldMapQuestionGroupToQuestionGroupDetail() {
    QuestionGroup questionGroup = getQuestionGroup("Create", "Client", "S1", "S2");
    QuestionGroupDetail questionGroupDetail = questionnaireMapper.mapToQuestionGroupDetail(questionGroup);
    assertThat(questionGroupDetail, is(notNullValue()));
    assertThat(questionGroupDetail.getTitle(), is(TITLE));
    assertThat(questionGroupDetail.isEditable(), is(true));
    assertThat(questionGroupDetail.isActive(), is(true));
    List<SectionDetail> sectionDetails = questionGroupDetail.getSectionDetails();
    assertThat(sectionDetails, is(notNullValue()));
    assertThat(questionGroupDetail.getSectionDetails().size(), is(2));
    assertThat(questionGroupDetail.getSectionDetails().get(0).getName(), is("S1"));
    assertThat(questionGroupDetail.getSectionDetails().get(1).getName(), is("S2"));
    EventSourceDto eventSourceDto = questionGroupDetail.getEventSources().get(0);
    assertThat(eventSourceDto, is(notNullValue()));
    assertThat(eventSourceDto.getEvent(), is("Create"));
    assertThat(eventSourceDto.getSource(), is("Client"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Aggregations

QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)23 Test (org.junit.Test)15 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)13 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)11 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)6 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)3 Section (org.mifos.platform.questionnaire.domain.Section)3 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)3 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 SystemException (org.mifos.framework.exceptions.SystemException)1 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)1 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)1 QuestionGroupInstanceDetail (org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)1