Search in sources :

Example 1 with EventEndPointCall

use of org.hisp.dhis.android.core.event.EventEndPointCall 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 EventEndPointCall

use of org.hisp.dhis.android.core.event.EventEndPointCall 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)

Example 3 with EventEndPointCall

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

the class LogoutCallRealIntegrationShould method delete_autenticate_user_table_only_when_log_out_after_sync_data.

// @Test
public void delete_autenticate_user_table_only_when_log_out_after_sync_data() throws Exception {
    retrofit2.Response response = null;
    response = d2.logIn("android", "Android123").call();
    assertThat(response.isSuccessful()).isTrue();
    response = d2.syncMetaData().call();
    assertThat(response.isSuccessful()).isTrue();
    EventEndPointCall eventCall = EventCallFactory.create(d2.retrofit(), databaseAdapter(), "DiszpKrYNg8", 0);
    eventCall.call();
    assertThat(isDatabaseEmpty(databaseAdapter())).isFalse();
    d2.logout().call();
    assertThat(isDatabaseEmpty(databaseAdapter())).isFalse();
    assertThat(isTableEmpty(databaseAdapter(), EventModel.TABLE)).isFalse();
    assertThat(isTableEmpty(databaseAdapter(), AuthenticatedUserModel.TABLE)).isTrue();
}
Also used : EventEndPointCall(org.hisp.dhis.android.core.event.EventEndPointCall)

Example 4 with EventEndPointCall

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

the class LogoutCallRealIntegrationShould method have_empty_database_when_wipe_db_after_sync_data.

// @Test
public void have_empty_database_when_wipe_db_after_sync_data() throws Exception {
    retrofit2.Response response = null;
    response = d2.logIn("android", "Android123").call();
    assertThat(response.isSuccessful()).isTrue();
    response = d2.syncMetaData().call();
    assertThat(response.isSuccessful()).isTrue();
    EventEndPointCall eventCall = EventCallFactory.create(d2.retrofit(), databaseAdapter(), "DiszpKrYNg8", 0);
    eventCall.call();
    DatabaseAssert.assertThatDatabase(databaseAdapter()).isNotEmpty();
    d2.wipeDB().call();
    DatabaseAssert.assertThatDatabase(databaseAdapter()).isEmpty();
}
Also used : EventEndPointCall(org.hisp.dhis.android.core.event.EventEndPointCall)

Example 5 with EventEndPointCall

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

the class LogoutCallMockIntegrationShould method givenAEventInDatabase.

private void givenAEventInDatabase() throws Exception {
    EventEndPointCall eventCall = EventCallFactory.create(d2.retrofit(), databaseAdapter(), "DiszpKrYNg8", 0);
    dhis2MockServer.enqueueMockResponse("events.json");
    Response response = eventCall.call();
    assertThat(response.isSuccessful(), is(true));
}
Also used : Response(retrofit2.Response) EventEndPointCall(org.hisp.dhis.android.core.event.EventEndPointCall)

Aggregations

EventEndPointCall (org.hisp.dhis.android.core.event.EventEndPointCall)5 EventQuery (org.hisp.dhis.android.core.event.EventQuery)2 Response (retrofit2.Response)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