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());
}
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()));
}
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;
}
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);
}
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;
}
}
Aggregations