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;
}
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;
}
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);
}
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()));
}
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"));
}
Aggregations