[jira] Created: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
------------------------------------------------------------------------------

                 Key: CAMEL-398
                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
             Project: Apache Camel
          Issue Type: New Feature
          Components: camel-core
    Affects Versions: 1.4.0
            Reporter: Charles Moulliard


Hi,

It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.

For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
and the following action (.convertBodyTo(Order<List>) by example.

Current situation

Camel route

from("file:///c:/temp/test?noop=true")
.unmarshal().csv()
.to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)

Converter class

        public void TransformMessage(Exchange in) {
                process(in.getIn().getBody(List.class));
        }

        @SuppressWarnings("unchecked")
        private void process(List messages) {
               
                // Iterate through the list of messages
                for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {

                        // Split the content of the message into field
                        message = it.next();
                        field = (String[]) message.toArray();

                        order = new Order();
                        order.setId(Integer.valueOf(field[0]).intValue());
                        order.setBank(field[1]);
                        order.setAmountFrom(Double.parseDouble(field[2]));
                        order.setAmountTo(Double.parseDouble(field[3]));
                        order.setOrderInstruction(field[4].trim());
                        this.orderService.createOrder(order);

                }
        }

Regards,

Charles


--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46351#action_46351 ]

Claus Ibsen commented on CAMEL-398:
-----------------------------------

Charles, I think this is possible today?

You can add your own type-converters that will be picked up automatically by camel:
http://activemq.apache.org/camel/type-converter.html

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment: Annotation.rar

Hi,

I'm very proud to propose you the first version of Camel bindy component. The attachment contains a maven project.

1) Introduction

"bindy" Why, the idea behind this framework is to bind data to Java Bean using annotations. The framework in this first release allows a user to bind a CSV record to more than one POJOs and to convert the data according to the type of the java property (for more info, look to the folder org.apache.camel.bindy.model & model2 of folder src/test/java).

The annotation used to detect data field is :

 @DataField : only the pos attribute is mandatory, patterns can be provided date, byte, float, double, integer, long, number and short format,

The objects created can be link together in an one to one relation

        @Link
        public Client client;

The CSV separator is defined through the @record annotation :

       @Record(separator =",")

2) Example

A) Model with 2 classes linked (Order has a reference to client)

@Record(separator =",")
public class Order {
       
        @DataField(pos = 0)
        public int orderNr;
       
        @Link
        public Client client;
       
        @DataField(pos = 4)
        public String ISIN_Code;
       
        @DataField(name = "Name", pos = 5)
        public String Instrument_Name;
       
        @DataField(pos = 6)
        public String Quantity;
       
        @DataField(pos = 7)
        public String Currency;
       
        @DataField(pos = 8, pattern="dd-MM-yyyy")
        public Date OrderDate;

public class Client {

        @DataField(pos = 1)
        public String clientNr;
       
        @DataField(pos = 2)
        public String FirstName;
       
        @DataField(pos = 3)
        public String LastName;


B) CSV record

10,A1,Julia,Roberts,BE123456789,Belgium Ventage 10/12,150,USD,14-01-2009

where we have two model classes Order.class and Client.class linked (Order has a reference to client)

C) Objects generated

{org.apache.camel.bindy.model.Order=Model : org.apache.camel.bindy.model.Order : 10, 150, BE123456789, Belgium Ventage 10/12, USD, Model : org.apache.camel.bindy.model.Client : A1, Julia, Roberts,Wed Jan 14 16:30:30 CET 2009, org.apache.camel.bindy.model.Client=Model : org.apache.camel.bindy.model.Client : A1, Julia, Roberts}

Remarks :

- Two camel junit tests have been added to test the marshalling and unmarshalling
-  In the next step, it will be possible to bind also fixed length content (including header and footer).

Any remarks, comments are welcome

Charles

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>         Attachments: Annotation.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48717#action_48717 ]

Claus Ibsen commented on CAMEL-398:
-----------------------------------

Hi Charles

Nice. I havent had the time to look much into it. This is just some thoughts. Some might already be fixed.

- But could you package it in a sub folder (camel-bindy) so it creates this folder name
- Fix pom.xml to be aligned with the other camel component pom.xml files
- pom.xml dependencies for unit test should have scope test so the runtime dependencies are minimal
- use commons logging for logging
- use a log4j.properties in src/test/resources that is like the other log4j.properties from the other components
- use Apache license header
- remove @author or fix it as @author your name (note: we normally dont have @author in camel code)

You can run unit testing with cobertura to check for gaps

I think the command is:
mvn cobertura:cobertura test


When I get done with my work on the Tracer then I have time to look some more.

And I am sure James would look as well.

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>         Attachments: Annotation.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48720#action_48720 ]

Charles Moulliard commented on CAMEL-398:
-----------------------------------------

Hi Claus,

I will update my project according to your rermarks and coming back today with a new attachment.

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>         Attachments: Annotation.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment: camel-bindy.rar

@All,

Here is a new attachement updated according to your remarks

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment:     (was: Annotation.rar)

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment:     (was: camel-bindy.rar)

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment: camel-bindy.rar

Small modifications have been added to the camel-bindy component to avoid errors when a blnak line is present in the CSV file or empty fields

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Assigned: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned CAMEL-398:
---------------------------------

    Assignee: Claus Ibsen

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.rar
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment:     (was: camel-bindy.rar)

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment: camel-bindy.zip

File compressed using zip format.

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48833#action_48833 ]

Claus Ibsen commented on CAMEL-398:
-----------------------------------

Comments on first impression

- interfaces should always be fully javadoced (especially if others should use or implement em)
- the classloading should be changed to use Camel classes and be OSGi friendly
- dependency on camel-spring should only be scope for test (= unit testing)
- Would it not be nice that each POJO should be annoted at classlevel as well (Client.java does not have etc.)
- Why are the fields in the model objects public? We should support private fields and use getter/setter to access them
- LinkType? Doesnt hibernate have a similar feature and maybe there is a better name?
- ModelFactory if its a shared instance then it need locking for concurrent access (we can address this later)
- BindyDataFormat might be renamed to BindyCsvDataFormat (its nice when the classname has this important piece in its name)
- use Camel type converter to convert from String to byte[] as it will handle encoding as well (exch.getContext().getTypeConverter().convertTo(byte[].class, exch, exch);) in BindyDataFormat
- In unmarshal we should use a java.util.Scanner if we for instance is reading a very big file and can reduce memory usage
- code needs to be polished a bit. If you use IDEA it reports :) Well we get that later
- ModelFactory should probably have an interface and a DefaultModelFactory implementatiion
- format.impl is not a nice package name - just use format
- I dont think you should use threadlocal to store pattern formatters. Yes they are not thread safe (damm SUN). creating objects is not expensive anymore!
- ByteFormat - new Byte(String) is not the right one to use - use parseByte instead.
- We could probably use generics for the format, so the API is nicer (we can check that later)




> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48837#action_48837 ]

Charles Moulliard commented on CAMEL-398:
-----------------------------------------

    *  interfaces should always be fully javadoced (especially if others should use or implement em)
>> I'm currently working on code documentation. My first release was not fully documented because I would like to have your feedback prior to do this job (depending on the modification requested and the refactory required, ..)

    * the classloading should be changed to use Camel classes and be OSGi friendly.
>> I will check how to use Camel ResolverUtil

    * dependency on camel-spring should only be scope for test (= unit testing)
>> ok.  Removed form the pom.xml
   
 * Would it not be nice that each POJO should be annoted at classlevel as well (Client.java does not have etc.)
>> Client is not annoted at class level because it is a slave of order class. So, this is not required. Moreover, we need only one 'root class' where the separator is defined.

    * Why are the fields in the model objects public? We should support private fields and use getter/setter to access them
>> I will check this point again and adapt the code. I have changed from private to public due to introspection.

    * LinkType? Doesnt hibernate have a similar feature and maybe there is a better name?
>> I have discovered last week that Hibernate use the following annotation @OnetoMany concerning the link type. So maybe, we can follow this convention ?

    * ModelFactory if its a shared instance then it need locking for concurrent access (we can address this later)
>> IF my code is correct. Only one instance of the modelfactory is created for each Dataformat(packageName) instance created

    * BindyDataFormat might be renamed to BindyCsvDataFormat (its nice when the classname has this important piece in its name)
>> OK. Is the name that you propose not redundant with the fact that this class is in the package org.apache.camel.bindy.csv ?

    * use Camel type converter to convert from String to byte[] as it will handle encoding as well (exch.getContext().getTypeConverter().convertTo(byte[].class, exch, exch) in BindyDataFormat
>> ok
   
    * In unmarshal we should use a java.util.Scanner if we for instance is reading a very big file and can reduce memory usage
>> ok
   
    * code needs to be polished a bit. If you use IDEA it reports Well we get that later
>> I use Eclipse. What do you want that I do, use the camel formating style ?

    * ModelFactory should probably have an interface and a DefaultModelFactory implementatiion
>> Absolutely
   
    * format.impl is not a nice package name - just use format
>> ok
   
    * I dont think you should use threadlocal to store pattern formatters. Yes they are not thread safe (damm SUN). creating objects is not expensive anymore!
>> This code is coming from my colleague. It will be happy that he must change it

    * ByteFormat - new Byte(String) is not the right one to use - use parseByte instead.
>> same remark as before
 
   * We could probably use generics for the format, so the API is nicer (we can check that later)
>> If you have an example, this will help me ?

Question : What do you think about the hashmap (HashMap<String, Object> modelObjects = new HashMap<String, Object>();) ? Do you think that this is a good idea to use hashmap and class name as key ?



> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48872#action_48872 ]

Charles Moulliard commented on CAMEL-398:
-----------------------------------------

Is it right for you if I create a version readme.txt file where I will put the changes made in the camel-bindy component and add it to the zip ?

remark : in this case, we will avoid to pollute too much this jira ticket.

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment: camel-bindy-v0.95.zip

I have added a new zip where some of your remarks have been implemented. See the readme.txt file concerning the points implemented.

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy-v0.95.zip, camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48889#action_48889 ]

Claus Ibsen commented on CAMEL-398:
-----------------------------------

v0.95 comments

- methods in interface must also be fully javadoced

BindyFactory
- throws Exception is pain to work with. But I can see we have this flaw in Camels DataFormat interface
- throws ClassNotFoundException should be removed as well. Nobody can recover from this one :)
- why is createModel() as void? The name kinda expects it to return a Object as model or something? Find a better name if it should be void
- retrieveSeparator() maybe getSeparator is a better name?
- bind - consider using List<String> instead of String[] as arrays is pain to work with in Java
- if parameter objects is the same in bind/unbind then the parameter should have same name, eg: models

Format
- T should be used a type in methods:
    public String format(T object)
    public T parse(String string)
- And get rid of throws Exception.

BindyCsvFactory
- Program against interface. Use Map x = new HashMap instead of HashMap x = new HashMap
- and your class attributes should be private and not public!
- Use ObjectHelper.notEmpty for testing if a String is not empty. Use ObjectHelper.notNull to test if a mandatory parameter is not null etc.
- use // for code comments inside methods and not /* */ blocks
- why are you using a sortedmap in unbind?
- You can use a LinkedHashMap then the order is preserved. That is the original insert order is the same order you can iterate
- unbind should not use a fixed comma as separator but from the getSeparator method
- getFormat would be nice to be moved into a FormatFactory so other implementation can reuse it

BindyCsvDataFormat
- separator should be mandatory. So you can use ObjectHelper.notEmpty() to force it be be given. Better to fail due a missing separator than to just ignore it and not unmarshal anything.
- scanner close id one twice. only do it in the finally

NumberPattern is still using the threadlocal stuff, please remove it

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy-v0.95.zip, camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Issue Comment Edited: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48889#action_48889 ]

davsclaus edited comment on CAMEL-398 at 1/21/09 10:45 PM:
-------------------------------------------------------------

v0.95 comments

- methods in interface must also be fully javadoced

BindyFactory
- throws Exception is pain to work with. But I can see we have this flaw in Camels DataFormat interface
- throws ClassNotFoundException should be removed as well. Nobody can recover from this one :)
- why is createModel() as void? The name kinda expects it to return a Object as model or something? Find a better name if it should be void
- retrieveSeparator() maybe getSeparator is a better name?
- bind - consider using List<String> instead of String[] as arrays is pain to work with in Java
- if parameter objects is the same in bind/unbind then the parameter should have same name, eg: models

Format
- T should be used a type in methods:
    public String format(T object)
    public T parse(String string)

BindyCsvFactory
- Program against interface. Use Map x = new HashMap instead of HashMap x = new HashMap
- and your class attributes should be private and not public!
- Use ObjectHelper.notEmpty for testing if a String is not empty. Use ObjectHelper.notNull to test if a mandatory parameter is not null etc.
- use // for code comments inside methods and not /* */ blocks
- why are you using a sortedmap in unbind?
- You can use a LinkedHashMap then the order is preserved. That is the original insert order is the same order you can iterate
- unbind should not use a fixed comma as separator but from the getSeparator method
- getFormat would be nice to be moved into a FormatFactory so other implementation can reuse it

BindyCsvDataFormat
- separator should be mandatory. So you can use ObjectHelper.notEmpty() to force it be be given. Better to fail due a missing separator than to just ignore it and not unmarshal anything.
- scanner close id one twice. only do it in the finally

NumberPattern is still using the threadlocal stuff, please remove it

      was (Author: davsclaus):
    v0.95 comments

- methods in interface must also be fully javadoced

BindyFactory
- throws Exception is pain to work with. But I can see we have this flaw in Camels DataFormat interface
- throws ClassNotFoundException should be removed as well. Nobody can recover from this one :)
- why is createModel() as void? The name kinda expects it to return a Object as model or something? Find a better name if it should be void
- retrieveSeparator() maybe getSeparator is a better name?
- bind - consider using List<String> instead of String[] as arrays is pain to work with in Java
- if parameter objects is the same in bind/unbind then the parameter should have same name, eg: models

Format
- T should be used a type in methods:
    public String format(T object)
    public T parse(String string)
- And get rid of throws Exception.

BindyCsvFactory
- Program against interface. Use Map x = new HashMap instead of HashMap x = new HashMap
- and your class attributes should be private and not public!
- Use ObjectHelper.notEmpty for testing if a String is not empty. Use ObjectHelper.notNull to test if a mandatory parameter is not null etc.
- use // for code comments inside methods and not /* */ blocks
- why are you using a sortedmap in unbind?
- You can use a LinkedHashMap then the order is preserved. That is the original insert order is the same order you can iterate
- unbind should not use a fixed comma as separator but from the getSeparator method
- getFormat would be nice to be moved into a FormatFactory so other implementation can reuse it

BindyCsvDataFormat
- separator should be mandatory. So you can use ObjectHelper.notEmpty() to force it be be given. Better to fail due a missing separator than to just ignore it and not unmarshal anything.
- scanner close id one twice. only do it in the finally

NumberPattern is still using the threadlocal stuff, please remove it
 

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy-v0.95.zip, camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment: camel-bindy-v0.96.zip

See readme.txt file for modifications done

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy-v0.95.zip, camel-bindy-v0.96.zip, camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-398) Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Charles Moulliard updated CAMEL-398:
------------------------------------

    Attachment:     (was: camel-bindy-v0.96.zip)

> Map the content of a CSV file to a POJO using @annotation and .convertBodyTo()
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-398
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-398
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Charles Moulliard
>            Assignee: Claus Ibsen
>             Fix For: 2.0.0
>
>         Attachments: camel-bindy-v0.95.zip, camel-bindy-v0.96.zip, camel-bindy.zip
>
>
> Hi,
> It should be nice if in a next relase of Camel, it will be possible to map the content of a CSV file to a POJO using @annotation.
> For the moment, I use an ArrayList + iterator (see code hereafter) to achieve the extraction of the content but I'm sure that we can simplify this code using @Annotation
> and the following action (.convertBodyTo(Order<List>) by example.
> Current situation
> Camel route
> from("file:///c:/temp/test?noop=true")
> .unmarshal().csv()
> .to("bean:converter?methodName=TransformMessage"); --> should be replaced by something like .convertBodyTo(Order<List>)
> Converter class
>         public void TransformMessage(Exchange in) {
>                 process(in.getIn().getBody(List.class));
>         }
>         @SuppressWarnings("unchecked")
>         private void process(List messages) {
>                
>                 // Iterate through the list of messages
>                 for (Iterator<ArrayList> it = messages.iterator(); it.hasNext();) {
>                         // Split the content of the message into field
>                         message = it.next();
>                         field = (String[]) message.toArray();
>                         order = new Order();
>                         order.setId(Integer.valueOf(field[0]).intValue());
>                         order.setBank(field[1]);
>                         order.setAmountFrom(Double.parseDouble(field[2]));
>                         order.setAmountTo(Double.parseDouble(field[3]));
>                         order.setOrderInstruction(field[4].trim());
>                         this.orderService.createOrder(order);
>                 }
>         }
> Regards,
> Charles

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

12