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;
}
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;
}
Aggregations