Retrieve the Record Count from the CSV file

429 views
Skip to first unread message

Greta

unread,
Feb 10, 2017, 6:00:17 AM2/10/17
to beanio-users
Hi,

I have been using BeanIO component and JAXB data format in Apache Camel

Current output :-
After marshalling data with beanio-
"First Name","Last Name","City"
"James","Strachan","London"
"Vasanth","Raman","Chennai"
"Count of Records:"


Desired output:
After marshalling data with beanio-
"First Name","Last Name","City"
"James","Strachan","London"
"Vasanth","Raman","Chennai"
"Count of Records:" "2"

What could I include in mapping.xml to get the count of record as "2"?
Any suggestions? Please post.

Nico Schlebusch

unread,
Feb 10, 2017, 6:17:03 AM2/10/17
to bea...@googlegroups.com
Hi Greta,

In your pojo that contains the list of people, add a getter (getCount()) for returning the size of the list and use that variable/property (count) in your mapping file.

Kind regards,
Nico Schlebusch
nico...@gmail.com

--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Greta

unread,
Feb 12, 2017, 2:46:09 AM2/12/17
to beanio-users, nico...@gmail.com
Hi,

I have added the getter and setter in my java file and have also included getter setter for that footer record in my mapping.xml file. Please find attached the mapping.xml file attached.
Also i have included "alwaysQuote" inside the <parser> tag.  


Current output :
After marshalling data with beanio-
"First Name","Last Name","City"
"James","Strachan","London"
"Vasanth","Raman","Chennai"
"Count of Records:" " "

Please help .
mapping.xml

Greta

unread,
Feb 12, 2017, 8:42:59 AM2/12/17
to beanio-users, nico...@gmail.com
Hi,

I have added the getter and setter in my java file and have also included getter setter for that footer record in my mapping.xml file. Please find attached the mapping.xml file attached.
Also i have included "alwaysQuote" inside the <parser> tag. 

Current output :
After marshalling data with beanio-
"First Name","Last Name","City"
"James","Strachan","London"
"Vasanth","Raman","Chennai"
"Count of Records:" " "

On Friday, February 10, 2017 at 4:47:03 PM UTC+5:30, Nico Schlebusch wrote:
mapping.xml

Greta

unread,
Feb 13, 2017, 2:29:06 AM2/13/17
to beanio-users, nico...@gmail.com
Hi,

Any suggestions on how to retreive the count of records from the CSv file. I have attaached the mapping.xml file. Please find it enclosed. 
Please help

Nico Schlebusch

unread,
Feb 13, 2017, 3:46:16 PM2/13/17
to Greta, beanio-users
Hi Greta,

Please show us your Java code as well. I need to see what your object structure looks like.

Thanks

Kind regards,
Nico Schlebusch
nico...@gmail.com


Nico Schlebusch

unread,
Feb 13, 2017, 5:04:38 PM2/13/17
to beanio-users
Hi Greta,

I have it working, I'm only showing you the relevant sections and bare minimum you need for it to work:

    <group name="personsGroup" class="com.redhat.gpe.training.camel.bindy.Persons">
      <record name="Header"> 
          <field name="header1" rid="true" literal="First Name" ignore="true"/>
          <field name="header2" rid="true" literal="Last Name" ignore="true"/>
          <field name="header3" rid="true" literal="City" ignore="true"/>
      </record>

If you use the "default" attribute for a field, you will need an extra class having the 3 fields header1-3, but when you use it as above to output static text, you don't need an extra class, note the rid="true" attribute, the same goes for the "Footer" record.

      <group name="persons" class="com.redhat.gpe.training.camel.bindy.Person" collection="list">
        <record name="person">  
          <field name="firstName" />
          <field name="lastName" />
          <field name="city" />
        </record>
      </group>

      <record name="Footer">
        <field name="cof" rid="true" ignore="true" literal="Count of Records:"/>  
        <field name="count" type="int" />
      </record>
    </group>

You can use the order attribute if you have to, I don't think it is really necessary here.

The only Java class of interest for now is "Persons" with its getters + setters.

public class Persons {

  private List<Person> persons;
  // NB: no variable called "count"

  public Persons() {
    persons = new ArrayList<>();
  }

  public int getCount() {
    return persons.size();
  }

  public void setCount(final int newCount) {
    // no-op - value is determined by the number of elements in the list
  }

  public List<Person> getPersons(){
    return persons;
  }

  public void setPersons(final List<Person> newList) {
    persons = newList;
  }
}

Hope this answers your question and that I have not done your homework assignment for you.


Kind regards,
Nico Schlebusch
nico...@gmail.com


Reply all
Reply to author
Forward
0 new messages