Search in sources :

Example 1 with EventQuery

use of org.hisp.dhis.android.core.event.EventQuery in project dhis2-android-sdk by dhis2.

the class SingleDataCall method eventCall.

private Response eventCall(Date serverDate) throws Exception {
    Response response = null;
    Set<String> organisationUnitUids = organisationUnitStore.selectUids();
    // TODO: we should download events by orgunit and program
    // programs to retrieve from DB should be non tracker programs
    // TrackerPrograms: programType = WITH_REGISTRATION
    // Non TrackerPrograms: programType = WITHOUT_REGISTRATION
    int pageSize = EventQuery.Builder.create().build().getPageSize();
    int numPages = (int) Math.ceil((double) eventLimitByOrgUnit / pageSize);
    int eventsDownloaded = 0;
    int pageLimit = 0;
    for (String orgUnitUid : organisationUnitUids) {
        for (int page = 1; page <= numPages; page++) {
            if (page == numPages && eventLimitByOrgUnit > 0) {
                pageLimit = eventLimitByOrgUnit - eventsDownloaded;
            }
            EventQuery eventQuery = EventQuery.Builder.create().withOrgUnit(orgUnitUid).withPage(page).withPageLimit(pageLimit).build();
            response = new EventEndPointCall(eventService, databaseAdapter, resourceHandler, eventHandler, serverDate, eventQuery).call();
            if (!response.isSuccessful()) {
                return response;
            }
            eventsDownloaded = eventsDownloaded + eventQuery.getPageSize();
        }
    }
    return response;
}
Also used : Response(retrofit2.Response) EventQuery(org.hisp.dhis.android.core.event.EventQuery) EventEndPointCall(org.hisp.dhis.android.core.event.EventEndPointCall)

Example 2 with EventQuery

use of org.hisp.dhis.android.core.event.EventQuery in project dhis2-android-sdk by dhis2.

the class EventCallFactory method create.

public static EventEndPointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter, String orgUnit, int pageLimit, String categoryComboUID, String categoryOptionUID) {
    EventService eventService = retrofit.create(EventService.class);
    EventHandler eventHandler = HandlerFactory.createEventHandler(databaseAdapter);
    ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
    CategoryCombo categoryCombo = CategoryCombo.builder().uid(categoryComboUID).build();
    CategoryOption categoryOption = CategoryOption.builder().uid(categoryOptionUID).build();
    EventQuery eventQuery = EventQuery.Builder.create().withOrgUnit(orgUnit).withPageLimit(pageLimit).withCategoryComboAndCategoryOption(categoryCombo, categoryOption).build();
    EventEndPointCall eventEndPointCall = new EventEndPointCall(eventService, databaseAdapter, resourceHandler, eventHandler, new Date(), eventQuery);
    return eventEndPointCall;
}
Also used : CategoryCombo(org.hisp.dhis.android.core.category.CategoryCombo) EventQuery(org.hisp.dhis.android.core.event.EventQuery) EventHandler(org.hisp.dhis.android.core.event.EventHandler) CategoryOption(org.hisp.dhis.android.core.category.CategoryOption) EventService(org.hisp.dhis.android.core.event.EventService) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) EventEndPointCall(org.hisp.dhis.android.core.event.EventEndPointCall) Date(java.util.Date)

Aggregations

EventEndPointCall (org.hisp.dhis.android.core.event.EventEndPointCall)2 EventQuery (org.hisp.dhis.android.core.event.EventQuery)2 Date (java.util.Date)1 CategoryCombo (org.hisp.dhis.android.core.category.CategoryCombo)1 CategoryOption (org.hisp.dhis.android.core.category.CategoryOption)1 EventHandler (org.hisp.dhis.android.core.event.EventHandler)1 EventService (org.hisp.dhis.android.core.event.EventService)1 ResourceHandler (org.hisp.dhis.android.core.resource.ResourceHandler)1 Response (retrofit2.Response)1