Search in sources :

Example 1 with EventStoreImpl

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

the class TrackedEntityInstanceCallMockIntegrationShould method getDownloadedTei.

private TrackedEntityInstance getDownloadedTei(String teiUid) {
    TrackedEntityInstance downloadedTei;
    TrackedEntityAttributeValueStore teiAttributeValuesStore = new TrackedEntityAttributeValueStoreImpl(databaseAdapter());
    Map<String, List<TrackedEntityAttributeValue>> attValues = teiAttributeValuesStore.queryAll();
    TrackedEntityInstanceStoreImpl teiStore = new TrackedEntityInstanceStoreImpl(databaseAdapter());
    downloadedTei = teiStore.queryAll().get(teiUid);
    EnrollmentStoreImpl enrollmentStore = new EnrollmentStoreImpl(databaseAdapter());
    Map<String, List<Enrollment>> downloadedEnrollments = enrollmentStore.queryAll();
    EventStoreImpl eventStore = new EventStoreImpl(databaseAdapter());
    List<Event> downloadedEventsWithoutValues = eventStore.queryAll();
    TrackedEntityDataValueStoreImpl trackedEntityDataValue = new TrackedEntityDataValueStoreImpl(databaseAdapter());
    Map<String, List<TrackedEntityDataValue>> downloadedValues = trackedEntityDataValue.queryTrackedEntityDataValues();
    return createTei(downloadedTei, attValues, downloadedEnrollments.get(teiUid), downloadedEventsWithoutValues, downloadedValues);
}
Also used : EnrollmentStoreImpl(org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl) EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) Event(org.hisp.dhis.android.core.event.Event) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with EventStoreImpl

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

the class TrackedEntityInstancePostCallRealIntegrationShould method setUp.

@Before
@Override
public void setUp() throws IOException {
    super.setUp();
    d2 = D2Factory.create("https://play.dhis2.org/android-current/api/", databaseAdapter());
    trackedEntityInstanceStore = new TrackedEntityInstanceStoreImpl(databaseAdapter());
    enrollmentStore = new EnrollmentStoreImpl(databaseAdapter());
    eventStore = new EventStoreImpl(databaseAdapter());
    trackedEntityAttributeValueStore = new TrackedEntityAttributeValueStoreImpl(databaseAdapter());
    trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter());
    codeGenerator = new CodeGeneratorImpl();
    orgUnitUid = "DiszpKrYNg8";
    programUid = "IpHINAT79UW";
    programStageUid = "A03MvHHogjR";
    dataElementUid = "a3kGcGDCuk6";
    trackedEntityUid = "nEenWmSyUEp";
    trackedEntityAttributeUid = "w75KJ2mc4zz";
    coordinates = "[9,9]";
    featureType = FeatureType.POINT;
    categoryOptionUid = "CW81uF03hvV";
    categoryComboOptionUid = "l5QR5hJ4u44";
    eventUid = codeGenerator.generate();
    enrollmentUid = codeGenerator.generate();
    trackedEntityInstanceUid = codeGenerator.generate();
    event1Uid = codeGenerator.generate();
    enrollment1Uid = codeGenerator.generate();
    trackedEntityInstance1Uid = codeGenerator.generate();
}
Also used : CodeGeneratorImpl(org.hisp.dhis.android.core.utils.CodeGeneratorImpl) EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) EnrollmentStoreImpl(org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl) Before(org.junit.Before)

Example 3 with EventStoreImpl

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

the class DataBaseMigrationShould method have_database_version_3_after_migration_from_database_with_content.

@Test
public void have_database_version_3_after_migration_from_database_with_content() throws IOException {
    // given
    final String finalEventScheme = "CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL " + "UNIQUE,enrollment TEXT, created TEXT,lastUpdated TEXT,createdAtClient " + "TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude " + "TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit" + " TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state " + "TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, " + "trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program " + "(uid) ON DELETE CASCADE, FOREIGN KEY (programStage) REFERENCES " + "ProgramStage (uid) ON DELETE CASCADE,FOREIGN KEY (enrollment) " + "REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY " + "DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit " + "(uid) ON DELETE CASCADE)";
    final String finalTrackedEntityDataValueScheme = "CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event" + " TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT," + "created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY " + "(dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE,  FOREIGN" + " KEY (event) REFERENCES Event (uid) ON DELETE CASCADE)";
    initCoreDataBase(dbName, 2, realMigrationDir, databaseSqlVersion2_with_data);
    EventStore eventStore = new EventStoreImpl(databaseAdapter);
    List<Event> eventList = eventStore.queryAll();
    TrackedEntityDataValueStore trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
    Map<String, List<TrackedEntityDataValue>> listOfTrackedEntityDataValues = trackedEntityDataValueStore.queryTrackedEntityDataValues();
    // when
    initCoreDataBase(dbName, 3, realMigrationDir, "");
    eventStore = new EventStoreImpl(databaseAdapter);
    trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
    // then
    assertTrue(eventList.equals(eventStore.queryAll()));
    assertTrue(eventList.size() == 50);
    assertTrue(listOfTrackedEntityDataValues.equals(trackedEntityDataValueStore.queryTrackedEntityDataValues()));
    assertTrue(listOfTrackedEntityDataValues.size() == 50);
    assertTrue(listOfTrackedEntityDataValues.get(eventList.get(0).uid()).equals(listOfTrackedEntityDataValues.get(eventList.get(0).uid())));
    assertTrue(getSqlTableScheme(databaseAdapter, "Event").equals(finalEventScheme));
    assertTrue(getSqlTableScheme(databaseAdapter, "TrackedEntityDataValue").equals(finalTrackedEntityDataValueScheme));
}
Also used : TrackedEntityDataValueStore(org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore) EventStore(org.hisp.dhis.android.core.event.EventStore) EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) TrackedEntityDataValueStoreImpl(org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl) Event(org.hisp.dhis.android.core.event.Event) List(java.util.List) Test(org.junit.Test)

Example 4 with EventStoreImpl

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

the class SingleDataCallMockIntegrationShould method download_number_of_events_according_to_limit_by_org_unit.

@Test
public void download_number_of_events_according_to_limit_by_org_unit() throws Exception {
    int eventLimitByOrgUnit = 122;
    givenAMetadataInDatabase();
    dhis2MockServer.enqueueMockResponse("system_info.json");
    dhis2MockServer.enqueueMockResponse("events_1.json");
    dhis2MockServer.enqueueMockResponse("events_2.json");
    dhis2MockServer.enqueueMockResponse("events_3.json");
    d2.syncSingleData(eventLimitByOrgUnit).call();
    EventStoreImpl eventStore = new EventStoreImpl(databaseAdapter());
    List<Event> downloadedEvents = eventStore.querySingleEvents();
    assertThat(downloadedEvents.size(), is(eventLimitByOrgUnit));
}
Also used : EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) Event(org.hisp.dhis.android.core.event.Event) Test(org.junit.Test)

Example 5 with EventStoreImpl

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

the class HandlerFactory method createEventHandler.

public static EventHandler createEventHandler(DatabaseAdapter databaseAdapter) {
    TrackedEntityDataValueHandler trackedEntityDataValueHandler = createTrackedEntityDataValueHandler(databaseAdapter);
    EventStore eventStore = new EventStoreImpl(databaseAdapter);
    EventHandler eventHandler = new EventHandler(eventStore, trackedEntityDataValueHandler);
    return eventHandler;
}
Also used : EventStore(org.hisp.dhis.android.core.event.EventStore) EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) TrackedEntityDataValueHandler(org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueHandler) EventHandler(org.hisp.dhis.android.core.event.EventHandler)

Aggregations

EventStoreImpl (org.hisp.dhis.android.core.event.EventStoreImpl)6 Event (org.hisp.dhis.android.core.event.Event)4 List (java.util.List)2 EnrollmentStoreImpl (org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl)2 EventStore (org.hisp.dhis.android.core.event.EventStore)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 EventHandler (org.hisp.dhis.android.core.event.EventHandler)1 TrackedEntityDataValueHandler (org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueHandler)1 TrackedEntityDataValueStore (org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore)1 TrackedEntityDataValueStoreImpl (org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl)1 CodeGeneratorImpl (org.hisp.dhis.android.core.utils.CodeGeneratorImpl)1 Before (org.junit.Before)1