From 227adcd7e70e2ff7a3b6cc81724fe948b1b3109a Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Fri, 19 May 2023 13:09:23 +0200 Subject: [PATCH] Do not mark forms as failed to send before sending --- .../android/gdrive/InstanceGoogleSheetsUploader.java | 4 ++-- .../android/upload/InstanceServerUploader.java | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/gdrive/InstanceGoogleSheetsUploader.java b/collect_app/src/main/java/org/odk/collect/android/gdrive/InstanceGoogleSheetsUploader.java index b6cf964471a..45ba52dcf66 100644 --- a/collect_app/src/main/java/org/odk/collect/android/gdrive/InstanceGoogleSheetsUploader.java +++ b/collect_app/src/main/java/org/odk/collect/android/gdrive/InstanceGoogleSheetsUploader.java @@ -89,8 +89,6 @@ public InstanceGoogleSheetsUploader(DriveApi driveApi, SheetsApi sheetsApi) { @Override public String uploadOneSubmission(Instance instance, String spreadsheetUrl) throws FormUploadException { - markSubmissionFailed(instance); - File instanceFile = new File(instance.getInstanceFilePath()); if (!instanceFile.exists()) { throw new FormUploadException(FAIL + "instance XML file does not exist!"); @@ -106,6 +104,7 @@ public String uploadOneSubmission(Instance instance, String spreadsheetUrl) thro Form form = forms.get(0); if (form.getBASE64RSAPublicKey() != null) { + markSubmissionFailed(instance); throw new FormUploadException(getLocalizedString(Collect.getInstance(), R.string.google_sheets_encrypted_message)); } @@ -123,6 +122,7 @@ public String uploadOneSubmission(Instance instance, String spreadsheetUrl) thro } insertRows(instance, instanceElement, null, key, instanceFile, spreadsheet.getSheets().get(0).getProperties().getTitle()); } catch (GoogleJsonResponseException e) { + markSubmissionFailed(instance); throw new FormUploadException(getErrorMessageFromGoogleJsonResponseException(e)); } diff --git a/collect_app/src/main/java/org/odk/collect/android/upload/InstanceServerUploader.java b/collect_app/src/main/java/org/odk/collect/android/upload/InstanceServerUploader.java index 04feea07f9b..09fb7ae2cf2 100644 --- a/collect_app/src/main/java/org/odk/collect/android/upload/InstanceServerUploader.java +++ b/collect_app/src/main/java/org/odk/collect/android/upload/InstanceServerUploader.java @@ -71,8 +71,6 @@ public InstanceServerUploader(OpenRosaHttpInterface httpInterface, */ @Override public String uploadOneSubmission(Instance instance, String urlString) throws FormUploadException { - markSubmissionFailed(instance); - Uri submissionUri = Uri.parse(urlString); long contentLength = 10000000L; @@ -86,6 +84,7 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Fo submissionUri.toString()); } else { if (submissionUri.getHost() == null) { + markSubmissionFailed(instance); throw new FormUploadException(FAIL + "Host name may not be null"); } @@ -93,6 +92,7 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Fo try { uri = URI.create(submissionUri.toString()); } catch (IllegalArgumentException e) { + markSubmissionFailed(instance); Timber.d(e.getMessage() != null ? e.getMessage() : e.toString()); throw new FormUploadException(getLocalizedString(Collect.getInstance(), R.string.url_error)); } @@ -113,11 +113,13 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Fo } } catch (Exception e) { + markSubmissionFailed(instance); throw new FormUploadException(FAIL + (e.getMessage() != null ? e.getMessage() : e.toString())); } if (headResult.getStatusCode() == HttpsURLConnection.HTTP_UNAUTHORIZED) { + markSubmissionFailed(instance); throw new FormUploadAuthRequestedException(getLocalizedString(Collect.getInstance(), R.string.server_auth_credentials, submissionUri.getHost()), submissionUri); } else if (headResult.getStatusCode() == HttpsURLConnection.HTTP_NO_CONTENT) { @@ -138,17 +140,20 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Fo } else { // Don't follow a redirection attempt to a different host. // We can't tell if this is a spoof or not. + markSubmissionFailed(instance); throw new FormUploadException(FAIL + "Unexpected redirection attempt to a different host: " + newURI.toString()); } } catch (Exception e) { + markSubmissionFailed(instance); throw new FormUploadException(FAIL + urlString + " " + e.toString()); } } } else { if (headResult.getStatusCode() >= HttpsURLConnection.HTTP_OK && headResult.getStatusCode() < HttpsURLConnection.HTTP_MULT_CHOICE) { + markSubmissionFailed(instance); throw new FormUploadException("Failed to send to " + uri + ". Is this an OpenRosa " + "submission endpoint? If you have a web proxy you may need to log in to " + "your network.\n\nHEAD request result status code: " + headResult.getStatusCode()); @@ -170,6 +175,7 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Fo } if (!instanceFile.exists() && !submissionFile.exists()) { + markSubmissionFailed(instance); throw new FormUploadException(FAIL + "instance XML file does not exist!"); } @@ -210,10 +216,12 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Fo } } + markSubmissionFailed(instance); throw exception; } } catch (Exception e) { + markSubmissionFailed(instance); throw new FormUploadException(FAIL + "Generic Exception: " + (e.getMessage() != null ? e.getMessage() : e.toString())); }