use of org.odk.collect.forms.instances.InstancesRepository in project collect by opendatakit.
the class InstancesRepositoryTest method deleteWithLogging_setsDeletedDate.
@Test
public void deleteWithLogging_setsDeletedDate() {
InstancesRepository instancesRepository = buildSubject();
Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
instancesRepository.deleteWithLogging(instance.getDbId());
assertThat(instancesRepository.get(instance.getDbId()).getDeletedDate(), is(notNullValue()));
}
use of org.odk.collect.forms.instances.InstancesRepository in project collect by opendatakit.
the class InstancesRepositoryTest method deleteWithLogging_deletesInstanceDir.
@Test
public void deleteWithLogging_deletesInstanceDir() {
InstancesRepository instancesRepository = buildSubject();
Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
File instanceDir = new File(instance.getInstanceFilePath()).getParentFile();
assertThat(instanceDir.exists(), is(true));
assertThat(instanceDir.isDirectory(), is(true));
instancesRepository.deleteWithLogging(instance.getDbId());
assertThat(instanceDir.exists(), is(false));
}
use of org.odk.collect.forms.instances.InstancesRepository in project collect by opendatakit.
the class InstancesRepositoryTest method getAllByStatus_withOneStatus_returnsMatchingInstances.
@Test
public void getAllByStatus_withOneStatus_returnsMatchingInstances() {
InstancesRepository instancesRepository = buildSubject();
instancesRepository.save(InstanceUtils.buildInstance("incomplete", "1", getInstancesDir()).status(Instance.STATUS_INCOMPLETE).build());
instancesRepository.save(InstanceUtils.buildInstance("incomplete", "1", getInstancesDir()).status(Instance.STATUS_INCOMPLETE).build());
instancesRepository.save(InstanceUtils.buildInstance("complete", "1", getInstancesDir()).status(Instance.STATUS_COMPLETE).build());
instancesRepository.save(InstanceUtils.buildInstance("complete", "1", getInstancesDir()).status(Instance.STATUS_COMPLETE).build());
List<Instance> incomplete = instancesRepository.getAllByStatus(Instance.STATUS_INCOMPLETE);
assertThat(incomplete.size(), is(2));
assertThat(incomplete.get(0).getFormId(), is("incomplete"));
assertThat(incomplete.get(1).getStatus(), is("incomplete"));
// Check corresponding count method is also correct
assertThat(instancesRepository.getCountByStatus(Instance.STATUS_INCOMPLETE), is(2));
}
use of org.odk.collect.forms.instances.InstancesRepository 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.InstancesRepository in project collect by opendatakit.
the class InstanceAutoSender method autoSendInstances.
public boolean autoSendInstances(String projectId) {
FormsRepository formsRepository = formsRepositoryProvider.get(projectId);
InstancesRepository instancesRepository = instancesRepositoryProvider.get(projectId);
Settings generalSettings = settingsProvider.getUnprotectedSettings(projectId);
InstanceSubmitter instanceSubmitter = new InstanceSubmitter(analytics, formsRepository, instancesRepository, googleAccountsManager, googleApiProvider, permissionsProvider, generalSettings);
return changeLockProvider.getInstanceLock(projectId).withLock(acquiredLock -> {
if (acquiredLock) {
try {
List<Instance> toUpload = getInstancesToAutoSend(formsRepository, instancesRepository, generalSettings);
Pair<Boolean, String> results = instanceSubmitter.submitInstances(toUpload);
notifier.onSubmission(results.first, results.second, projectId);
} catch (SubmitException e) {
switch(e.getType()) {
case GOOGLE_ACCOUNT_NOT_SET:
notifier.onSubmission(true, context.getString(R.string.google_set_account), projectId);
break;
case GOOGLE_ACCOUNT_NOT_PERMITTED:
notifier.onSubmission(true, context.getString(R.string.odk_permissions_fail), projectId);
break;
case NOTHING_TO_SUBMIT:
break;
}
}
instancesAppState.update();
return true;
} else {
return false;
}
});
}
Aggregations