camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r686614 - in /activemq/camel/trunk/components/camel-flatpack/src: main/java/org/apache/camel/component/flatpack/ test/data/headerandtrailer/ test/java/org/apache/camel/component/flatpack/ test/resources/ test/resources/org/apache/camel/comp...
Date Sun, 17 Aug 2008 14:28:37 GMT
Author: davsclaus
Date: Sun Aug 17 07:28:36 2008
New Revision: 686614

URL: http://svn.apache.org/viewvc?rev=686614&view=rev
Log:
CAMEL-731: Support for header and trailer rows in camel-flatpack

Added:
    activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/
    activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt
  (with props)
    activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java
  (contents, props changed)
      - copied, changed from r686454, activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthTest.java
    activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
  (contents, props changed)
      - copied, changed from r686454, activemq/camel/trunk/components/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml
    activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
  (contents, props changed)
      - copied, changed from r686454, activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthTest-context.xml
Modified:
    activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
    activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackComponent.java
    activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
    activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackDataFormat.java

Modified: activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java?rev=686614&r1=686613&r2=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
Sun Aug 17 07:28:36 2008
@@ -32,38 +32,26 @@
     }
 
     public Object get(int index) {
-        Iterator iter = iterator();
-        for (int i = 0; iter.hasNext(); i++) {
-            Object value = iter.next();
-            if (i == index) {
-                return value;
-            }
-        }
-        return null;
+        dataSet.absolute(index);
+        return FlatpackConverter.toMap(dataSet);
     }
 
     public int size() {
-        int answer = 0;
-        for (Iterator iter = iterator(); iter.hasNext();) {
-            iter.next();
-            answer++;
-        }
-        return answer;
+        return dataSet.getRowCount();
     }
 
     @Override
     public Iterator iterator() {
         dataSet.goTop();
         return new Iterator() {
+
             public boolean hasNext() {
                 return dataSet.next();
             }
 
             public Object next() {
-                // TODO because of a limitation in split()
-                // we need to create an object for the current position
-                // otherwise strangeness occurs when the same object is used to represent
-                // each row
+                // because of a limitation in split() we need to create an object for the
current position
+                // otherwise strangeness occurs when the same object is used to represent
each row
                 return FlatpackConverter.toMap(dataSet);
             }
 
@@ -71,6 +59,6 @@
                 throw new UnsupportedOperationException("remove() not supported");
             }
         };
-
     }
+    
 }

Modified: activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackComponent.java?rev=686614&r1=686613&r2=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackComponent.java
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackComponent.java
Sun Aug 17 07:28:36 2008
@@ -32,6 +32,9 @@
  */
 public class FlatpackComponent extends ResourceBasedComponent {
 
+    public static final String HEADER_ID = "header";
+    public static final String TRAILER_ID = "trailer";
+
     protected Endpoint<Exchange> createEndpoint(String uri, String remaining, Map parameters)
throws Exception {
         boolean fixed = false;
         if (remaining.startsWith("fixed:")) {

Modified: activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java?rev=686614&r1=686613&r2=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
Sun Aug 17 07:28:36 2008
@@ -27,9 +27,11 @@
  */
 @Converter
 public final class FlatpackConverter {
+
     private FlatpackConverter() {
         // helper class
     }
+
     @Converter
     public static Map toMap(DataSet dataSet) {
         Map<String, Object> map = new HashMap<String, Object>();
@@ -39,15 +41,25 @@
 
     /**
      * Puts the values of the dataset into the map
-     * @param map
-     * @param dataSet
      */
     public static void putValues(Map<String, Object> map, DataSet dataSet) {
-        String[] columns = dataSet.getColumns();
+        boolean header = dataSet.isRecordID(FlatpackComponent.HEADER_ID);
+        boolean trailer = dataSet.isRecordID(FlatpackComponent.TRAILER_ID);
+
+        // the columns can vary depending on header, body or trailer
+        String[] columns;
+        if (header) {
+            columns = dataSet.getColumns(FlatpackComponent.HEADER_ID);
+        } else if (trailer) {
+            columns = dataSet.getColumns(FlatpackComponent.TRAILER_ID);
+        } else {
+            columns = dataSet.getColumns();
+        }
+
         for (String column : columns) {
-            // TODO deal with non-string types?
             String value = dataSet.getString(column);
             map.put(column, value);
         }
     }
+
 }

Modified: activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackDataFormat.java?rev=686614&r1=686613&r2=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackDataFormat.java
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackDataFormat.java
Sun Aug 17 07:28:36 2008
@@ -90,7 +90,6 @@
         this.textQualifier = textQualifier;
     }
 
-
     public Resource getDefinition() {
         return definition;
     }

Added: activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt?rev=686614&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt
(added)
+++ activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt
Sun Aug 17 07:28:36 2008
@@ -0,0 +1,6 @@
+HBT20080817
+JOHN                               DOE                                1234 CIRCLE CT    
                                                                                 ELYRIA  
                                                                                         
 OH44035
+JIMMY                              SMITH                              180 SOME ST       
                                                                                 AVON    
                                                                                         
 OH44011
+JANE                               DOE                                111 MILKY WY      
                                                                                 AMHERST 
                                                                                         
 OH44001
+FRED                               FLINTSTONE                         123 ROCKY WY      
                                                                                 BEDROCK 
                                                                                         
 AZ12345
+FBTSUCCESS

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java
(from r686454, activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java?p2=activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java&p1=activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthTest.java&r1=686454&r2=686614&rev=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthTest.java
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java
Sun Aug 17 07:28:36 2008
@@ -33,21 +33,28 @@
  * @version $Revision$
  */
 @ContextConfiguration
-public class FixedLengthTest extends AbstractJUnit38SpringContextTests {
-    private static final transient Log LOG = LogFactory.getLog(FixedLengthTest.class);
+public class HeaderAndTrailerTest extends AbstractJUnit38SpringContextTests {
+    private static final transient Log LOG = LogFactory.getLog(HeaderAndTrailerTest.class);
 
     @EndpointInject(uri = "mock:results")
     protected MockEndpoint results;
 
     protected String[] expectedFirstName = {"JOHN", "JIMMY", "JANE", "FRED"};
 
-    public void testCamel() throws Exception {
-        results.expectedMessageCount(4);
+    public void testHeaderAndTrailer() throws Exception {
+        results.expectedMessageCount(6);
         results.assertIsSatisfied();
 
         int counter = 0;
         List<Exchange> list = results.getReceivedExchanges();
-        for (Exchange exchange : list) {
+
+        // assert header
+        Map header = list.get(0).getIn().getBody(Map.class);
+        assertEquals("HBT", header.get("INDICATOR"));
+        assertEquals("20080817", header.get("DATE"));
+
+        // assert body
+        for (Exchange exchange : list.subList(1, 5)) {
             Message in = exchange.getIn();
             Map body = in.getBody(Map.class);
             assertNotNull("Should have found body as a Map but was: " + ObjectHelper.className(in.getBody()),
body);
@@ -56,6 +63,10 @@
             counter++;
         }
 
+        // assert trailer
+        Map trailer = list.get(5).getIn().getBody(Map.class);
+        assertEquals("FBT", trailer.get("INDICATOR"));
+        assertEquals("SUCCESS", trailer.get("STATUS"));
     }
 
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/HeaderAndTrailerTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
(from r686454, activemq/camel/trunk/components/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml?p2=activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml&p1=activemq/camel/trunk/components/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml&r1=686454&r2=686614&rev=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
Sun Aug 17 07:28:36 2008
@@ -1,9 +1,22 @@
 <?xml version='1.0'?>
-<!DOCTYPE PZMAP SYSTEM
-	"flatpack.dtd" >
+<!DOCTYPE PZMAP SYSTEM "flatpack.dtd" >
+
 <PZMAP>
-	<COLUMN name="ITEM_DESC" />
-	<COLUMN name="IN_STOCK" />
-	<COLUMN name="PRICE" />
-	<COLUMN name="LAST_RECV_DT" />
-</PZMAP> 
+    <RECORD id="header" startPosition="1" endPosition="3" indicator="HBT">
+        <COLUMN name="INDICATOR" length="3"/>
+        <COLUMN name="DATE" length="8"/>
+    </RECORD>
+    
+    <COLUMN name="FIRSTNAME" length="35" />
+    <COLUMN name="LASTNAME" length="35" />
+    <COLUMN name="ADDRESS" length="100" />
+    <COLUMN name="CITY" length="100" />
+    <COLUMN name="STATE" length="2" />
+    <COLUMN name="ZIP" length="5" />
+
+    <RECORD id="trailer" startPosition="1" endPosition="3" indicator="FBT">
+        <COLUMN name="INDICATOR" length="3"/>
+        <COLUMN name="STATUS" length="7"/>
+    </RECORD>
+
+</PZMAP>
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/PEOPLE-HeaderAndTrailer.pzmap.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Copied: activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
(from r686454, activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthTest-context.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml?p2=activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml&p1=activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthTest-context.xml&r1=686454&r2=686614&rev=686614&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthTest-context.xml
(original)
+++ activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
Sun Aug 17 07:28:36 2008
@@ -25,12 +25,12 @@
   <!-- START SNIPPET: example -->
   <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
     <route>
-      <from uri="file://src/test/data/fixed?noop=true"/>
-      <to uri="flatpack:fixed:PEOPLE-FixedLength.pzmap.xml"/>
+      <from uri="file://src/test/data/headerandtrailer?noop=true"/>
+      <to uri="flatpack:fixed:PEOPLE-HeaderAndTrailer.pzmap.xml"/>
     </route>
 
     <route>
-      <from uri="flatpack:fixed:PEOPLE-FixedLength.pzmap.xml"/>
+      <from uri="flatpack:fixed:PEOPLE-HeaderAndTrailer.pzmap.xml"/>
       <convertBodyTo type="java.util.Map"/>
       <to uri="mock:results"/>
     </route>

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: activemq/camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/HeaderAndTrailerTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message