You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jothi <co...@gmail.com> on 2013/07/10 19:07:25 UTC

CSV files processing

Is there a way to find out which CSV file that is currently being processed?
I mean I have a couple of CSV files and I do not know the name of those CSV
files. All I know is their structure. If it was XML, I can identify the file
structure using xpath. Is there something similar that I can do for CSV
files? The first line always contains the name of the fields. Of course I
can hard code the fields and do a string comparison, but I feel this to be a
bit ugly. Is there an elegant way?

Regards,
Joe 



--
View this message in context: http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV files processing

Posted by Christian Müller <ch...@gmail.com>.
Bindy always maps an "ObjectMaster" and the contained objects to one line
[1].

[1]
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java;h=3ab36149f803b665eac43e42bbde09bada86d329;hb=HEAD

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Fri, Jul 12, 2013 at 2:43 PM, Jothi <co...@gmail.com> wrote:

> I have a Bindy bean written as below:
>
> public class ObjectMaster {
>
>     private String field1;
>
>     @OneToMany
>     private List < Object1 > field2;
>
>     @OneToMany
>     private List < Object2 > field3;
> }
>
> I have two CSV files in which unmarshalling one of them would produce a one
> to many relationship with ObjectMaster and Object1 and the other CSV file
> will produce the one to many relationship with ObjectMaster and Object2. Is
> this possible with the camel bindy?
>
> Regards,
> Joe
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470p5735570.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: CSV files processing

Posted by Jothi <co...@gmail.com>.
I have a Bindy bean written as below:

public class ObjectMaster {

    private String field1;

    @OneToMany
    private List < Object1 > field2;

    @OneToMany
    private List < Object2 > field3;
}

I have two CSV files in which unmarshalling one of them would produce a one
to many relationship with ObjectMaster and Object1 and the other CSV file
will produce the one to many relationship with ObjectMaster and Object2. Is
this possible with the camel bindy?

Regards,
Joe 




--
View this message in context: http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470p5735570.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV files processing

Posted by Jothi <co...@gmail.com>.
I'm considering the Bindy component to marshall and unmarshall stuff. I can
see that there is a OneToMany annotation that I can use. Will the OneToMany
only map to a List or can I use a Set as well?



--
View this message in context: http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470p5735569.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV files processing

Posted by gquintana <ge...@gmail.com>.
XPath is the language to walk through the XML Dom Tree. Either you treat the
file as a String and use String operations ( Simple
<http://camel.apache.org/simple.html>   as contains and regex operations).
Or you treat the file as Java object tree (after unmarshalling) and walk
through the Java object tree (an expression language like  Simple
<http://camel.apache.org/simple.html>   can do that).



--
View this message in context: http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470p5735527.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV files processing

Posted by Joe San <co...@gmail.com>.
The problem is that I cannot rely on that file name. I have to rely on the
content. The first line in the CSV file will always contain what is being
exported with the field names. This set of field names are finite. I can of
course hard code that comma seperated field names in a string and compare
them. But is there a better approach like we do for an xml using xpath?

Regards,
Joe


On Thu, Jul 11, 2013 at 8:22 AM, Claus Ibsen <cl...@gmail.com> wrote:

> If you pickup files using the file component, then the message headers
> contains file name information.
> http://camel.apache.org/file2
>
>
>
> On Wed, Jul 10, 2013 at 7:07 PM, Jothi <co...@gmail.com> wrote:
> > Is there a way to find out which CSV file that is currently being
> processed?
> > I mean I have a couple of CSV files and I do not know the name of those
> CSV
> > files. All I know is their structure. If it was XML, I can identify the
> file
> > structure using xpath. Is there something similar that I can do for CSV
> > files? The first line always contains the name of the fields. Of course I
> > can hard code the fields and do a string comparison, but I feel this to
> be a
> > bit ugly. Is there an elegant way?
> >
> > Regards,
> > Joe
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: CSV files processing

Posted by Claus Ibsen <cl...@gmail.com>.
If you pickup files using the file component, then the message headers
contains file name information.
http://camel.apache.org/file2



On Wed, Jul 10, 2013 at 7:07 PM, Jothi <co...@gmail.com> wrote:
> Is there a way to find out which CSV file that is currently being processed?
> I mean I have a couple of CSV files and I do not know the name of those CSV
> files. All I know is their structure. If it was XML, I can identify the file
> structure using xpath. Is there something similar that I can do for CSV
> files? The first line always contains the name of the fields. Of course I
> can hard code the fields and do a string comparison, but I feel this to be a
> bit ugly. Is there an elegant way?
>
> Regards,
> Joe
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: CSV files processing

Posted by gquintana <ge...@gmail.com>.
I would convert the CSV file into a List<Map&lt;String,String>>, each row
being a Map<String,String>, the first String being the column header name.
Unfortunately Camel CSV unmarshals to List<List&lt;String>> and Camel Bindy
looks too strict for your case (unmarshalls to List<JavaBean>). So I would
code my own data format to do the conversion CSV -->
List<Map&lt;String,String>> using for example
http://supercsv.sourceforge.net/apidocs/org/supercsv/io/CsvMapReader.html 

I always found strange that Camel CSV marshals from
List<Map&lt;String,String>> but unmarshals to List<List&lt;String>>



--
View this message in context: http://camel.465427.n5.nabble.com/CSV-files-processing-tp5735470p5735493.html
Sent from the Camel - Users mailing list archive at Nabble.com.