branch develop updated (2bb9489 -> 9c7510b)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-csv. See https://gitlab.nuiton.org/nuiton/nuiton-csv.git from 2bb9489 Update versions : nuitonpom 10.5 ; nuiton-i18n 3.6.3 ; nuiton-utils 3.0 ; commons-lang3 3.7 ; commons-io 2.6 ; guava 25.0 new 2e7527b Add 'rawContent' support in ImportRow new c3dd139 Downgrade Guava and nuiton-utils to avoid Java8 requirement new 9c7510b Add GitlabCI configuration The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 9c7510bde5e9b0df8ee7927c26bff9e5f1a10527 Author: Arnaud Thimel <thimel@codelutin.com> Date: Tue May 1 16:31:24 2018 +0200 Add GitlabCI configuration commit c3dd1398677256807ab16cb033a1be3d823ef4c4 Author: Arnaud Thimel <thimel@codelutin.com> Date: Tue May 1 16:29:56 2018 +0200 Downgrade Guava and nuiton-utils to avoid Java8 requirement commit 2e7527b919048756b0021c97a218874d9d00cadb Author: Arnaud Thimel <thimel@codelutin.com> Date: Tue May 1 16:05:57 2018 +0200 Add 'rawContent' support in ImportRow Summary of changes: .gitlab-ci.yml | 30 ++++++++ pom.xml | 26 ++++++- src/main/java/org/nuiton/csv/Import2.java | 11 ++- src/main/java/org/nuiton/csv/ImportConf.java | 18 +++++ src/main/java/org/nuiton/csv/ImportRow.java | 28 +++++++ src/test/java/org/nuiton/csv/Import2Test.java | 107 +++++++++++++++++++------- 6 files changed, 188 insertions(+), 32 deletions(-) create mode 100644 .gitlab-ci.yml -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-csv. See https://gitlab.nuiton.org/nuiton/nuiton-csv.git commit 2e7527b919048756b0021c97a218874d9d00cadb Author: Arnaud Thimel <thimel@codelutin.com> Date: Tue May 1 16:05:57 2018 +0200 Add 'rawContent' support in ImportRow --- src/main/java/org/nuiton/csv/Import2.java | 11 ++- src/main/java/org/nuiton/csv/ImportConf.java | 18 +++++ src/main/java/org/nuiton/csv/ImportRow.java | 28 +++++++ src/test/java/org/nuiton/csv/Import2Test.java | 107 +++++++++++++++++++------- 4 files changed, 134 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/nuiton/csv/Import2.java b/src/main/java/org/nuiton/csv/Import2.java index 9e90202..2a11e3a 100644 --- a/src/main/java/org/nuiton/csv/Import2.java +++ b/src/main/java/org/nuiton/csv/Import2.java @@ -310,9 +310,10 @@ public class Import2<E> implements Iterable<ImportRow<E>>, Closeable { } this.conf = conf; this.model = model; - reader = new CsvReader(inputStream, model.getSeparator(), Charset.forName("UTF-8")); - reader.setTrimWhitespace(true); + this.reader = new CsvReader(inputStream, model.getSeparator(), Charset.forName("UTF-8")); + this.reader.setTrimWhitespace(true); this.reader.setSafetySwitch(conf.isSafetySwitch()); + this.reader.setCaptureRawRecord(conf.isCaptureRawRecord()); } protected Import2(ImportConf conf, ImportModel<E> model, Reader reader) { @@ -324,6 +325,7 @@ public class Import2<E> implements Iterable<ImportRow<E>>, Closeable { this.reader = new CsvReader(reader, model.getSeparator()); this.reader.setTrimWhitespace(true); this.reader.setSafetySwitch(conf.isSafetySwitch()); + this.reader.setCaptureRawRecord(conf.isCaptureRawRecord()); } /** @@ -386,6 +388,11 @@ public class Import2<E> implements Iterable<ImportRow<E>>, Closeable { boolean strictMode = conf.isStrictMode(); + if (conf.isCaptureRawRecord()) { + String rawRecord = reader.getRawRecord(); + row.setRawRecord(rawRecord); + } + for (ImportableColumn<E, Object> field : columns) { // read value from csv cell diff --git a/src/main/java/org/nuiton/csv/ImportConf.java b/src/main/java/org/nuiton/csv/ImportConf.java index f321c28..86553b4 100644 --- a/src/main/java/org/nuiton/csv/ImportConf.java +++ b/src/main/java/org/nuiton/csv/ImportConf.java @@ -67,6 +67,15 @@ public class ImportConf { */ protected boolean cloneImportRow = false; + /** + * Flag to ask for raw record in result. + * <p> + * By default, raw record are not included. + * + * @since 3.0 + */ + protected boolean captureRawRecord = false; + public boolean isSafetySwitch() { return safetySwitch; } @@ -98,4 +107,13 @@ public class ImportConf { public void setCloneImportRow(boolean cloneImportRow) { this.cloneImportRow = cloneImportRow; } + + public boolean isCaptureRawRecord() { + return captureRawRecord; + } + + public void setCaptureRawRecord(boolean captureRawRecord) { + this.captureRawRecord = captureRawRecord; + } + } diff --git a/src/main/java/org/nuiton/csv/ImportRow.java b/src/main/java/org/nuiton/csv/ImportRow.java index 07db7f8..2552dab 100644 --- a/src/main/java/org/nuiton/csv/ImportRow.java +++ b/src/main/java/org/nuiton/csv/ImportRow.java @@ -22,6 +22,8 @@ package org.nuiton.csv; * #L% */ +import com.google.common.base.Optional; +import com.google.common.base.Strings; import com.google.common.collect.Sets; import org.apache.commons.collections4.CollectionUtils; @@ -49,11 +51,18 @@ public class ImportRow<E> { protected boolean next; + /** + * The source data. May be empty if {@link ImportConf#captureRawRecord} is false. + * When project will be Java8 based, use Java8 Optional + */ + protected Optional<String> rawRecord = Optional.absent(); + public ImportRow(ImportRow<E> row) { this.lineNumber = row.getLineNumber(); this.bean = row.getBean(); this.errors = Sets.newHashSet(row.getErrors()); this.setNext(row.hasNext()); + this.rawRecord = row.getRawRecord(); } public ImportRow() { @@ -98,6 +107,25 @@ public class ImportRow<E> { this.bean = bean; lineNumber++; errors = null; + rawRecord = Optional.absent(); + } + + public Optional<String> getRawRecord() { + return rawRecord; } + public void setRawRecord(String rawRecord) { + this.rawRecord = Optional.fromNullable(Strings.emptyToNull(rawRecord)); + } + + @Override + public String toString() { + return "ImportRow{" + + "lineNumber=" + lineNumber + + ", bean=" + bean + + ", errors=" + errors + + ", next=" + next + + ", rawRecord=" + rawRecord + + '}'; + } } diff --git a/src/test/java/org/nuiton/csv/Import2Test.java b/src/test/java/org/nuiton/csv/Import2Test.java index 009bf5a..a153928 100644 --- a/src/test/java/org/nuiton/csv/Import2Test.java +++ b/src/test/java/org/nuiton/csv/Import2Test.java @@ -22,6 +22,8 @@ package org.nuiton.csv; * #L% */ +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -123,41 +125,90 @@ public class Import2Test { assertRowEquals(rows.get(2), DateUtil.createDate(7, 12, 2011), null, "3ème ligne", RowBeanEnum.TWO); } - protected List<RowBean> importContent(ImportConf conf, ImportModel<RowBean> model, + @Test + public void testCaptureRawRecord() { + String row1 = "2011-12-05;18;\"1ère ligne\";ZERO"; + String row2 = "2011-12-06;19;\"2ème ligne\";ONE"; + String row3 = "2011-12-07;21;\"3ème ligne\";TWO"; + String row4 = ";;"; + String content = "DATE;NUMBER;TITLE;ROWBEANENUM\n" + Joiner.on("\n").join(row1, row2, row3, row4); + + ImportConf conf = new ImportConf(); + conf.setCaptureRawRecord(true); + conf.setCloneImportRow(true); + + try ( + StringReader reader = new StringReader(content); + Import2<RowBean> rowImport = Import2.newImport(conf, importModel, reader) + ) { + ImmutableList<ImportRow<RowBean>> rows = ImmutableList.copyOf(rowImport); + + Assert.assertEquals(4, rows.size()); + Assert.assertTrue(rows.get(0).getRawRecord().isPresent()); + Assert.assertEquals(row1, rows.get(0).getRawRecord().get()); + Assert.assertTrue(rows.get(1).getRawRecord().isPresent()); + Assert.assertEquals(row2, rows.get(1).getRawRecord().get()); + Assert.assertTrue(rows.get(2).getRawRecord().isPresent()); + Assert.assertEquals(row3, rows.get(2).getRawRecord().get()); + Assert.assertTrue(rows.get(3).getRawRecord().isPresent()); + Assert.assertEquals(row4, rows.get(3).getRawRecord().get()); + } + } + + @Test + public void testDontCaptureRawRecord() { + String row1 = "2011-12-05;18;\"1ère ligne\";ZERO"; + String row2 = "2011-12-06;19;\"2ème ligne\";ONE"; + String row3 = "2011-12-07;21;\"3ème ligne\";TWO"; + String row4 = ";;"; + String content = "DATE;NUMBER;TITLE;ROWBEANENUM\n" + Joiner.on("\n").join(row1, row2, row3, row4); + + ImportConf conf = new ImportConf(); + conf.setCaptureRawRecord(false); + conf.setCloneImportRow(true); + + + try ( + StringReader reader = new StringReader(content); + Import2<RowBean> rowImport = Import2.newImport(conf, importModel, reader) + ) { + ImmutableList<ImportRow<RowBean>> rows = ImmutableList.copyOf(rowImport); + + Assert.assertEquals(4, rows.size()); + Assert.assertFalse(rows.get(0).getRawRecord().isPresent()); + Assert.assertFalse(rows.get(1).getRawRecord().isPresent()); + Assert.assertFalse(rows.get(2).getRawRecord().isPresent()); + Assert.assertFalse(rows.get(3).getRawRecord().isPresent()); + } + } + + protected List<RowBean> importContent(ImportConf conf, + ImportModel<RowBean> model, String content) throws IOException { - Reader reader = new StringReader(content); - try { - Import2<RowBean> rowImport = Import2.newImport(conf, model, reader); - try { - List<RowBean> result = new ArrayList<RowBean>(); - for (ImportRow<RowBean> row : rowImport) { - result.add(row.getBean()); - } - return result; - } finally { - rowImport.close(); + + try ( + Reader reader = new StringReader(content); + Import2<RowBean> rowImport = Import2.newImport(conf, model, reader) + ){ + List<RowBean> result = new ArrayList<RowBean>(); + for (ImportRow<RowBean> row : rowImport) { + result.add(row.getBean()); } - } finally { - reader.close(); - } + return result; + } } protected List<RowBean> importContent(ImportModel<RowBean> model, String content) throws IOException { - Reader reader = new StringReader(content); - try { - Import2<RowBean> rowImport = Import2.newImport(model, reader); - try { - List<RowBean> result = new ArrayList<RowBean>(); - for (ImportRow<RowBean> row : rowImport) { - result.add(row.getBean()); - } - return result; - } finally { - rowImport.close(); + try ( + Reader reader = new StringReader(content); + Import2<RowBean> rowImport = Import2.newImport(model, reader) + ){ + List<RowBean> result = new ArrayList<RowBean>(); + for (ImportRow<RowBean> row : rowImport) { + result.add(row.getBean()); } - } finally { - reader.close(); + return result; } } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-csv. See https://gitlab.nuiton.org/nuiton/nuiton-csv.git commit c3dd1398677256807ab16cb033a1be3d823ef4c4 Author: Arnaud Thimel <thimel@codelutin.com> Date: Tue May 1 16:29:56 2018 +0200 Downgrade Guava and nuiton-utils to avoid Java8 requirement --- pom.xml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4a11f31..c5b655d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,26 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Nuiton CSV + %% + Copyright (C) 2013 - 2018 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -80,7 +102,7 @@ <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> - <version>3.0</version> + <version>3.0-rc-18</version> <!-- From version 3.0+, nuiton-utils requires Java8 --> </dependency> <dependency> @@ -128,7 +150,7 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>25.0-jre</version> + <version>20.0</version> <!-- From version 21+, Guava requires Java8 --> </dependency> <dependency> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-csv. See https://gitlab.nuiton.org/nuiton/nuiton-csv.git commit 9c7510bde5e9b0df8ee7927c26bff9e5f1a10527 Author: Arnaud Thimel <thimel@codelutin.com> Date: Tue May 1 16:31:24 2018 +0200 Add GitlabCI configuration --- .gitlab-ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..cc38cee --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +image: registry.nuiton.org/codelutin/dockerfiles:maven-release + +stages: +- build +- deploy +- reporting + +build: + stage: build + script: + - mvn install + +snapshot: + stage: deploy + only: + - develop + script: + - mvn deploy -Prelease-profile + +pages: + stage: reporting + only: + - develop + artifacts: + paths: + - public + script: + - mvn install && mvn site -Preporting + - mv target/site public + -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm