use of org.odk.collect.forms.FormsRepository 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