Search in sources :

Example 1 with SyncLogDao

use of de.symeda.sormas.app.backend.synclog.SyncLogDao in project SORMAS-Project by hzi-braunschweig.

the class BaseActivity method synchronizeData.

public void synchronizeData(final SynchronizeDataAsync.SyncMode syncMode, final boolean showUpgradePrompt, final boolean showProgressDialog, final SwipeRefreshLayout swipeRefreshLayout, final Callback resultCallback, final Callback beforeSyncCallback) {
    if (!checkActiveUser())
        return;
    if (RetroProvider.isConnectedOrConnecting()) {
        NotificationHelper.showNotification(BaseActivity.this, NotificationType.WARNING, "Background synchronization already in progress.");
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
        return;
    }
    if (showProgressDialog) {
        if (progressDialog == null || !progressDialog.isShowing()) {
            boolean isInitialSync = DatabaseHelper.getFacilityDao().isEmpty();
            progressDialog = ProgressDialog.show(this, getString(R.string.heading_synchronization), getString(isInitialSync ? R.string.info_initial_synchronization : R.string.info_synchronizing), true);
        }
    } else {
        progressDialog = null;
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(true);
        }
    }
    final SyncLogDao syncLogDao = DatabaseHelper.getSyncLogDao();
    final long syncLogCountBefore = syncLogDao.countOf();
    RetroProvider.connectAsyncHandled(this, showUpgradePrompt, false, result -> {
        if (Boolean.TRUE.equals(result)) {
            if (beforeSyncCallback != null)
                beforeSyncCallback.call();
            SynchronizeDataAsync.call(syncMode, getApplicationContext(), (syncFailed, syncFailedMessage) -> {
                if (swipeRefreshLayout != null) {
                    swipeRefreshLayout.setRefreshing(false);
                }
                if (progressDialog != null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                }
                BaseActivity.this.onResume();
                long syncLogCountAfter = syncLogDao.countOf();
                if (!syncFailed) {
                    if (syncLogCountAfter > syncLogCountBefore) {
                        showConflictSnackbar();
                    } else if (SynchronizeDataAsync.hasAnyUnsynchronizedData()) {
                        NotificationHelper.showNotification(BaseActivity.this, NotificationType.WARNING, R.string.message_sync_not_synchronized);
                    } else {
                        NotificationHelper.showNotification(BaseActivity.this, NotificationType.SUCCESS, R.string.message_sync_success);
                    }
                } else {
                    NotificationHelper.showNotification(BaseActivity.this, NotificationType.ERROR, syncFailedMessage);
                    checkActiveUser();
                }
                RetroProvider.disconnect();
                if (resultCallback != null)
                    resultCallback.call();
            });
        } else {
            if (swipeRefreshLayout != null) {
                swipeRefreshLayout.setRefreshing(false);
            }
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
                progressDialog = null;
            }
        }
    });
}
Also used : SyncLogDao(de.symeda.sormas.app.backend.synclog.SyncLogDao)

Example 2 with SyncLogDao

use of de.symeda.sormas.app.backend.synclog.SyncLogDao in project SORMAS-Project by hzi-braunschweig.

the class CaseBackendTest method shouldCreateSyncLogEntry.

// TODO #704
// @Test
// public void shouldUpdateUnreadStatus() throws DaoException {
// CaseDao caseDao = DatabaseHelper.getCaseDao();
// Case caze = TestEntityCreator.createCase();
// EpiDataBurial burial = TestEntityCreator.createEpiDataBurial(caze);
// 
// caze.setLocalChangeDate(DateHelper.addSeconds(caze.getLocalChangeDate(), 6));
// 
// // Updated case should be unread
// assertThat(caze.isUnreadOrChildUnread(), is(true));
// 
// caseDao.markAsRead(caze);
// caze = DatabaseHelper.getCaseDao().queryUuidWithEmbedded(caze.getUuid());
// // Case shouldn't be marked as unread after markAsRead has been called
// assertThat(caze.isUnreadOrChildUnread(), is(false));
// // UUID of embedded object should still be the same
// EpiDataBurial burialFromDB = DatabaseHelper.getEpiDataBurialDao().queryUuid(burial.getUuid());
// assertEquals(burial.getUuid(), burialFromDB.getUuid());
// }
@Test
public void shouldCreateSyncLogEntry() throws DaoException {
    SyncLogDao syncLogDao = DatabaseHelper.getSyncLogDao();
    assertThat(syncLogDao.countOf(), is(0L));
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    Case caze = TestEntityCreator.createCase();
    caze.setEpidNumber("AppEpidNumber");
    DatabaseHelper.getCaseDao().saveAndSnapshot(caze);
    DatabaseHelper.getPersonDao().saveAndSnapshot(caze.getPerson());
    Case mergeCase = (Case) caze.clone();
    mergeCase.setPerson((Person) caze.getPerson().clone());
    mergeCase.getPerson().setAddress((Location) caze.getPerson().getAddress().clone());
    mergeCase.setSymptoms((Symptoms) caze.getSymptoms().clone());
    mergeCase.setHospitalization((Hospitalization) caze.getHospitalization().clone());
    mergeCase.setEpiData((EpiData) caze.getEpiData().clone());
    mergeCase.setId(null);
    mergeCase.getPerson().setId(null);
    mergeCase.getPerson().getAddress().setId(null);
    mergeCase.getSymptoms().setId(null);
    mergeCase.getHospitalization().setId(null);
    mergeCase.getEpiData().setId(null);
    mergeCase.getClinicalCourse().setId(null);
    mergeCase.getPortHealthInfo().setId(null);
    mergeCase.getTherapy().setId(null);
    mergeCase.getHealthConditions().setId(null);
    mergeCase.getMaternalHistory().setId(null);
    mergeCase.setEpidNumber("ServerEpidNumber");
    caseDao.mergeOrCreate(mergeCase);
    DatabaseHelper.getPersonDao().mergeOrCreate(mergeCase.getPerson());
    assertThat(syncLogDao.countOf(), is(1L));
}
Also used : SyncLogDao(de.symeda.sormas.app.backend.synclog.SyncLogDao) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) Case(de.symeda.sormas.app.backend.caze.Case) Test(org.junit.Test)

Aggregations

SyncLogDao (de.symeda.sormas.app.backend.synclog.SyncLogDao)2 Case (de.symeda.sormas.app.backend.caze.Case)1 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)1 Test (org.junit.Test)1