Search in sources :

Example 1 with Callback

use of de.symeda.sormas.app.util.Callback in project SORMAS-Project by hzi-braunschweig.

the class SettingsFragment method showRepullDataConfirmationDialog.

private void showRepullDataConfirmationDialog() {
    final ConfirmationDialog confirmationDialog = new ConfirmationDialog(getActivity(), R.string.heading_confirmation_dialog, R.string.info_resync_duration);
    confirmationDialog.setPositiveCallback(() -> {
        // Collect unsynchronized changes
        final List<Case> modifiedCases = DatabaseHelper.getCaseDao().getModifiedEntities();
        final List<Contact> modifiedContacts = DatabaseHelper.getContactDao().getModifiedEntities();
        final List<Person> modifiedPersons = DatabaseHelper.getPersonDao().getModifiedEntities();
        final List<Event> modifiedEvents = DatabaseHelper.getEventDao().getModifiedEntities();
        final List<EventParticipant> modifiedEventParticipants = DatabaseHelper.getEventParticipantDao().getModifiedEntities();
        final List<Sample> modifiedSamples = DatabaseHelper.getSampleDao().getModifiedEntities();
        final List<Visit> modifiedVisits = DatabaseHelper.getVisitDao().getModifiedEntities();
        getBaseActivity().synchronizeData(SynchronizeDataAsync.SyncMode.CompleteAndRepull, true, true, null, new Callback() {

            @Override
            public void call() {
                // Add deleted entities that had unsynchronized changes to sync log
                for (Case caze : modifiedCases) {
                    if (DatabaseHelper.getCaseDao().queryUuidReference(caze.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(caze.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
                for (Contact contact : modifiedContacts) {
                    if (DatabaseHelper.getContactDao().queryUuidReference(contact.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(contact.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
                for (Person person : modifiedPersons) {
                    if (DatabaseHelper.getPersonDao().queryUuidReference(person.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(person.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
                for (Event event : modifiedEvents) {
                    if (DatabaseHelper.getEventDao().queryUuidReference(event.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(event.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
                for (EventParticipant eventParticipant : modifiedEventParticipants) {
                    if (DatabaseHelper.getEventParticipantDao().queryUuidReference(eventParticipant.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(eventParticipant.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
                for (Sample sample : modifiedSamples) {
                    if (DatabaseHelper.getSampleDao().queryUuidReference(sample.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(sample.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
                for (Visit visit : modifiedVisits) {
                    if (DatabaseHelper.getVisitDao().queryUuidReference(visit.getUuid()) == null) {
                        DatabaseHelper.getSyncLogDao().createWithParentStack(visit.toString(), getResources().getString(R.string.caption_changed_data_lost));
                    }
                }
            }
        }, new Callback() {

            @Override
            public void call() {
                DatabaseHelper.clearTables(false);
            }
        });
    });
    confirmationDialog.show();
}
Also used : Sample(de.symeda.sormas.app.backend.sample.Sample) Visit(de.symeda.sormas.app.backend.visit.Visit) ConfirmationDialog(de.symeda.sormas.app.component.dialog.ConfirmationDialog) Case(de.symeda.sormas.app.backend.caze.Case) Contact(de.symeda.sormas.app.backend.contact.Contact) Callback(de.symeda.sormas.app.util.Callback) Event(de.symeda.sormas.app.backend.event.Event) Person(de.symeda.sormas.app.backend.person.Person) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant)

Aggregations

Case (de.symeda.sormas.app.backend.caze.Case)1 Contact (de.symeda.sormas.app.backend.contact.Contact)1 Event (de.symeda.sormas.app.backend.event.Event)1 EventParticipant (de.symeda.sormas.app.backend.event.EventParticipant)1 Person (de.symeda.sormas.app.backend.person.Person)1 Sample (de.symeda.sormas.app.backend.sample.Sample)1 Visit (de.symeda.sormas.app.backend.visit.Visit)1 ConfirmationDialog (de.symeda.sormas.app.component.dialog.ConfirmationDialog)1 Callback (de.symeda.sormas.app.util.Callback)1