Search in sources :

Example 26 with FormsRepository

use of org.odk.collect.forms.FormsRepository in project collect by opendatakit.

the class InstanceAutoSender method autoSendInstances.

public boolean autoSendInstances(String projectId) {
    FormsRepository formsRepository = formsRepositoryProvider.get(projectId);
    InstancesRepository instancesRepository = instancesRepositoryProvider.get(projectId);
    Settings generalSettings = settingsProvider.getUnprotectedSettings(projectId);
    InstanceSubmitter instanceSubmitter = new InstanceSubmitter(analytics, formsRepository, instancesRepository, googleAccountsManager, googleApiProvider, permissionsProvider, generalSettings);
    return changeLockProvider.getInstanceLock(projectId).withLock(acquiredLock -> {
        if (acquiredLock) {
            try {
                List<Instance> toUpload = getInstancesToAutoSend(formsRepository, instancesRepository, generalSettings);
                Pair<Boolean, String> results = instanceSubmitter.submitInstances(toUpload);
                notifier.onSubmission(results.first, results.second, projectId);
            } catch (SubmitException e) {
                switch(e.getType()) {
                    case GOOGLE_ACCOUNT_NOT_SET:
                        notifier.onSubmission(true, context.getString(R.string.google_set_account), projectId);
                        break;
                    case GOOGLE_ACCOUNT_NOT_PERMITTED:
                        notifier.onSubmission(true, context.getString(R.string.odk_permissions_fail), projectId);
                        break;
                    case NOTHING_TO_SUBMIT:
                        break;
                }
            }
            instancesAppState.update();
            return true;
        } else {
            return false;
        }
    });
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Settings(org.odk.collect.shared.settings.Settings)

Aggregations

FormsRepository (org.odk.collect.forms.FormsRepository)26 Form (org.odk.collect.forms.Form)21 Test (org.junit.Test)20 File (java.io.File)8 Instance (org.odk.collect.forms.instances.Instance)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 AsyncTask (android.os.AsyncTask)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 BUTTON_NEGATIVE (android.content.DialogInterface.BUTTON_NEGATIVE)2 BUTTON_POSITIVE (android.content.DialogInterface.BUTTON_POSITIVE)2 IntentFilter (android.content.IntentFilter)2 LocationManager (android.location.LocationManager)2 MediaPlayer (android.media.MediaPlayer)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2 ContextMenu (android.view.ContextMenu)2 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)2