From b74d9b4af5a3d13cf118ff68630c402d870f9b7f Mon Sep 17 00:00:00 2001 From: Dave Briccetti Date: Tue, 30 Mar 2021 16:21:35 -0700 Subject: [PATCH 1/4] Create a test to reveal parsing defects --- .../instance/CsvExternalInstanceTest.java | 24 +++++++++++++++++++ .../core/model/instance/non_trivial.csv | 13 ++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java create mode 100644 src/test/resources/org/javarosa/core/model/instance/non_trivial.csv diff --git a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java new file mode 100644 index 000000000..8a735d73c --- /dev/null +++ b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java @@ -0,0 +1,24 @@ +package org.javarosa.core.model.instance; + +import org.junit.Test; + +import java.io.IOException; + +import static org.javarosa.test.utils.ResourcePathHelper.r; +import static org.junit.Assert.assertEquals; + +public class CsvExternalInstanceTest { + + @Test + public void heading_has_no_extra_quotes() throws IOException { + TreeElement root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); + assertEquals("label", root.getChildAt(0).getChildAt(0).getName()); + } + + @Test + public void value_has_no_extra_quotes() throws IOException { + TreeElement root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); + assertEquals("A", root.getChildAt(0).getChildAt(0).getValue().getValue()); + } + +} diff --git a/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv b/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv new file mode 100644 index 000000000..97faf68d8 --- /dev/null +++ b/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv @@ -0,0 +1,13 @@ +"label","name","first" +"A","a", +B,b, +C,c, +AA,aa,a +AB,ab,a +AC,ac,a +BA,ba,b +BB,bb,b +BC,bc,b +CA,ca,c +CB,cb,c +CC,cc,c From fae6c7c13d2deb0a935db653b74567495775af1b Mon Sep 17 00:00:00 2001 From: Dave Briccetti Date: Mon, 5 Apr 2021 15:56:00 -0700 Subject: [PATCH 2/4] Replace hand-written CSV parser with Apache Commons CSV --- build.gradle | 2 + javarosa-android-api-level-checker.zip | Bin 250137 -> 143280 bytes pom.xml | 5 +++ .../model/instance/CsvExternalInstance.java | 39 ++++++++---------- .../instance/CsvExternalInstanceTest.java | 31 ++++++++++---- .../core/model/instance/non_trivial.csv | 11 ++--- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/build.gradle b/build.gradle index a441c8849..f4f5ee6dd 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,8 @@ dependencies { // Be sure to update dependencies in pom.xml to match implementation 'joda-time:joda-time:2.10.10' implementation 'org.slf4j:slf4j-api:1.7.31' + // Upgrade to version higher than 1.4 when Collect minSDK >= 26 + implementation 'org.apache.commons:commons-csv:1.4' compileOnly 'net.sf.kxml:kxml2:2.3.0' testImplementation 'ch.qos.logback:logback-classic:1.2.3' testImplementation 'junit:junit:4.13.2' diff --git a/javarosa-android-api-level-checker.zip b/javarosa-android-api-level-checker.zip index 4ed2c00b89364e50252e6daad54da2f61c10b963..aa536ec70124d7869d5c8db9df610d4343857862 100644 GIT binary patch delta 3808 zcmZ`+3s@6Z7M{rkl8_LRfd~m0f)p?UQEY|92ZD&QRlBjQ0Fm5PeBYVXV>GXo-ge9SrLzyCS+oO92e z*|E>rd_%HjpxwGPL*rqDShID!k$KKf_ap7L(#kf;bZAm2Atmyctj7u(X^9kdk=&Xg zwJC;J!umtn6NHk`6Y(a~z`1E3FPUdtxIBK|lKE36I}zf0tB1zhIN(OR;0(vU8{Uhl zGskt^uzY%X+f1KDtIXA{cOKM-Zx3D`m7O;(cQAG5^uF=Sj@W-ApV@EWtVL@3$YkFP z(P!dY*;^jh&fZfoG+TfFKw4m;_lp^e@2}W2Xjh|ZLRCvc?wnJdu}2*zJ)7E~x&7Z| zRAStBzHz}v`pTY1emSvf{rT%RcLbezlQH4zup<{gX!eX*o>-co-ZCh6e-!0>@lwu{ zf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zQ}z;Spq}9GF8n326`?s-Nge;i)r~Wd#u2&V_84b)?kuP4I)}*>lCBK7dEIi5W{=q{ z!GAcQrPDMLoX{F{zf$6E(|qn4wYjfQzQ=T`>j+HJZ?^<%{h+avi&mfxOwIC;N1xFE}aWe^)5O JWK~Ou^dCT3`nLc8 diff --git a/pom.xml b/pom.xml index f560b117e..c43fdab75 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,11 @@ compile + org.apache.commons + commons-csv + 1.4 + + org.slf4j slf4j-api 1.7.31 diff --git a/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java b/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java index daccee198..c3194d6c2 100644 --- a/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java +++ b/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java @@ -1,36 +1,33 @@ package org.javarosa.core.model.instance; -import java.io.BufferedReader; -import java.io.FileReader; +import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; import org.javarosa.core.model.data.UncastData; public class CsvExternalInstance { public static TreeElement parse(String instanceId, String path) throws IOException { - TreeElement root = new TreeElement("root", 0); + final TreeElement root = new TreeElement("root", 0); root.setInstanceName(instanceId); - try (BufferedReader br = new BufferedReader(new FileReader(path))) { - String csvLine = br.readLine(); + final CSVParser csvParser = CSVParser.parse(new File(path), StandardCharsets.UTF_8, CSVFormat.DEFAULT.withFirstRecordAsHeader()); + final String[] fieldNames = csvParser.getHeaderMap().keySet().toArray(new String[0]); + int multiplicity = 0; - if (csvLine != null) { - String[] fieldNames = csvLine.split(","); - int multiplicity = 0; + for (CSVRecord csvRecord : csvParser.getRecords()) { + TreeElement item = new TreeElement("item", multiplicity); - while ((csvLine = br.readLine()) != null) { - 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); - field.setValue(new UncastData(i < data.length ? data[i] : "")); - - item.addChild(field); - } - - root.addChild(item); - multiplicity++; - } + for (int i = 0; i < fieldNames.length; ++i) { + TreeElement field = new TreeElement(fieldNames[i], 0); + field.setValue(new UncastData(i < csvRecord.size() ? csvRecord.get(i) : "")); + item.addChild(field); } + + root.addChild(item); + multiplicity++; } return root; diff --git a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java index 8a735d73c..7f1a7e3cf 100644 --- a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java +++ b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java @@ -1,24 +1,39 @@ package org.javarosa.core.model.instance; -import org.junit.Test; - -import java.io.IOException; - import static org.javarosa.test.utils.ResourcePathHelper.r; import static org.junit.Assert.assertEquals; +import java.io.IOException; +import org.junit.Before; +import org.junit.Test; + public class CsvExternalInstanceTest { + private TreeElement root; + + @Before + public void setUp() throws IOException { + root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); + } @Test - public void heading_has_no_extra_quotes() throws IOException { - TreeElement root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); + public void heading_has_no_extra_quotes() { assertEquals("label", root.getChildAt(0).getChildAt(0).getName()); } @Test - public void value_has_no_extra_quotes() throws IOException { - TreeElement root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); + public void value_has_no_extra_quotes() { assertEquals("A", root.getChildAt(0).getChildAt(0).getValue().getValue()); } + @Test + public void quoted_string_with_comma() { + assertEquals("121 Main St, NE", root.getChildAt(6).getChildAt(0).getValue().getValue()); + } + + @Test + public void missing_fields_replaced_with_spaces() { + for (int fieldIndex = 1; fieldIndex < 2; fieldIndex++) { + assertEquals("", root.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); + } + } } diff --git a/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv b/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv index 97faf68d8..3ec94c7b6 100644 --- a/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv +++ b/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv @@ -1,13 +1,8 @@ "label","name","first" "A","a", B,b, -C,c, +C,c AA,aa,a AB,ab,a -AC,ac,a -BA,ba,b -BB,bb,b -BC,bc,b -CA,ca,c -CB,cb,c -CC,cc,c +AC +"121 Main St, NE", main, m From d17662854964e409109501040349273f7a4dd1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Martin?= Date: Mon, 13 Sep 2021 12:01:24 -0700 Subject: [PATCH 3/4] Support semicolon as delimiter Excel export format for CSV is based on the document locale. For some locales such as French/France, semicolon is used as the delimiter. --- .../model/instance/CsvExternalInstance.java | 19 ++++++++++++++- .../instance/CsvExternalInstanceTest.java | 24 ++++++++++++++----- ...v => external-secondary-comma-complex.csv} | 3 ++- .../external-secondary-semicolon-complex.csv | 9 +++++++ 4 files changed, 47 insertions(+), 8 deletions(-) rename src/test/resources/org/javarosa/core/model/instance/{non_trivial.csv => external-secondary-comma-complex.csv} (54%) create mode 100644 src/test/resources/org/javarosa/core/model/instance/external-secondary-semicolon-complex.csv diff --git a/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java b/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java index c3194d6c2..242130d96 100644 --- a/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java +++ b/src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java @@ -1,6 +1,8 @@ package org.javarosa.core.model.instance; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.apache.commons.csv.CSVFormat; @@ -13,7 +15,10 @@ public static TreeElement parse(String instanceId, String path) throws IOExcepti final TreeElement root = new TreeElement("root", 0); root.setInstanceName(instanceId); - final CSVParser csvParser = CSVParser.parse(new File(path), StandardCharsets.UTF_8, CSVFormat.DEFAULT.withFirstRecordAsHeader()); + final CSVFormat csvFormat = CSVFormat.DEFAULT + .withDelimiter(getDelimiter(path)) + .withFirstRecordAsHeader(); + final CSVParser csvParser = CSVParser.parse(new File(path), StandardCharsets.UTF_8, csvFormat); final String[] fieldNames = csvParser.getHeaderMap().keySet().toArray(new String[0]); int multiplicity = 0; @@ -32,4 +37,16 @@ public static TreeElement parse(String instanceId, String path) throws IOExcepti return root; } + + private static char getDelimiter(String path) throws IOException { + char delimiter = ','; + try (BufferedReader reader = new BufferedReader(new FileReader(path))) { + String header = reader.readLine(); + + if (header.contains(";")) { + delimiter = ';'; + } + } + return delimiter; + } } diff --git a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java index 7f1a7e3cf..3e13bd362 100644 --- a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java +++ b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java @@ -8,32 +8,44 @@ import org.junit.Test; public class CsvExternalInstanceTest { - private TreeElement root; + private TreeElement commaSeparated; + private TreeElement tabSeparated; @Before public void setUp() throws IOException { - root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); + commaSeparated = CsvExternalInstance.parse("id", r("external-secondary-comma-complex.csv").toString()); + tabSeparated = CsvExternalInstance.parse("id", r("external-secondary-semicolon-complex.csv").toString()); } @Test public void heading_has_no_extra_quotes() { - assertEquals("label", root.getChildAt(0).getChildAt(0).getName()); + assertEquals("label", commaSeparated.getChildAt(0).getChildAt(0).getName()); + assertEquals("label", tabSeparated.getChildAt(0).getChildAt(0).getName()); } @Test public void value_has_no_extra_quotes() { - assertEquals("A", root.getChildAt(0).getChildAt(0).getValue().getValue()); + assertEquals("A", commaSeparated.getChildAt(0).getChildAt(0).getValue().getValue()); + assertEquals("A", tabSeparated.getChildAt(0).getChildAt(0).getValue().getValue()); } @Test public void quoted_string_with_comma() { - assertEquals("121 Main St, NE", root.getChildAt(6).getChildAt(0).getValue().getValue()); + assertEquals("121 Main St, NE", commaSeparated.getChildAt(6).getChildAt(0).getValue().getValue()); + assertEquals("121 Main St, NE", tabSeparated.getChildAt(6).getChildAt(0).getValue().getValue()); + } + + @Test + public void quoted_string_with_semicolon() { + assertEquals("text; more text", commaSeparated.getChildAt(7).getChildAt(0).getValue().getValue()); + assertEquals("text; more text", tabSeparated.getChildAt(7).getChildAt(0).getValue().getValue()); } @Test public void missing_fields_replaced_with_spaces() { for (int fieldIndex = 1; fieldIndex < 2; fieldIndex++) { - assertEquals("", root.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); + assertEquals("", commaSeparated.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); + assertEquals("", tabSeparated.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); } } } diff --git a/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv b/src/test/resources/org/javarosa/core/model/instance/external-secondary-comma-complex.csv similarity index 54% rename from src/test/resources/org/javarosa/core/model/instance/non_trivial.csv rename to src/test/resources/org/javarosa/core/model/instance/external-secondary-comma-complex.csv index 3ec94c7b6..20f509bfc 100644 --- a/src/test/resources/org/javarosa/core/model/instance/non_trivial.csv +++ b/src/test/resources/org/javarosa/core/model/instance/external-secondary-comma-complex.csv @@ -5,4 +5,5 @@ C,c AA,aa,a AB,ab,a AC -"121 Main St, NE", main, m +"121 Main St, NE",main,m +"text; more text",foo,bar diff --git a/src/test/resources/org/javarosa/core/model/instance/external-secondary-semicolon-complex.csv b/src/test/resources/org/javarosa/core/model/instance/external-secondary-semicolon-complex.csv new file mode 100644 index 000000000..50bb116d0 --- /dev/null +++ b/src/test/resources/org/javarosa/core/model/instance/external-secondary-semicolon-complex.csv @@ -0,0 +1,9 @@ +"label";"name";"first" +"A";"a"; +B;b; +C;c +AA;aa;a +AB;ab;a +AC +"121 Main St, NE";main;m +"text; more text";foo;bar From 829d1dde55afe5686b7687e141f1d260e11fb69d Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Thu, 16 Sep 2021 10:03:23 +0100 Subject: [PATCH 4/4] Correct field name --- .../model/instance/CsvExternalInstanceTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java index 3e13bd362..e32e339f5 100644 --- a/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java +++ b/src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java @@ -9,43 +9,43 @@ public class CsvExternalInstanceTest { private TreeElement commaSeparated; - private TreeElement tabSeparated; + private TreeElement semiColonSeparated; @Before public void setUp() throws IOException { commaSeparated = CsvExternalInstance.parse("id", r("external-secondary-comma-complex.csv").toString()); - tabSeparated = CsvExternalInstance.parse("id", r("external-secondary-semicolon-complex.csv").toString()); + semiColonSeparated = CsvExternalInstance.parse("id", r("external-secondary-semicolon-complex.csv").toString()); } @Test public void heading_has_no_extra_quotes() { assertEquals("label", commaSeparated.getChildAt(0).getChildAt(0).getName()); - assertEquals("label", tabSeparated.getChildAt(0).getChildAt(0).getName()); + assertEquals("label", semiColonSeparated.getChildAt(0).getChildAt(0).getName()); } @Test public void value_has_no_extra_quotes() { assertEquals("A", commaSeparated.getChildAt(0).getChildAt(0).getValue().getValue()); - assertEquals("A", tabSeparated.getChildAt(0).getChildAt(0).getValue().getValue()); + assertEquals("A", semiColonSeparated.getChildAt(0).getChildAt(0).getValue().getValue()); } @Test public void quoted_string_with_comma() { assertEquals("121 Main St, NE", commaSeparated.getChildAt(6).getChildAt(0).getValue().getValue()); - assertEquals("121 Main St, NE", tabSeparated.getChildAt(6).getChildAt(0).getValue().getValue()); + assertEquals("121 Main St, NE", semiColonSeparated.getChildAt(6).getChildAt(0).getValue().getValue()); } @Test public void quoted_string_with_semicolon() { assertEquals("text; more text", commaSeparated.getChildAt(7).getChildAt(0).getValue().getValue()); - assertEquals("text; more text", tabSeparated.getChildAt(7).getChildAt(0).getValue().getValue()); + assertEquals("text; more text", semiColonSeparated.getChildAt(7).getChildAt(0).getValue().getValue()); } @Test public void missing_fields_replaced_with_spaces() { for (int fieldIndex = 1; fieldIndex < 2; fieldIndex++) { assertEquals("", commaSeparated.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); - assertEquals("", tabSeparated.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); + assertEquals("", semiColonSeparated.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); } } }