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;
}
Aggregations