Search in sources :

Example 1 with FormDeleter

use of org.odk.collect.android.formmanagement.FormDeleter 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 FormDeleter

use of org.odk.collect.android.formmanagement.FormDeleter in project collect by opendatakit.

the class FormsProvider method delete.

/**
 * This method removes the entry from the content provider, and also removes
 * any associated files. files: form.xml, [formmd5].formdef, formname-media
 * {directory}
 */
@Override
public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
    deferDaggerInit();
    int count;
    String projectId = getProjectId(uri);
    logServerEvent(projectId, AnalyticsEvents.FORMS_PROVIDER_DELETE);
    FormDeleter formDeleter = new FormDeleter(getFormsRepository(projectId), instancesRepositoryProvider.get(projectId));
    switch(URI_MATCHER.match(uri)) {
        case FORMS:
            try (Cursor cursor = databaseQuery(projectId, null, where, whereArgs, null, null, null)) {
                while (cursor.moveToNext()) {
                    formDeleter.delete(cursor.getLong(cursor.getColumnIndex(_ID)));
                }
                count = cursor.getCount();
            }
            break;
        case FORM_ID:
            formDeleter.delete(ContentUriHelper.getIdFromUri(uri));
            count = 1;
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}
Also used : Cursor(android.database.Cursor) FormDeleter(org.odk.collect.android.formmanagement.FormDeleter)

Example 3 with FormDeleter

use of org.odk.collect.android.formmanagement.FormDeleter in project collect by opendatakit.

the class DeleteFormsTask method doInBackground.

@Override
protected Integer doInBackground(Long... params) {
    int deleted = 0;
    if (params == null || dl == null) {
        return deleted;
    }
    toDeleteCount = params.length;
    // delete files from database and then from file system
    for (Long param : params) {
        if (isCancelled()) {
            break;
        }
        try {
            new FormDeleter(formsRepository, instancesRepository).delete(param);
            deleted++;
            successCount++;
            publishProgress(successCount, toDeleteCount);
        } catch (Exception ex) {
            Timber.e("Exception during delete of: %s exception: %s", param.toString(), ex.toString());
        }
    }
    successCount = deleted;
    return deleted;
}
Also used : FormDeleter(org.odk.collect.android.formmanagement.FormDeleter)

Aggregations

FormDeleter (org.odk.collect.android.formmanagement.FormDeleter)3 Cursor (android.database.Cursor)1 FormDownloadException (org.odk.collect.android.formmanagement.FormDownloadException)1 ServerFormDetails (org.odk.collect.android.formmanagement.ServerFormDetails)1 Form (org.odk.collect.forms.Form)1