use of org.odk.collect.android.instancemanagement.InstanceDeleter in project collect by opendatakit.
the class DeleteInstancesTask method doInBackground.
@Override
protected Integer doInBackground(Long... params) {
int deleted = 0;
if (params == null) {
return deleted;
}
toDeleteCount = params.length;
InstanceDeleter instanceDeleter = new InstanceDeleter(instancesRepository, formsRepository);
// delete files from database and then from file system
for (Long param : params) {
if (isCancelled()) {
break;
}
try {
instanceDeleter.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;
}
use of org.odk.collect.android.instancemanagement.InstanceDeleter in project collect by opendatakit.
the class FormEntryActivity method loadFromIntent.
private void loadFromIntent(Intent intent) {
Uri uri = intent.getData();
String uriMimeType = null;
if (uri != null) {
uriMimeType = getContentResolver().getType(uri);
}
if (uriMimeType != null && uriMimeType.equals(InstancesContract.CONTENT_ITEM_TYPE)) {
Instance instance = new InstancesRepositoryProvider(Collect.getInstance()).get().get(ContentUriHelper.getIdFromUri(uri));
if (instance == null) {
createErrorDialog(getString(R.string.bad_uri, uri), true);
return;
}
instancePath = instance.getInstanceFilePath();
if (!new File(instancePath).exists()) {
analytics.logEvent(AnalyticsEvents.OPEN_DELETED_INSTANCE);
new InstanceDeleter(new InstancesRepositoryProvider(Collect.getInstance()).get(), formsRepository).delete(instance.getDbId());
createErrorDialog(getString(R.string.instance_deleted_message), true);
return;
}
List<Form> candidateForms = formsRepository.getAllByFormIdAndVersion(instance.getFormId(), instance.getFormVersion());
if (candidateForms.isEmpty()) {
createErrorDialog(getString(R.string.parent_form_not_present, instance.getFormId()) + ((instance.getFormVersion() == null) ? "" : "\n" + getString(R.string.version) + " " + instance.getFormVersion()), true);
return;
} else if (candidateForms.stream().filter(f -> !f.isDeleted()).count() > 1) {
createErrorDialog(getString(R.string.survey_multiple_forms_error), true);
return;
}
formPath = candidateForms.get(0).getFormFilePath();
} else if (uriMimeType != null && uriMimeType.equals(FormsContract.CONTENT_ITEM_TYPE)) {
Form form = formsRepositoryProvider.get().get(ContentUriHelper.getIdFromUri(uri));
if (form != null) {
formPath = form.getFormFilePath();
}
if (formPath == null) {
createErrorDialog(getString(R.string.bad_uri, uri), true);
return;
} else {
/**
* This is the fill-blank-form code path.See if there is a savepoint for this form
* that has never been explicitly saved by the user. If there is, open this savepoint(resume this filled-in form).
* Savepoints for forms that were explicitly saved will be recovered when that
* explicitly saved instance is edited via edit-saved-form.
*/
instancePath = loadSavePoint();
}
} else {
Timber.i("Unrecognized URI: %s", uri);
createErrorDialog(getString(R.string.unrecognized_uri, uri), true);
return;
}
formLoaderTask = new FormLoaderTask(instancePath, null, null);
showIfNotShowing(FormLoadingDialogFragment.class, getSupportFragmentManager());
formLoaderTask.execute(formPath);
}
use of org.odk.collect.android.instancemanagement.InstanceDeleter in project collect by opendatakit.
the class InstanceProvider 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) {
DaggerUtils.getComponent(getContext()).inject(this);
String projectId = getProjectId(uri);
logServerEvent(projectId, AnalyticsEvents.INSTANCE_PROVIDER_DELETE);
int count;
switch(URI_MATCHER.match(uri)) {
case INSTANCES:
try (Cursor cursor = dbQuery(projectId, new String[] { _ID }, where, whereArgs, null)) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(_ID));
new InstanceDeleter(instancesRepositoryProvider.get(projectId), formsRepositoryProvider.get(projectId)).delete(id);
}
count = cursor.getCount();
}
break;
case INSTANCE_ID:
long id = ContentUriHelper.getIdFromUri(uri);
if (where == null) {
new InstanceDeleter(instancesRepositoryProvider.get(projectId), formsRepositoryProvider.get(projectId)).delete(id);
} else {
try (Cursor cursor = dbQuery(projectId, new String[] { _ID }, where, whereArgs, null)) {
while (cursor.moveToNext()) {
if (cursor.getLong(cursor.getColumnIndex(_ID)) == id) {
new InstanceDeleter(instancesRepositoryProvider.get(), formsRepositoryProvider.get()).delete(id);
break;
}
}
}
}
count = 1;
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
Aggregations