Search in sources :

Example 1 with FormDownloadException

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();
    }
}
Also used : ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) Form(org.odk.collect.forms.Form) FormDeleter(org.odk.collect.android.formmanagement.FormDeleter) FormDownloadException(org.odk.collect.android.formmanagement.FormDownloadException)

Example 2 with FormDownloadException

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;
}
Also used : ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) HashMap(java.util.HashMap) LocalizedApplicationKt.getLocalizedString(org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString) FormDownloadException(org.odk.collect.android.formmanagement.FormDownloadException)

Aggregations

FormDownloadException (org.odk.collect.android.formmanagement.FormDownloadException)2 ServerFormDetails (org.odk.collect.android.formmanagement.ServerFormDetails)2 HashMap (java.util.HashMap)1 FormDeleter (org.odk.collect.android.formmanagement.FormDeleter)1 Form (org.odk.collect.forms.Form)1 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)1