You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/02/18 09:33:04 UTC

[2/4] camel git commit: CAMEL-10853: Aligned code. This closes #1474

CAMEL-10853: Aligned code. This closes #1474


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/da54b7c2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/da54b7c2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/da54b7c2

Branch: refs/heads/master
Commit: da54b7c275bd46fd97d59c018734045663ecf3e4
Parents: 11284d3
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Feb 18 10:28:21 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Feb 18 10:28:21 2017 +0100

----------------------------------------------------------------------
 .../camel/model/dataformat/CsvDataFormat.java   | 39 +++------
 .../model/dataformat/CsvDataFormatTest.java     | 89 --------------------
 .../camel-csv/src/main/docs/csv-dataformat.adoc |  7 +-
 .../springboot/CsvDataFormatConfiguration.java  | 36 ++++++++
 4 files changed, 51 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/da54b7c2/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
index 80ca6ea..1c0213b 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
@@ -17,7 +17,6 @@
 package org.apache.camel.model.dataformat;
 
 import java.util.List;
-import java.util.stream.Stream;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
@@ -171,17 +170,16 @@ public class CsvDataFormat extends DataFormatDefinition {
         if (quoteMode != null) {
             setProperty(camelContext, dataFormat, "quoteMode", quoteMode);
         }
-        Stream.of("trim", "ignoreHeaderCase", "trailingDelimiter")
-            .forEach(item -> {
-                try {
-                    setProperty(camelContext, dataFormat, item,
-                    CsvDataFormat.class.getDeclaredField(item).get(this));
-                } catch (Exception e) {
-                    // Not expected to happen
-                    throw new AssertionError(e);
-                }
-            });
-        
+        if (trim != null) {
+            setProperty(camelContext, dataFormat, "trim", trim);
+        }
+        if (ignoreHeaderCase != null) {
+            setProperty(camelContext, dataFormat, "ignoreHeaderCase", ignoreHeaderCase);
+        }
+        if (trailingDelimiter != null) {
+            setProperty(camelContext, dataFormat, "trailingDelimiter", trailingDelimiter);
+        }
+
         // Unmarshall options
         if (lazyLoad != null) {
             setProperty(camelContext, dataFormat, "lazyLoad", lazyLoad);
@@ -459,12 +457,6 @@ public class CsvDataFormat extends DataFormatDefinition {
 
     /**
      * Sets whether or not to trim leading and trailing blanks.
-     * <p>
-     * If {@code null} then the default value of the format used.
-     * </p>
-     * 
-     * @param trim whether or not to trim leading and trailing blanks.
-     *            <code>null</code> value allowed.
      */
     public void setTrim(Boolean trim) {
         this.trim = trim;
@@ -476,12 +468,6 @@ public class CsvDataFormat extends DataFormatDefinition {
     
     /**
      * Sets whether or not to ignore case when accessing header names.
-     * <p>
-     * If {@code null} then the default value of the format used.
-     * </p>
-     * 
-     * @param ignoreHeaderCase whether or not to ignore case when accessing header names.
-     *            <code>null</code> value allowed.
      */
     public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) {
         this.ignoreHeaderCase = ignoreHeaderCase;
@@ -493,11 +479,6 @@ public class CsvDataFormat extends DataFormatDefinition {
     
     /**
      * Sets whether or not to add a trailing delimiter.
-     * <p>
-     * If {@code null} then the default value of the format used.
-     * </p>
-     * 
-     * @param trailingDelimiter whether or not to add a trailing delimiter.
      */
     public void setTrailingDelimiter(Boolean trailingDelimiter) {
         this.trailingDelimiter = trailingDelimiter;

http://git-wip-us.apache.org/repos/asf/camel/blob/da54b7c2/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java b/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java
deleted file mode 100644
index 6831b67..0000000
--- a/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.model.dataformat;
-
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.BitSet;
-
-import javax.xml.bind.annotation.XmlAttribute;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.spi.DataFormat;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test cases for corresponding class {@link CsvDataFormat}.
- */
-public class CsvDataFormatTest {
-
-    @Test
-    public void testConfigureDataFormatDataFormatCamelContext() {
-        CsvDataFormat csvDataFormat = new CsvDataFormat();
-        csvDataFormat.setIgnoreHeaderCase(true);
-        csvDataFormat.setTrim(true);
-        csvDataFormat.setTrailingDelimiter(true);
-        MyDataFormat dataFormat = new MyDataFormat();
-        DefaultCamelContext camelContext = new DefaultCamelContext();
-        csvDataFormat.configureDataFormat(dataFormat, camelContext);
-        assertEquals(3, dataFormat.bitSet.cardinality());
-        csvDataFormat.setIgnoreHeaderCase(false);
-        csvDataFormat.setTrim(false);
-        csvDataFormat.setTrailingDelimiter(false);
-        csvDataFormat.configureDataFormat(dataFormat, camelContext);
-        assertEquals(dataFormat.bitSet.cardinality(), 0);
-    }
-
-    //
-    // Helper classes
-    //
-
-    static final class MyDataFormat implements DataFormat {
-
-        final BitSet bitSet = new BitSet();
-
-        MyDataFormat() {
-        }
-
-        public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) {
-            bitSet.set(0, ignoreHeaderCase);
-        }
-
-        public void setTrim(Boolean trim) {
-            bitSet.set(2, trim);
-        }
-
-        public void setTrailingDelimiter(Boolean trailingDelimiter) {
-            bitSet.set(3, trailingDelimiter);
-        }
-
-        @Override
-        public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
-            throw new UnsupportedOperationException();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/da54b7c2/components/camel-csv/src/main/docs/csv-dataformat.adoc
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/main/docs/csv-dataformat.adoc b/components/camel-csv/src/main/docs/csv-dataformat.adoc
index d17e1d2..454880f 100644
--- a/components/camel-csv/src/main/docs/csv-dataformat.adoc
+++ b/components/camel-csv/src/main/docs/csv-dataformat.adoc
@@ -11,7 +11,7 @@ exported/imported by Excel.
 ### Options
 
 // dataformat options: START
-The CSV dataformat supports 24 options which are listed below.
+The CSV dataformat supports 27 options which are listed below.
 
 
 
@@ -39,6 +39,9 @@ The CSV dataformat supports 24 options which are listed below.
 | recordSeparator |  | String | Sets the record separator (aka new line) which by default is \r\n (CRLF)
 | skipHeaderRecord | false | Boolean | Whether to skip the header record in the output
 | quoteMode |  | String | Sets the quote mode
+| ignoreHeaderCase | false | Boolean | Sets whether or not to ignore case when accessing header names.
+| trim | false | Boolean | Sets whether or not to trim leading and trailing blanks.
+| trailingDelimiter | false | Boolean | Sets whether or not to add a trailing delimiter.
 | lazyLoad | false | Boolean | Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one.
 | useMaps | false | Boolean | Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected).
 | recordConverterRef |  | String | Refers to a custom CsvRecordConverter to lookup from the registry to use.
@@ -362,4 +365,4 @@ link:download.html[the download page for the latest versions]).
   <artifactId>camel-csv</artifactId>
   <version>x.x.x</version>
 </dependency>
--------------------------------------
\ No newline at end of file
+-------------------------------------

http://git-wip-us.apache.org/repos/asf/camel/blob/da54b7c2/platforms/spring-boot/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java b/platforms/spring-boot/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
index e07831e..bf5f8c4 100644
--- a/platforms/spring-boot/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
@@ -109,6 +109,18 @@ public class CsvDataFormatConfiguration {
      */
     private String quoteMode;
     /**
+     * Sets whether or not to ignore case when accessing header names.
+     */
+    private Boolean ignoreHeaderCase = false;
+    /**
+     * Sets whether or not to trim leading and trailing blanks.
+     */
+    private Boolean trim = false;
+    /**
+     * Sets whether or not to add a trailing delimiter.
+     */
+    private Boolean trailingDelimiter = false;
+    /**
      * Whether the unmarshalling should produce an iterator that reads the lines
      * on the fly or if all the lines must be read at one.
      */
@@ -291,6 +303,30 @@ public class CsvDataFormatConfiguration {
         this.quoteMode = quoteMode;
     }
 
+    public Boolean getIgnoreHeaderCase() {
+        return ignoreHeaderCase;
+    }
+
+    public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) {
+        this.ignoreHeaderCase = ignoreHeaderCase;
+    }
+
+    public Boolean getTrim() {
+        return trim;
+    }
+
+    public void setTrim(Boolean trim) {
+        this.trim = trim;
+    }
+
+    public Boolean getTrailingDelimiter() {
+        return trailingDelimiter;
+    }
+
+    public void setTrailingDelimiter(Boolean trailingDelimiter) {
+        this.trailingDelimiter = trailingDelimiter;
+    }
+
     public Boolean getLazyLoad() {
         return lazyLoad;
     }