Author: hadrian
Date: Thu Jun 10 00:06:55 2010
New Revision: 953192
URL: http://svn.apache.org/viewvc?rev=953192&view=rev
Log:
CAMEL-2803. Patch applied with many thanks.
Added:
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest.java
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandremovewhitespace/
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandremovewhitespace/Order.java
camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest-context.xml
Modified:
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
Modified:
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=953192&r1=953191&r2=953192&view=diff
==============================================================================
---
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
(original)
+++
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
Thu Jun 10 00:06:55 2010
@@ -154,6 +154,10 @@ public class BindyCsvFactory extends Bin
DataField dataField = dataFields.get(pos);
ObjectHelper.notNull(dataField, "No position " + pos + " defined
for the field : " + data + ", line : " + line);
+ if (dataField.trim()) {
+ data = data.trim();
+ }
+
if (dataField.required()) {
// Increment counter of mandatory fields
++counterMandatoryFields;
Modified:
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java?rev=953192&r1=953191&r2=953192&view=diff
==============================================================================
---
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
(original)
+++
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
Thu Jun 10 00:06:55 2010
@@ -94,4 +94,10 @@ public @interface DataField {
*/
boolean required() default false;
+ /**
+ * Indicates if the value should be trimed
+ *
+ * @return boolean
+ */
+ boolean trim() default false;
}
Added:
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest.java?rev=953192&view=auto
==============================================================================
---
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest.java
(added)
+++
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest.java
Thu Jun 10 00:06:55 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.dataformat.bindy.csv;
+
+
+import java.util.List;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.junit.Assert.assertEquals;
+
+...@contextconfiguration
+public class BindySimpleCsvRemoveWhitespaceUnmarshallTest extends
AbstractJUnit4SpringContextTests {
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ private String record = "1 ,
2,Albert,Cartier,ISIN,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
+ +
",,Jacques,,,BE12345678,SELL,,1500,EUR,08-01-2009";
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint resultEndpoint;
+
+ @Test
+ public void testUnMarshallMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+
+ template.sendBody(record);
+
+ resultEndpoint.assertIsSatisfied();
+ Exchange exchange = resultEndpoint.assertExchangeReceived(0);
+ assertEquals(2, exchange.getIn().getBody(List.class).size());
+ }
+
+ public static class ContextConfig extends RouteBuilder {
+ BindyCsvDataFormat camelDataFormat = new
BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.simple.oneclassandremovewhitespace");
+
+ public void configure() {
+ // from("file://src/test/data2")
+ from("direct:start").unmarshal(camelDataFormat).to("mock:result");
+ }
+ }
+}
Added:
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandremovewhitespace/Order.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandremovewhitespace/Order.java?rev=953192&view=auto
==============================================================================
---
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandremovewhitespace/Order.java
(added)
+++
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandremovewhitespace/Order.java
Thu Jun 10 00:06:55 2010
@@ -0,0 +1,155 @@
+/**
+ * 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.dataformat.bindy.model.simple.oneclassandremovewhitespace;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+
+...@csvrecord(separator = ",")
+public class Order {
+
+ @DataField(pos = 1, trim = true)
+ private int orderNr;
+
+ @DataField(pos = 2, trim = true)
+ private Integer clientNr;
+
+ @DataField(pos = 3)
+ private String firstName;
+
+ @DataField(pos = 4)
+ private String lastName;
+
+ @DataField(pos = 5)
+ private String instrumentCode;
+
+ @DataField(pos = 6)
+ private String instrumentNumber;
+
+ @DataField(pos = 7)
+ private String orderType;
+
+ @DataField(name = "Name", pos = 8)
+ private String instrumentType;
+
+ @DataField(pos = 9, precision = 2)
+ private BigDecimal amount;
+
+ @DataField(pos = 10)
+ private String currency;
+
+ @DataField(pos = 11, pattern = "dd-MM-yyyy")
+ private Date orderDate;
+
+ public int getOrderNr() {
+ return orderNr;
+ }
+
+ public void setOrderNr(int orderNr) {
+ this.orderNr = orderNr;
+ }
+
+ public Integer getClientNr() {
+ return clientNr;
+ }
+
+ public void setClientNr(Integer clientNr) {
+ this.clientNr = clientNr;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getInstrumentCode() {
+ return instrumentCode;
+ }
+
+ public void setInstrumentCode(String instrumentCode) {
+ this.instrumentCode = instrumentCode;
+ }
+
+ public String getInstrumentNumber() {
+ return instrumentNumber;
+ }
+
+ public void setInstrumentNumber(String instrumentNumber) {
+ this.instrumentNumber = instrumentNumber;
+ }
+
+ public String getOrderType() {
+ return orderType;
+ }
+
+ public void setOrderType(String orderType) {
+ this.orderType = orderType;
+ }
+
+ public String getInstrumentType() {
+ return instrumentType;
+ }
+
+ public void setInstrumentType(String instrumentType) {
+ this.instrumentType = instrumentType;
+ }
+
+ public BigDecimal getAmount() {
+ return amount;
+ }
+
+ public void setAmount(BigDecimal amount) {
+ this.amount = amount;
+ }
+
+ public String getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+
+ public Date getOrderDate() {
+ return orderDate;
+ }
+
+ public void setOrderDate(Date orderDate) {
+ this.orderDate = orderDate;
+ }
+
+ @Override
+ public String toString() {
+ return "Model : " + this.getClass().getName() + " : " + this.orderNr +
", " + this.orderType + ", " + String.valueOf(this.amount) + ", " +
this.instrumentCode + ", "
+ + this.instrumentNumber + ", " + this.instrumentType + ", " +
this.currency + ", " + this.clientNr + ", " + this.firstName + ", " +
this.lastName + ", "
+ + String.valueOf(this.orderDate);
+ }
+}
Added:
camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest-context.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest-context.xml?rev=953192&view=auto
==============================================================================
---
camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest-context.xml
(added)
+++
camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvRemoveWhitespaceUnmarshallTest-context.xml
Thu Jun 10 00:06:55 2010
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="myBuilder" />
+ </camelContext>
+
+ <bean id="myBuilder"
class="org.apache.camel.dataformat.bindy.csv.BindySimpleCsvRemoveWhitespaceUnmarshallTest$ContextConfig"/>
+
+</beans>
\ No newline at end of file