Search in sources :

Example 6 with QuestionGroupResponse

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

the class QuestionGroupInstanceDaoIntegrationTest method getQuestionGroupResponse.

private QuestionGroupResponse getQuestionGroupResponse(String responses, QuestionGroupInstance questionGroupInstance, SectionQuestion sectionQuestion) {
    QuestionGroupResponse response = new QuestionGroupResponse();
    response.setResponse(responses);
    response.setQuestionGroupInstance(questionGroupInstance);
    response.setSectionQuestion(sectionQuestion);
    return response;
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse)

Example 7 with QuestionGroupResponse

use of org.mifos.platform.questionnaire.domain.QuestionGroupResponse 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 8 with QuestionGroupResponse

use of org.mifos.platform.questionnaire.domain.QuestionGroupResponse 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 9 with QuestionGroupResponse

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

the class QuestionnaireMapperImpl method setMultiChoiceResponses.

private void setMultiChoiceResponses(List<QuestionGroupResponse> questionGroupResponses, SectionQuestionDetail sectionQuestionDetail) {
    List<SelectionDetail> answers = new ArrayList<SelectionDetail>();
    for (QuestionGroupResponse questionGroupResponse : questionGroupResponses) {
        if (questionGroupResponse.getSectionQuestion().getId() == sectionQuestionDetail.getId()) {
            answers.add(mapToSelectionDetail(questionGroupResponse));
        }
    }
    sectionQuestionDetail.setSelections(answers);
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SelectionDetail(org.mifos.platform.questionnaire.service.SelectionDetail) ArrayList(java.util.ArrayList)

Example 10 with QuestionGroupResponse

use of org.mifos.platform.questionnaire.domain.QuestionGroupResponse 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

QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)13 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)7 Test (org.junit.Test)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 ArrayList (java.util.ArrayList)3 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)3 Transactional (org.springframework.transaction.annotation.Transactional)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)2 QuestionGroupInstanceDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto)2 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)1 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)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