Search in sources :

Example 6 with EventSourceDto

use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.

the class QuestionGroupForm method getEventSourceIds.

public List<String> getEventSourceIds() {
    List<String> eventSources = new ArrayList<String>();
    List<EventSourceDto> eventSourcesDtos = this.questionGroupDetail.getEventSources();
    if (eventSourcesDtos == null) {
        return eventSources;
    }
    for (EventSourceDto eventSourceDto : eventSourcesDtos) {
        if (eventSourceDto == null || isEmpty(eventSourceDto.getEvent()) || isEmpty(eventSourceDto.getSource())) {
            continue;
        }
        eventSources.add(format("%s.%s", eventSourceDto.getEvent(), eventSourceDto.getSource()));
    }
    return eventSources;
}
Also used : ArrayList(java.util.ArrayList) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 7 with EventSourceDto

use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.

the class QuestionGroupForm method setEventSourceIds.

public void setEventSourceIds(List<String> eventSourceIds) {
    List<EventSourceDto> eventSourceDtos = new ArrayList<EventSourceDto>();
    if (eventSourceIds != null) {
        for (String eventSourceId : eventSourceIds) {
            if (StringUtils.isNotEmpty(eventSourceId) && !StringUtils.equals(DEFAULT_APPLIES_TO_OPTION, eventSourceId)) {
                String[] parts = eventSourceId.split("\\.");
                eventSourceDtos.add(new EventSourceDto(parts[0], parts[1], eventSourceId));
            }
        }
    }
    this.questionGroupDetail.setEventSources(eventSourceDtos);
}
Also used : ArrayList(java.util.ArrayList) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 8 with EventSourceDto

use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.

the class QuestionGroupDefinitionParserTest method shouldParseQuestionDefinitionXml.

@Test
public void shouldParseQuestionDefinitionXml() throws Exception {
    QuestionGroupDefinitionParser questionGroupDefinitionParser = new QuestionGroupDefinitionParserImpl();
    String questionGroupDefXml = "/org/mifos/platform/questionnaire/QuestionGroupDefinition.xml";
    InputStream inputStream = getClass().getResourceAsStream(questionGroupDefXml);
    QuestionGroupDto questionGroupDto = questionGroupDefinitionParser.parse(inputStream);
    assertQuestionGroupDto(questionGroupDto);
    EventSourceDto eventSourceDto = questionGroupDto.getEventSourceDtos().get(0);
    assertEventSource(eventSourceDto);
    List<SectionDto> sectionDtos = questionGroupDto.getSections();
    assertSections(sectionDtos);
}
Also used : InputStream(java.io.InputStream) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 9 with EventSourceDto

use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.

the class QuestionnaireMapperIntegrationTest method testMapEventSource.

private void testMapEventSource(String event, String source, String description) {
    EventSourceDto eventSourceDto = new EventSourceDto(event, source, description);
    List<SectionDetail> sectionDetails = getSectionDefinitions();
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(new QuestionGroupDetail(0, "Title", Arrays.asList(eventSourceDto), sectionDetails, false));
    Set<EventSourceEntity> eventSources = questionGroup.getEventSources();
    assertThat(eventSources, is(not(nullValue())));
    assertThat(eventSources.size(), is(1));
    EventSourceEntity eventSourceEntity = eventSources.toArray(new EventSourceEntity[eventSources.size()])[0];
    assertThat(eventSourceEntity.getEvent().getName(), is(event));
    assertThat(eventSourceEntity.getSource().getEntityType(), is(source));
    assertThat(eventSourceEntity.getDescription(), is(description));
    assertThat(eventSourceEntity.getEvent().getName(), is(event));
    assertThat(eventSourceEntity.getSource().getEntityType(), is(source));
    assertThat(eventSourceEntity.getDescription(), is(description));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 10 with EventSourceDto

use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.

the class QuestionnaireServiceTest method shouldGetAllQuestionGroupsByEventSource.

@Test
public void shouldGetAllQuestionGroupsByEventSource() throws SystemException {
    List<QuestionGroup> questionGroups = asList(getQuestionGroup(1, "Title1", "View", "Loan", QuestionGroupState.ACTIVE, true, getSections("Section1")), getQuestionGroup(2, "Title2", "View", "Loan", QuestionGroupState.ACTIVE, true, getSections("Section2")));
    when(questionGroupDao.retrieveQuestionGroupsByEventSource("Create", "Client")).thenReturn(questionGroups);
    List<QuestionGroupDetail> questionGroupDetails = questionnaireService.getQuestionGroups(new EventSourceDto("Create", "Client", "Create.Client"));
    assertThat(questionGroupDetails, is(notNullValue()));
    assertThat(questionGroupDetails.size(), is(2));
    assertThat(questionGroupDetails.get(0).getTitle(), is("Title1"));
    assertThat(questionGroupDetails.get(1).getTitle(), is("Title2"));
    verify(questionnaireValidator, times(1)).validateForEventSource(any(EventSourceDto.class));
    verify(questionGroupDao, times(1)).retrieveQuestionGroupsByEventSource("Create", "Client");
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Aggregations

EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)39 Test (org.junit.Test)28 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)15 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)12 ArrayList (java.util.ArrayList)10 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)6 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 SystemException (org.mifos.framework.exceptions.SystemException)4 EventSourcesMatcher (org.mifos.platform.questionnaire.matchers.EventSourcesMatcher)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 QuestionGroupInstanceDetail (org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)3 ValidationException (org.mifos.platform.validations.ValidationException)3 LinkedHashMap (java.util.LinkedHashMap)2 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)2 Section (org.mifos.platform.questionnaire.domain.Section)2 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)2 MandatoryAnswerNotFoundException (org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException)2 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2