Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #836 from ggalmazor/issue_831_ignore_failing_forms…
Browse files Browse the repository at this point in the history
…_on_startup

Issue 831 ignore failing forms on startup
  • Loading branch information
ggalmazor authored Nov 20, 2019
2 parents e0ff3c2 + ec400e2 commit 8f78fd7
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import org.opendatakit.briefcase.export.XmlElement;
import org.opendatakit.briefcase.reused.BriefcaseException;
import org.opendatakit.briefcase.reused.LegacyPrefs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileSystemFormMetadataAdapter implements FormMetadataPort {
private static final Logger log = LoggerFactory.getLogger(FileSystemFormMetadataAdapter.class);
private static final ObjectMapper MAPPER = new ObjectMapper().findAndRegisterModules();
private final Map<FormKey, FormMetadata> store = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -53,7 +56,7 @@ public FormMetadataPort syncWithFilesAt(Path storageRoot) {

// select XML files that look like forms by parsing them
// and looking for key parts that all forms must have
Stream<Path> formFiles = candidateFormFiles.filter(path -> isAForm(XmlElement.from(path)));
Stream<Path> formFiles = candidateFormFiles.filter(this::isAForm);

// Parse existing metadata.json files or build new FormMetadata from form files
// At this point, we collect the stream to avoid problems coming
Expand All @@ -78,7 +81,14 @@ public FormMetadataPort syncWithFilesAt(Path storageRoot) {
return this;
}

private boolean isAForm(XmlElement root) {
private boolean isAForm(Path path) {
XmlElement root;
try {
root = XmlElement.from(path);
} catch (BriefcaseException e) {
log.error("Couldn't parse form at {}", path, e);
return false;
}
return root.getName().equals("html")
&& root.findElements("head", "title").size() == 1
&& root.findElements("head", "model", "instance").size() >= 1
Expand Down

0 comments on commit 8f78fd7

Please sign in to comment.