use of org.mifos.platform.questionnaire.domain.QuestionGroupInstance in project head by mifos.
the class QuestionGroupInstanceDaoIntegrationTest method shouldGetLatestQuestionGroupInstancesBasedOnQuestionGroupAndEntity.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetLatestQuestionGroupInstancesBasedOnQuestionGroupAndEntity() {
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 instance1 = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
QuestionGroupInstance instance2 = getQuestionGroupInstance(2, questionGroup, 101, "Hello World1", "Hello World2");
questionGroupInstanceDao.saveOrUpdateAll(asList(instance1, instance2));
List<QuestionGroupInstance> instances = questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(101, questionGroupDetail.getId());
assertThat(instances, is(notNullValue()));
assertThat(instances.size(), is(1));
QuestionGroupInstance qGInst = instances.get(0);
assertThat(qGInst.getVersionNum(), is(2));
assertThat(qGInst.getEntityId(), is(101));
assertThat(qGInst.getQuestionGroup().getId(), is(questionGroupDetail.getId()));
List<QuestionGroupResponse> qGResponses = qGInst.getQuestionGroupResponses();
assertThat(qGResponses, is(notNullValue()));
assertThat(qGResponses.size(), is(2));
assertThat(qGResponses.get(0).getResponse(), is("Hello World1"));
assertThat(qGResponses.get(1).getResponse(), is("Hello World2"));
}
use of org.mifos.platform.questionnaire.domain.QuestionGroupInstance in project head by mifos.
the class QuestionGroupInstanceDaoIntegrationTest method getQuestionGroupInstance.
private QuestionGroupInstance getQuestionGroupInstance(int version, QuestionGroup questionGroup, int entityId, String... responses) {
QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
questionGroupInstance.setCompletedStatus(1);
questionGroupInstance.setQuestionGroup(questionGroup);
questionGroupInstance.setDateConducted(Calendar.getInstance().getTime());
questionGroupInstance.setCreatorId(122);
questionGroupInstance.setVersionNum(version);
questionGroupInstance.setEntityId(entityId);
List<QuestionGroupResponse> questionGroupResponses = new ArrayList<QuestionGroupResponse>();
for (int index = 0; index < responses.length; index++) {
SectionQuestion sectionQuestion = questionGroup.getSections().get(index).getQuestions().get(0);
questionGroupResponses.add(getQuestionGroupResponse(responses[index], questionGroupInstance, sectionQuestion));
}
questionGroupInstance.setQuestionGroupResponses(questionGroupResponses);
return questionGroupInstance;
}
use of org.mifos.platform.questionnaire.domain.QuestionGroupInstance in project head by mifos.
the class QuestionnaireMapperImpl method nextQuestionGroupInstanceVersion.
private int nextQuestionGroupInstanceVersion(int entityId, Integer questionGroupId) {
int nextVersion = 0;
List questionGroupInstances = questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(entityId, questionGroupId);
if (isNotEmpty(questionGroupInstances)) {
nextVersion = ((QuestionGroupInstance) questionGroupInstances.get(0)).getVersionNum() + 1;
}
return nextVersion;
}
use of org.mifos.platform.questionnaire.domain.QuestionGroupInstance 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"));
}
use of org.mifos.platform.questionnaire.domain.QuestionGroupInstance in project head by mifos.
the class QuestionnaireMapperTest method getQuestionGroupInstanceWithSingleMultiSelectQuestion.
private QuestionGroupInstance getQuestionGroupInstanceWithSingleMultiSelectQuestion(int entityId, int version, QuestionGroup questionGroup, String... responses) {
QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
questionGroupInstance.setQuestionGroup(questionGroup);
questionGroupInstance.setCompletedStatus(1);
questionGroupInstance.setCreatorId(122);
questionGroupInstance.setDateConducted(Calendar.getInstance().getTime());
questionGroupInstance.setEntityId(entityId);
questionGroupInstance.setVersionNum(version);
List<QuestionGroupResponse> groupResponses = new ArrayList<QuestionGroupResponse>();
for (String response : responses) {
groupResponses.add(getQuestionGroupResponse(response, questionGroupInstance, questionGroup.getSections().get(0).getQuestions().get(0)));
}
questionGroupInstance.setQuestionGroupResponses(groupResponses);
return questionGroupInstance;
}
Aggregations