Search in sources :

Example 36 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstanceDeleterTest method whenInstanceIsSubmitted_deletesInstanceWithLogging.

@Test
public void whenInstanceIsSubmitted_deletesInstanceWithLogging() {
    Instance instance = instancesRepository.save(buildInstance("1", "version", TempFiles.createTempDir().getAbsolutePath()).status(Instance.STATUS_SUBMITTED).build());
    instanceDeleter.delete(instance.getDbId());
    assertThat(instancesRepository.get(instance.getDbId()).getDeletedDate(), notNullValue());
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstanceUtils.buildInstance(org.odk.collect.formstest.InstanceUtils.buildInstance) Test(org.junit.Test)

Example 37 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstancesRepositoryTest method save_whenLastStatusChangeDateIsNull_setsIt.

@Test
public void save_whenLastStatusChangeDateIsNull_setsIt() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).lastStatusChangeDate(null).build());
    assertThat(instancesRepository.get(instance.getDbId()).getLastStatusChangeDate(), is(notNullValue()));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 38 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InMemInstancesRepository method getAllByStatus.

@Override
public List<Instance> getAllByStatus(String... status) {
    List<String> statuses = Arrays.asList(status);
    List<Instance> result = new ArrayList<>();
    for (Instance instance : instances) {
        if (statuses.contains(instance.getStatus())) {
            result.add(instance);
        }
    }
    return result;
}
Also used : Instance(org.odk.collect.forms.instances.Instance) ArrayList(java.util.ArrayList)

Example 39 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InMemInstancesRepository method deleteWithLogging.

@Override
public void deleteWithLogging(Long id) {
    Instance instance = new Instance.Builder(get(id)).geometry(null).geometryType(null).deletedDate(clock.get()).build();
    instances.removeIf(i -> i.getDbId().equals(id));
    instances.add(instance);
    deleteInstanceFiles(instance);
}
Also used : Instance(org.odk.collect.forms.instances.Instance)

Example 40 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InMemInstancesRepository method save.

@Override
public Instance save(Instance instance) {
    if (instance.getStatus() == null) {
        instance = new Instance.Builder(instance).status(Instance.STATUS_INCOMPLETE).build();
    }
    Long id = instance.getDbId();
    if (id == null) {
        if (instance.getLastStatusChangeDate() == null) {
            instance = new Instance.Builder(instance).lastStatusChangeDate(clock.get()).build();
        }
        Instance newInstance = new Instance.Builder(instance).dbId(idCounter++).build();
        instances.add(newInstance);
        return newInstance;
    } else {
        if (instance.getDeletedDate() == null) {
            instance = new Instance.Builder(instance).lastStatusChangeDate(clock.get()).build();
        }
        instances.removeIf(i -> i.getDbId().equals(id));
        instances.add(instance);
        return instance;
    }
}
Also used : Instance(org.odk.collect.forms.instances.Instance)

Aggregations

Instance (org.odk.collect.forms.instances.Instance)62 Test (org.junit.Test)28 InstancesRepository (org.odk.collect.forms.instances.InstancesRepository)23 InstancesRepositoryProvider (org.odk.collect.android.utilities.InstancesRepositoryProvider)10 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)9 File (java.io.File)7 DatabaseObjectMapper.getValuesFromInstance (org.odk.collect.android.database.DatabaseObjectMapper.getValuesFromInstance)7 Uri (android.net.Uri)6 Form (org.odk.collect.forms.Form)6 InstanceUtils.buildInstance (org.odk.collect.formstest.InstanceUtils.buildInstance)6 Pair (android.util.Pair)5 ArrayList (java.util.ArrayList)5 FormsRepositoryProvider (org.odk.collect.android.utilities.FormsRepositoryProvider)5 Date (java.util.Date)4 FormController (org.odk.collect.android.javarosawrapper.FormController)4 MapPoint (org.odk.collect.geo.maps.MapPoint)4 ContentValues (android.content.ContentValues)3 Intent (android.content.Intent)3 Cursor (android.database.Cursor)3 AsyncTask (android.os.AsyncTask)2