Search in sources :

Example 1 with UploadAuthRequestedException

use of org.odk.collect.android.upload.UploadAuthRequestedException in project collect by opendatakit.

the class InstanceServerUploaderTask method doInBackground.

@Override
public Outcome doInBackground(Long... instanceIdsToUpload) {
    Outcome outcome = new Outcome();
    InstanceServerUploader uploader = new InstanceServerUploader(httpInterface, webCredentialsUtils, new HashMap<>(), settingsProvider.getUnprotectedSettings());
    List<Instance> instancesToUpload = uploader.getInstancesFromIds(instanceIdsToUpload);
    String deviceId = new PropertyManager().getSingularProperty(PropertyManager.PROPMGR_DEVICE_ID);
    for (int i = 0; i < instancesToUpload.size(); i++) {
        if (isCancelled()) {
            return outcome;
        }
        Instance instance = instancesToUpload.get(i);
        publishProgress(i + 1, instancesToUpload.size());
        try {
            String destinationUrl = uploader.getUrlToSubmitTo(instance, deviceId, completeDestinationUrl, null);
            String customMessage = uploader.uploadOneSubmission(instance, destinationUrl);
            outcome.messagesByInstanceId.put(instance.getDbId().toString(), customMessage != null ? customMessage : getLocalizedString(Collect.getInstance(), R.string.success));
            analytics.logEvent(SUBMISSION, "HTTP", Collect.getFormIdentifierHash(instance.getFormId(), instance.getFormVersion()));
        } catch (UploadAuthRequestedException e) {
            outcome.authRequestingServer = e.getAuthRequestingServer();
        // Don't add the instance that caused an auth request to the map because we want to
        // retry. Items present in the map are considered already attempted and won't be
        // retried.
        } catch (UploadException e) {
            outcome.messagesByInstanceId.put(instance.getDbId().toString(), e.getDisplayMessage());
        }
    }
    return outcome;
}
Also used : InstanceServerUploader(org.odk.collect.android.upload.InstanceServerUploader) Instance(org.odk.collect.forms.instances.Instance) PropertyManager(org.odk.collect.android.logic.PropertyManager) UploadException(org.odk.collect.android.upload.UploadException) LocalizedApplicationKt.getLocalizedString(org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString) UploadAuthRequestedException(org.odk.collect.android.upload.UploadAuthRequestedException)

Aggregations

PropertyManager (org.odk.collect.android.logic.PropertyManager)1 InstanceServerUploader (org.odk.collect.android.upload.InstanceServerUploader)1 UploadAuthRequestedException (org.odk.collect.android.upload.UploadAuthRequestedException)1 UploadException (org.odk.collect.android.upload.UploadException)1 Instance (org.odk.collect.forms.instances.Instance)1 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)1