Search in sources :

Example 1 with QuestionGroupInstance

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

the class QuestionnaireMapperImpl method mapToQuestionGroupInstance.

@Override
public QuestionGroupInstance mapToQuestionGroupInstance(QuestionGroupInstanceDto questionGroupInstanceDto) {
    QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
    questionGroupInstance.setCompletedStatus(questionGroupInstanceDto.isCompleted());
    questionGroupInstance.setCreatorId(questionGroupInstanceDto.getCreatorId());
    questionGroupInstance.setEventSourceId(questionGroupInstanceDto.getEventSourceId());
    questionGroupInstance.setDateConducted(questionGroupInstanceDto.getDateConducted());
    questionGroupInstance.setEntityId(questionGroupInstanceDto.getEntityId());
    questionGroupInstance.setVersionNum(questionGroupInstanceDto.getVersion());
    questionGroupInstance.setQuestionGroup(questionGroupDao.getDetails(questionGroupInstanceDto.getQuestionGroupId()));
    questionGroupInstance.setQuestionGroupResponses(mapToQuestionGroupResponses(questionGroupInstance, questionGroupInstanceDto.getQuestionGroupResponseDtos()));
    return questionGroupInstance;
}
Also used : QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance)

Example 2 with QuestionGroupInstance

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

the class QuestionnaireMapperImpl method mapToQuestionGroupInstance.

private QuestionGroupInstance mapToQuestionGroupInstance(int creatorId, int entityId, int eventSourceId, QuestionGroupDetail questionGroupDetail) {
    QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
    questionGroupInstance.setDateConducted(getCurrentDateTime());
    questionGroupInstance.setCompletedStatus(1);
    Integer questionGroupId = questionGroupDetail.getId();
    questionGroupInstance.setVersionNum(nextQuestionGroupInstanceVersion(entityId, questionGroupId));
    questionGroupInstance.setCreatorId(creatorId);
    questionGroupInstance.setEventSourceId(eventSourceId);
    questionGroupInstance.setEntityId(entityId);
    questionGroupInstance.setQuestionGroup(questionGroupDao.getDetails(questionGroupId));
    questionGroupInstance.setQuestionGroupResponses(mapToQuestionGroupResponses(questionGroupDetail, questionGroupInstance));
    return questionGroupInstance;
}
Also used : QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance)

Example 3 with QuestionGroupInstance

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstance.

@Test
public void shouldMapToQuestionGroupInstance() {
    QuestionGroupInstanceDto questionGroupInstanceDto = getQuestionGroupInstanceDto();
    QuestionGroup questionGroup = new QuestionGroup();
    when(questionGroupDao.getDetails(123)).thenReturn(questionGroup);
    SectionQuestion sectionQuestion = new SectionQuestion();
    when(sectionQuestionDao.getDetails(999)).thenReturn(sectionQuestion);
    QuestionGroupInstance questionGroupInstance = questionnaireMapper.mapToQuestionGroupInstance(questionGroupInstanceDto);
    assertThat(questionGroupInstance, is(notNullValue()));
    assertThat(questionGroupInstance.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance.getCreatorId(), is(111));
    assertThat(questionGroupInstance.getEntityId(), is(12345));
    assertThat(questionGroupInstance.getVersionNum(), is(1));
    assertThat(questionGroupInstance.getQuestionGroup(), is(questionGroup));
    List<QuestionGroupResponse> questionGroupResponses = questionGroupInstance.getQuestionGroupResponses();
    assertThat(questionGroupResponses, is(notNullValue()));
    assertThat(questionGroupResponses.size(), is(1));
    QuestionGroupResponse questionGroupResponse = questionGroupResponses.get(0);
    assertThat(questionGroupResponse.getResponse(), is("Answer1"));
    assertThat(questionGroupResponse.getSectionQuestion(), is(sectionQuestion));
    verify(questionGroupDao).getDetails(123);
    verify(sectionQuestionDao).getDetails(999);
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroupInstanceDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) Test(org.junit.Test)

Example 4 with QuestionGroupInstance

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

the class QuestionGroupInstanceDaoIntegrationTest method shouldGetAllLatestQuestionGroupInstancesByEntityAndEventSourceId.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetAllLatestQuestionGroupInstancesByEntityAndEventSourceId() {
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroup questionGroup1 = questionGroupDao.getDetails(defineQuestionGroup("QG2" + currentTimeMillis(), "View", "Client", details, false).getId());
    QuestionGroup questionGroup2 = questionGroupDao.getDetails(defineQuestionGroup("QG1" + currentTimeMillis(), "View", "Client", details, false).getId());
    QuestionGroup questionGroup3 = questionGroupDao.getDetails(defineQuestionGroup("QG3" + currentTimeMillis(), "View", "Client", details, false).getId());
    List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(2010, 7, 24, questionGroup1, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup1, 101, 2), getQuestionGroupInstance(2010, 7, 24, questionGroup2, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup2, 101, 2), getQuestionGroupInstance(2010, 7, 26, questionGroup2, 101, 3), getQuestionGroupInstance(2010, 7, 24, questionGroup3, 101, 1), getQuestionGroupInstance(2010, 7, 26, questionGroup3, 101, 2));
    questionGroupInstanceDao.saveOrUpdateAll(questionGroupInstances);
    int eventSourceId = eventSourceDao.retrieveByEventAndSource("View", "Client").get(0).getId();
    //  questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId)
    //  is a hack to flush the entities as method under test is in SQL and not HQL
    questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
    List<QuestionGroupInstance> list = questionGroupInstanceDao.retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
    assertThat(list, is(notNullValue()));
    assertThat(list.size(), is(3));
    assertThat((list.get(0)).getId(), is(questionGroupInstances.get(4).getId()));
    assertThat((list.get(1)).getId(), is(questionGroupInstances.get(6).getId()));
    assertThat((list.get(2)).getId(), is(questionGroupInstances.get(1).getId()));
}
Also used : QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with QuestionGroupInstance

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

the class QuestionGroupInstanceDaoIntegrationTest method shouldPersistQuestionGroupInstance.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldPersistQuestionGroupInstance() throws SystemException {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    QuestionGroupInstance questionGroupInstance = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
    questionGroupInstanceDao.saveOrUpdateAll(asList(questionGroupInstance));
    QuestionGroupInstance groupInstance = questionGroupInstanceDao.getDetails(questionGroupInstance.getId());
    assertThat(groupInstance, is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().size(), is(2));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(questionGroup.getSections().get(0).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getResponse(), is("Foo Bar1"));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(questionGroup.getSections().get(1).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getResponse(), is("Foo Bar2"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)15 Test (org.junit.Test)9 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)7 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)7 Transactional (org.springframework.transaction.annotation.Transactional)6 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 ArrayList (java.util.ArrayList)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)3 QuestionGroupInstanceDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto)2 Calendar (java.util.Calendar)1 LinkedList (java.util.LinkedList)1 List (java.util.List)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 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)1 SelectionDetail (org.mifos.platform.questionnaire.service.SelectionDetail)1 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1