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