Search in sources :

Example 6 with QuestionGroupInstance

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"));
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) 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)

Example 7 with QuestionGroupInstance

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;
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) ArrayList(java.util.ArrayList)

Example 8 with 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;
}
Also used : QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 9 with QuestionGroupInstance

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"));
}
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 10 with QuestionGroupInstance

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;
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

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