Search in sources :

Example 1 with FormSourceException

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

the class SyncStatusAppStateTest method getSyncError_whenFinishSyncWithException_isException.

@Test
public void getSyncError_whenFinishSyncWithException_isException() {
    SyncStatusAppState syncStatusAppState = new SyncStatusAppState(context);
    syncStatusAppState.startSync("projectId");
    FormSourceException exception = new FormSourceException.FetchError();
    syncStatusAppState.finishSync("projectId", exception);
    assertThat(syncStatusAppState.getSyncError("projectId").getValue(), is(exception));
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) SyncStatusAppState(org.odk.collect.android.formmanagement.matchexactly.SyncStatusAppState) Test(org.junit.Test)

Example 2 with FormSourceException

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

the class ServerFormsSynchronizerTest method whenFetchingFormDetailsThrowsAnError_throwsError.

@Test
public void whenFetchingFormDetailsThrowsAnError_throwsError() throws Exception {
    FormSourceException exception = new FormSourceException.AuthRequired();
    when(serverFormDetailsFetcher.fetchFormDetails()).thenThrow(exception);
    try {
        synchronizer.synchronize();
    } catch (FormSourceException e) {
        assertThat(e, is(exception));
    }
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) Test(org.junit.Test)

Example 3 with FormSourceException

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

the class ServerFormDownloader method downloadForm.

@Override
public void downloadForm(ServerFormDetails form, @Nullable ProgressReporter progressReporter, @Nullable Supplier<Boolean> isCancelled) throws FormDownloadException {
    Form formOnDevice;
    try {
        formOnDevice = formsRepository.getOneByMd5Hash(validateHash(form.getHash()));
    } catch (IllegalArgumentException e) {
        throw new FormDownloadException.FormWithNoHash();
    }
    if (formOnDevice != null) {
        if (formOnDevice.isDeleted()) {
            formsRepository.restore(formOnDevice.getDbId());
        }
    } else {
        List<Form> allSameFormIdVersion = formsRepository.getAllByFormIdAndVersion(form.getFormId(), form.getFormVersion());
        if (!allSameFormIdVersion.isEmpty() && !form.getDownloadUrl().contains("/draft.xml")) {
            analytics.logEventWithParam(DOWNLOAD_SAME_FORMID_VERSION_DIFFERENT_HASH, "form", AnalyticsUtils.getFormHash(form.getFormId(), form.getFormName()));
        }
    }
    File tempDir = new File(cacheDir, "download-" + UUID.randomUUID().toString());
    tempDir.mkdirs();
    try {
        FormDownloaderListener stateListener = new ProgressReporterAndSupplierStateListener(progressReporter, isCancelled);
        processOneForm(form, stateListener, tempDir, formsDirPath, formMetadataParser);
    } catch (FormSourceException e) {
        throw new FormDownloadException.FormSourceError(e);
    } finally {
        try {
            deleteDirectory(tempDir);
        } catch (IOException ignored) {
        // ignored
        }
    }
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) FormDownloaderListener(org.odk.collect.android.listeners.FormDownloaderListener) Form(org.odk.collect.forms.Form) IOException(java.io.IOException) MediaFile(org.odk.collect.forms.MediaFile) File(java.io.File)

Example 4 with FormSourceException

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

the class DownloadFormListTask method doInBackground.

@Override
protected Pair<List<ServerFormDetails>, FormSourceException> doInBackground(Void... values) {
    if (webCredentialsUtils != null) {
        setTemporaryCredentials();
    }
    List<ServerFormDetails> formList = null;
    FormSourceException exception = null;
    try {
        formList = serverFormsDetailsFetcher.fetchFormDetails();
    } catch (FormSourceException e) {
        exception = e;
    } finally {
        if (webCredentialsUtils != null) {
            clearTemporaryCredentials();
        }
    }
    return new Pair<>(formList, exception);
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) Pair(androidx.core.util.Pair)

Aggregations

FormSourceException (org.odk.collect.forms.FormSourceException)4 Test (org.junit.Test)2 Pair (androidx.core.util.Pair)1 File (java.io.File)1 IOException (java.io.IOException)1 ServerFormDetails (org.odk.collect.android.formmanagement.ServerFormDetails)1 SyncStatusAppState (org.odk.collect.android.formmanagement.matchexactly.SyncStatusAppState)1 FormDownloaderListener (org.odk.collect.android.listeners.FormDownloaderListener)1 Form (org.odk.collect.forms.Form)1 MediaFile (org.odk.collect.forms.MediaFile)1