use of org.odk.collect.forms.Form in project collect by opendatakit.
the class FormsRepositoryTest method getAllNotDeletedByFormId_doesNotReturnDeletedForms.
@Test
public void getAllNotDeletedByFormId_doesNotReturnDeletedForms() {
FormsRepository formsRepository = buildSubject();
formsRepository.save(FormUtils.buildForm("1", "deleted", getFormFilesPath()).deleted(true).build());
formsRepository.save(FormUtils.buildForm("1", "not-deleted", getFormFilesPath()).deleted(false).build());
List<Form> forms = formsRepository.getAllNotDeletedByFormId("1");
assertThat(forms.size(), is(1));
assertThat(forms.get(0).getVersion(), equalTo("not-deleted"));
}
use of org.odk.collect.forms.Form in project collect by opendatakit.
the class FormsRepositoryTest method save_addsId.
@Test
public void save_addsId() {
FormsRepository formsRepository = buildSubject();
Form form = FormUtils.buildForm("id", "version", getFormFilesPath()).build();
formsRepository.save(form);
assertThat(formsRepository.getAll().get(0).getDbId(), notNullValue());
}
use of org.odk.collect.forms.Form in project collect by opendatakit.
the class FormsRepositoryTest method save_whenFormHasId_updatesExisting.
@Test
public void save_whenFormHasId_updatesExisting() {
FormsRepository formsRepository = buildSubject();
Form originalForm = formsRepository.save(FormUtils.buildForm("id", "version", getFormFilesPath()).displayName("original").build());
formsRepository.save(new Form.Builder(originalForm).displayName("changed").build());
assertThat(formsRepository.get(originalForm.getDbId()).getDisplayName(), is("changed"));
}
use of org.odk.collect.forms.Form in project collect by opendatakit.
the class FormsProvider method update.
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
deferDaggerInit();
String projectId = getProjectId(uri);
logServerEvent(projectId, AnalyticsEvents.FORMS_PROVIDER_UPDATE);
FormsRepository formsRepository = getFormsRepository(projectId);
String formsPath = storagePathProvider.getOdkDirPath(StorageSubdirectory.FORMS, projectId);
String cachePath = storagePathProvider.getOdkDirPath(StorageSubdirectory.CACHE, projectId);
int count;
switch(URI_MATCHER.match(uri)) {
case FORMS:
try (Cursor cursor = databaseQuery(projectId, null, where, whereArgs, null, null, null)) {
while (cursor.moveToNext()) {
Form form = getFormFromCurrentCursorPosition(cursor, formsPath, cachePath);
ContentValues existingValues = getValuesFromForm(form, formsPath);
existingValues.putAll(values);
formsRepository.save(getFormFromValues(existingValues, formsPath, cachePath));
}
count = cursor.getCount();
}
break;
case FORM_ID:
Form form = formsRepository.get(ContentUriHelper.getIdFromUri(uri));
if (form != null) {
ContentValues existingValues = getValuesFromForm(form, formsPath);
existingValues.putAll(values);
formsRepository.save(getFormFromValues(existingValues, formsPath, cachePath));
count = 1;
} else {
count = 0;
}
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
use of org.odk.collect.forms.Form in project collect by opendatakit.
the class DatabaseFormsRepository method getFormsFromCursor.
@NotNull
private static List<Form> getFormsFromCursor(Cursor cursor, String formsPath, String cachePath) {
List<Form> forms = new ArrayList<>();
if (cursor != null) {
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
Form form = getFormFromCurrentCursorPosition(cursor, formsPath, cachePath);
forms.add(form);
}
}
return forms;
}
Aggregations