View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

Projects/Generic CSV Bankstatement Importer/Developers Manual

Contents

About this document

This document is oriented to Java developers who want to create new CSV bank statement importers for any CSV file format based on the Generic CSV Bank Statement Importer framework.

Introduction

The way to import bank statements lines from a CSV file is either to adapt your CSV file to a defined structure compatible with the Generic CSV Bank Statement Importer or to develop some code to support the concrete CSV format.

The advantage of the latter solution is that the user can directly import the CSV file generated from any software into Openbravo, instead of manually adapting it to the generic CSV format each time he/she wants to import a new file.


The Generic CSV Bank Statement importer module provides a framework that makes it easier to develop the code for supporting any CSV bank statement lines format.

Creating the Java Bean

The first step is to create a Java Bean that represents the file structure we want to import. Each one of the CSV columns must be mandatory represented as a String attribute. Let's see an example that will help us to understand it better:

 
public class GenericBankStatementLineBean extends GenericCsvImporterBean {
 
  public static final String PROPERTY_BPARTNERNAME = "bpartnername";
  public static final String PROPERTY_TRANSACTIONDATESTRING = "transactionDateString";
  public static final String PROPERTY_CRAMOUNTSTRING = "cramountString";
 
  private String bpartnername;
 
  private String cramountString;
  private BigDecimal cramount;
 
  private String transactionDateString;
  private Date transactionDate;
 
  public String getBpartnername() {
    return bpartnername;
  }
 
  public void setBpartnername(String bpartnername) {
    this.bpartnername = bpartnername;
  }
 
  public void setCramountString(String cramountString) {
    this.cramountString = cramountString;
    setCramount(Utility.stringToBigDecimal(cramountString, getDecimalSeparator()));
  }
 
  public void setTransactionDateString(String transactionDateString) throws ParseException {
    this.transactionDateString = transactionDateString;
    setTransactionDate(Utility.stringToDate(transactionDateString, getDateFormat()));
  }
 
  // Rest of getter/setter hidden for simplicity
}
public void setTransactionDateString(String transactionDateString) throws ParseException {
    this.transactionDateString = transactionDateString;
    setTransactionDate(Utility.stringToDate(transactionDateString, getDateFormat()));
  }
public void setCramountString(String cramountString) {
    this.cramountString = cramountString;
    setCramount(Utility.stringToBigDecimal(cramountString, getDecimalSeparator()));
  }

Creating the CSV Importer

The last step is to create a class with the logic for importing the CSV file. Let's see an example:

public class GenericCSVImporterImplementation extends
    GenericCSVImporter<GenericBankStatementLineBean> {
 
  @Override
  public Map<String, String> generateColumnMapping() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("Transaction Date", GenericBankStatementLineBean.PROPERTY_TRANSACTIONDATESTRING);
    map.put("Business Partner Name", GenericBankStatementLineBean.PROPERTY_BPARTNERNAME);
    map.put("Amount IN", GenericBankStatementLineBean.PROPERTY_CRAMOUNTSTRING);
    return map;
  }
 
  @Override
  public Class<GenericBankStatementLineBean> configureBean() {
    return GenericBankStatementLineBean.class;
  }
 
  @Override
  public List<FIN_BankStatementLine> generateFIN_BankStatementLine() {
    List<FIN_BankStatementLine> bankStatementLines = new ArrayList<FIN_BankStatementLine>();
    for (final GenericBankStatementLineBean gbslb : getBankStatementLines()) {
      bankStatementLines.add(Utility.createFIN_BankStatementLine(gbslb, getTargetBankStatement(),
          getLineNo() + 10l));
    }
 
    return bankStatementLines;
  }
 
}

Finally, the generateFIN_BankStatementLine() method must return the List of FIN_BankStatementLine ready to be saved into the system


This is everything you need to develop your own CSV bank statement lines importer based on the Generic CSV Bank Statement Importer framework. Finally remember that you can package your code as a module to be easily distributed to your customers. For more information see the Modularity concepts.

Retrieved from "http://wiki.openbravo.com/wiki/Projects/Generic_CSV_Bankstatement_Importer/Developers_Manual"

This page has been accessed 994 times. This page was last modified on 10 September 2012, at 13:48. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.