use of org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance in project dhis2-android-sdk by dhis2.
the class TrackerDataCall method call.
@Override
public Response call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
Response response = null;
Map<String, TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceStore.querySynced();
if (!trackedEntityInstances.isEmpty()) {
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
response = new SystemInfoCall(databaseAdapter, systemInfoStore, systemInfoService, resourceStore).call();
if (!response.isSuccessful()) {
return response;
}
SystemInfo systemInfo = (SystemInfo) response.body();
Date serverDate = systemInfo.serverDate();
response = trackedEntityInstanceCall(serverDate, trackedEntityInstances);
transaction.setSuccessful();
} finally {
transaction.end();
}
}
return response;
}
use of org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance in project dhis2-android-sdk by dhis2.
the class TrackerDataCallMockIntegrationShould method not_download_tracked_entity_instances_if_does_not_exists_synced_in_database.
@Test
public void not_download_tracked_entity_instances_if_does_not_exists_synced_in_database() throws Exception {
givenAMetadataInDatabase();
TrackedEntityInstance toPostTrackedEntityInstance = givenAToPostTrackedEntityInstanceInDatabase();
Response response = d2.syncTrackerData().call();
verifyHaveNotSynchronized(response, Arrays.asList(toPostTrackedEntityInstance));
}
use of org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance in project dhis2-android-sdk by dhis2.
the class TrackerDataCallMockIntegrationShould method givenASyncedTrackedEntityInstancesInDatabase.
private List<TrackedEntityInstance> givenASyncedTrackedEntityInstancesInDatabase() {
TrackedEntityInstance ngelehunGunnarson = givenATrackedEntityInstancesInDatabase("PgmUFEQYZdt", State.SYNCED);
TrackedEntityInstance mikeBensinger = givenATrackedEntityInstancesInDatabase("IaxoagO9899", State.SYNCED);
return Arrays.asList(mikeBensinger, ngelehunGunnarson);
}
use of org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance in project dhis2-android-sdk by dhis2.
the class TrackerDataCallMockIntegrationShould method only_download_synced_tracked_entity_instance_that_exists_in_database.
@Test
public void only_download_synced_tracked_entity_instance_that_exists_in_database() throws Exception {
givenAMetadataInDatabase();
TrackedEntityInstance toPostTrackedEntityInstance = givenAToPostTrackedEntityInstanceInDatabase();
TrackedEntityInstance syncedTrackedEntityInstance = givenASyncedTrackedEntityInstanceInDatabase();
dhis2MockServer.enqueueMockResponse("system_info.json");
dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json");
Response response = d2.syncTrackerData().call();
verifyHaveSynchronized(response, Arrays.asList(syncedTrackedEntityInstance), Arrays.asList(toPostTrackedEntityInstance));
}
use of org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance in project dhis2-android-sdk by dhis2.
the class TrackerDataCallMockIntegrationShould method verifyHaveNotSynchronized.
private void verifyHaveNotSynchronized(Response response, List<TrackedEntityInstance> expectedToPost) {
Map<String, TrackedEntityInstance> inDatabaseToPost = trackedEntityInstanceStore.queryToPost();
Map<String, TrackedEntityInstance> inDatabaseSynced = trackedEntityInstanceStore.querySynced();
String lastUpdated = resourceStore.getLastUpdated(ResourceModel.Type.TRACKED_ENTITY_INSTANCE);
assertThat(response, is(nullValue()));
assertThat(inDatabaseSynced.size(), is(0));
assertThat(lastUpdated, is(nullValue()));
assertThat(inDatabaseToPost.size(), is(expectedToPost.size()));
for (TrackedEntityInstance trackedEntityInstance : expectedToPost) {
assertThat(inDatabaseToPost.containsKey(trackedEntityInstance.uid()), is(true));
}
}
Aggregations