Search in sources :

Example 1 with EventStore

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

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

EventStore (org.hisp.dhis.android.core.event.EventStore)2 EventStoreImpl (org.hisp.dhis.android.core.event.EventStoreImpl)2 List (java.util.List)1 Event (org.hisp.dhis.android.core.event.Event)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 Test (org.junit.Test)1