Search in sources :

Example 21 with QuestionGroup

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

the class SectionQuestionDaoIntegrationTest method shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId() {
    String title = "QG1" + currentTimeMillis();
    SectionDetail sectionDetail1 = getSection("S1");
    SectionDetail sectionDetail2 = getSection("S2");
    List<SectionDetail> details = asList(sectionDetail1, sectionDetail2);
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    Integer questionId = questionGroup.getSections().get(1).getQuestions().get(1).getQuestion().getQuestionId();
    Integer sectionQuestionId = questionGroup.getSections().get(1).getQuestions().get(1).getId();
    List<Integer> sectionQuestionIds = sectionQuestionDao.retrieveIdFromQuestionGroupIdQuestionIdSectionName("S2", questionId, questionGroup.getId());
    assertThat(sectionQuestionIds, is(notNullValue()));
    assertThat(sectionQuestionIds.size(), is(1));
    assertThat(sectionQuestionIds.get(0), is(sectionQuestionId));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) 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 22 with QuestionGroup

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

the class QuestionnaireServiceIntegrationTest method shouldDefineQuestionGroup.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldDefineQuestionGroup() throws SystemException {
    String title = TITLE + currentTimeMillis();
    QuestionDetail questionDetail1 = defineQuestion(title + 1, QuestionType.NUMERIC, true);
    QuestionDetail questionDetail2 = defineQuestion(title + 2, QuestionType.FREETEXT, true);
    SectionDetail section1 = getSectionWithQuestionId("S1", questionDetail1);
    SectionDetail section2 = getSectionWithQuestionId("S2", questionDetail2);
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", asList(section1, section2), true);
    assertNotNull(questionGroupDetail);
    Integer questionGroupId = questionGroupDetail.getId();
    assertNotNull(questionGroupId);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupId);
    assertNotNull(questionGroup);
    Assert.assertEquals(title, questionGroup.getTitle());
    Assert.assertEquals(QuestionGroupState.ACTIVE, questionGroup.getState());
    Assert.assertEquals(true, questionGroup.isEditable());
    List<Section> sections = questionGroup.getSections();
    Assert.assertEquals(2, sections.size());
    Assert.assertEquals("S1", sections.get(0).getName());
    Assert.assertEquals(title + 1, sections.get(0).getQuestions().get(0).getQuestion().getQuestionText());
    Assert.assertEquals("S2", sections.get(1).getName());
    Assert.assertEquals(title + 2, sections.get(1).getQuestions().get(0).getQuestion().getQuestionText());
    verifyCreationDate(questionGroup);
    verifyEventSources(questionGroup);
}
Also used : QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) Section(org.mifos.platform.questionnaire.domain.Section) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with QuestionGroup

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

the class QuestionnaireServiceFacadeImpl method checkAccessToQuestionGroup.

private boolean checkAccessToQuestionGroup(Integer questionGroupId) {
    QuestionGroup questionGroup = this.questionnaireService.getQuestionGroupById(questionGroupId);
    boolean result = false;
    if (questionGroup != null) {
        Short activityID = questionGroup.getActivityId();
        try {
            result = this.rolesPermissionService.hasUserAccessForActivity(activityID);
        } catch (Exception ex) {
            result = false;
        }
    }
    return result;
}
Also used : QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) ParseException(java.text.ParseException)

Aggregations

QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)23 Test (org.junit.Test)15 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)13 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)11 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)6 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)3 Section (org.mifos.platform.questionnaire.domain.Section)3 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)3 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 SystemException (org.mifos.framework.exceptions.SystemException)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