Skip to content

Commit

Permalink
Set multiplicity for nodes from CSV dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Jun 28, 2019
1 parent 1ddbbd5 commit 203241e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public static TreeElement parse(String instanceId, String path) throws IOExcepti

if (csvLine != null) {
String[] fieldNames = csvLine.split(",");
int multiplicity = 0;

while ((csvLine = br.readLine()) != null) {
TreeElement item = new TreeElement("item", 0);
TreeElement item = new TreeElement("item", multiplicity);
String[] data = csvLine.split(",");
for (int i = 0; i < fieldNames.length; ++i) {
TreeElement field = new TreeElement(fieldNames[i], 0);
Expand All @@ -30,6 +31,7 @@ public static TreeElement parse(String instanceId, String path) throws IOExcepti
}

root.addChild(item);
multiplicity++;
}
}
return root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public void formWithExternalSecondaryCSVInstance_ShouldParseWithoutError() throw
mapFileToResourcePath(formName);
FormDef formDef = parse(formName);
assertEquals("External Secondary Instance CSV", formDef.getTitle());

// Confirm that items are actually made available to the XPath parser
TreeReference treeReference = ((XPathPathExpr) parseXPath("instance('external-csv')/root/item")).getReference();
EvaluationContext evaluationContext = formDef.getEvaluationContext();
List<TreeReference> treeReferences = evaluationContext.expandReference(treeReference);
assertThat(treeReferences.size(), is(6));
}

// ODK Collect has CSV-parsing features that bypass XPath and use databases. This test verifies that if a
Expand Down

0 comments on commit 203241e

Please sign in to comment.