use of org.odk.collect.android.formmanagement.FormDownloadException in project collect by opendatakit.
the class ServerFormsSynchronizer method synchronize.
public void synchronize() throws FormSourceException {
List<ServerFormDetails> formList = serverFormsDetailsFetcher.fetchFormDetails();
List<Form> formsOnDevice = formsRepository.getAll();
FormDeleter formDeleter = new FormDeleter(formsRepository, instancesRepository);
formsOnDevice.stream().forEach(form -> {
if (formList.stream().noneMatch(f -> form.getFormId().equals(f.getFormId()))) {
formDeleter.delete(form.getDbId());
}
});
boolean downloadException = false;
for (ServerFormDetails form : formList) {
if (form.isNotOnDevice() || form.isUpdated()) {
try {
formDownloader.downloadForm(form, null, null);
} catch (FormDownloadException.DownloadingInterrupted e) {
return;
} catch (FormDownloadException e) {
downloadException = true;
}
}
}
if (downloadException) {
throw new FormSourceException.FetchError();
}
}
use of org.odk.collect.android.formmanagement.FormDownloadException in project collect by opendatakit.
the class DownloadFormsTask method doInBackground.
@Override
protected Map<ServerFormDetails, FormDownloadException> doInBackground(ArrayList<ServerFormDetails>... values) {
HashMap<ServerFormDetails, FormDownloadException> results = new HashMap<>();
int index = 1;
for (ServerFormDetails serverFormDetails : values[0]) {
try {
String currentFormNumber = String.valueOf(index);
String totalForms = String.valueOf(values[0].size());
publishProgress(serverFormDetails.getFormName(), currentFormNumber, totalForms);
formDownloader.downloadForm(serverFormDetails, count -> {
String message = getLocalizedString(Collect.getInstance(), R.string.form_download_progress, serverFormDetails.getFormName(), String.valueOf(count), String.valueOf(serverFormDetails.getManifest().getMediaFiles().size()));
publishProgress(message, currentFormNumber, totalForms);
}, this::isCancelled);
results.put(serverFormDetails, null);
} catch (FormDownloadException.DownloadingInterrupted e) {
return emptyMap();
} catch (FormDownloadException e) {
results.put(serverFormDetails, e);
}
index++;
}
return results;
}
Aggregations