Search in sources :

Example 1 with EventFilters

use of org.hisp.dhis.client.sdk.core.event.EventFilters in project pictureapp by EyeSeeTea.

the class PullDhisSDKDataSource method pullData.

public void pullData(PullFilters pullFilters, List<OrganisationUnit> organisationUnits, IDataSourceCallback<List<Event>> callback) {
    boolean isNetworkAvailable = isNetworkAvailable();
    if (!isNetworkAvailable) {
        callback.onError(new NetworkException());
    } else {
        try {
            List<Event> events = new ArrayList<>();
            for (OrganisationUnit organisationUnit : organisationUnits) {
                Scheduler pullEventsThread = Schedulers.newThread();
                EventFilters eventFilters = new EventFilters();
                eventFilters.setStartDate(pullFilters.getStartDate());
                eventFilters.setEndDate(pullFilters.getEndDate());
                eventFilters.setMaxEvents(pullFilters.getMaxEvents());
                eventFilters.setOrganisationUnitUId(organisationUnit.getUId());
                mPullDhisSDKDataSourceStrategy.setEventFilters(eventFilters);
                List<Event> eventsByOrgUnit = D2.events().pull(eventFilters).subscribeOn(pullEventsThread).observeOn(pullEventsThread).toBlocking().single();
                events.addAll(eventsByOrgUnit);
            }
            callback.onSuccess(events);
        } catch (Exception e) {
            callback.onError(e);
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit) Scheduler(rx.Scheduler) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.client.sdk.models.event.Event) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) EventFilters(org.hisp.dhis.client.sdk.core.event.EventFilters)

Aggregations

ArrayList (java.util.ArrayList)1 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)1 EventFilters (org.hisp.dhis.client.sdk.core.event.EventFilters)1 Event (org.hisp.dhis.client.sdk.models.event.Event)1 OrganisationUnit (org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit)1 Scheduler (rx.Scheduler)1