Search in sources :

Example 31 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class TrackerEventsExportController method getEvents.

@GetMapping(produces = APPLICATION_JSON_VALUE)
public PagingWrapper<org.hisp.dhis.tracker.domain.Event> getEvents(TrackerEventCriteria eventCriteria, @RequestParam Map<String, String> parameters, HttpServletRequest request) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    EventSearchParams eventSearchParams = requestToSearchParamsMapper.map(eventCriteria);
    if (areAllEnrollmentsInvalid(eventCriteria, eventSearchParams)) {
        return new PagingWrapper<org.hisp.dhis.tracker.domain.Event>().withInstances(Collections.emptyList());
    }
    Events events = eventService.getEvents(eventSearchParams);
    if (hasHref(fields, eventCriteria.getSkipEventId())) {
        events.getEvents().forEach(e -> e.setHref(getUri(e.getEvent(), request)));
    }
    PagingWrapper<org.hisp.dhis.tracker.domain.Event> eventPagingWrapper = new PagingWrapper<>();
    if (eventCriteria.isPagingRequest()) {
        eventPagingWrapper = eventPagingWrapper.withPager(PagingWrapper.Pager.fromLegacy(eventCriteria, events.getPager()));
    }
    return eventPagingWrapper.withInstances(EVENTS_MAPPER.fromCollection(events.getEvents()));
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) Events(org.hisp.dhis.dxf2.events.event.Events) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Event(org.hisp.dhis.dxf2.events.event.Event) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 32 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class EventRequestToParamsMapperTest method testEventRequestToSearchParamsMapperSuccess.

@Test
void testEventRequestToSearchParamsMapperSuccess() {
    EventSearchParams eventSearchParams = requestToSearchParamsMapper.map("programuid", null, null, null, "orgunituid", OrganisationUnitSelectionMode.ACCESSIBLE, "teiUid", null, null, null, null, null, null, null, null, null, null, null, null, false, false, null, null, false, new HashSet<>(), new HashSet<>(), null, null, new HashSet<>(), Collections.singleton("UXz7xuGCEhU:GT:100"), new HashSet<>(), false, // Then
    false);
    assertThat(eventSearchParams, is(not(nullValue())));
}
Also used : EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Test(org.junit.jupiter.api.Test)

Aggregations

EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)28 Events (org.hisp.dhis.dxf2.events.event.Events)11 Test (org.junit.jupiter.api.Test)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 Event (org.hisp.dhis.dxf2.events.event.Event)8 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)7 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)7 User (org.hisp.dhis.user.User)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 Program (org.hisp.dhis.program.Program)5 ProgramStage (org.hisp.dhis.program.ProgramStage)5 HashSet (java.util.HashSet)4 QueryItem (org.hisp.dhis.common.QueryItem)4 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)4 ImmutableList (com.google.common.collect.ImmutableList)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3