Import transactions with format reader
This sample shows how to import transactions in custom CSV format to FA using reader format configuration and a Camel route. The highlights of this sample are:
Creating a reader format configuration to convert the custom file format to FA transaction import format.
Setting up a camel route and feeding the file to the reader format configuration and further to the transaction import process.
Starting point
You have a semicolon-separated file that looks like this:
Transaction type;Status;Transaction date;Amount;Price;Trade amount;Parent portfolio Buy;Active;2022-02-08;10;100;1000;Clark Kent
Create the reader format configuration
Go to Preference > Importing > Reader format configuration in FA Back, fill in the fields in the Basic info tab and click next. You can find instructions about the Reader format configuration in the FA Back reference: Preference - Importing.
In this sample, you need to set the field order in the right column according to this:
Type,Status,trasactionDate,Amount,Price,TradeAmount,parentPortfolio
Set up the Camel route
Upload the Camel route in FA back. For the instructions, see Deploy Camel routes
The route below:
Reacts to all files with the name that ends with
Transactions.csv
(antInclude=*Transactions.csv
) placed in the/integrations/customFiles/
directory.Archives the original file in the monthly folders after processing (
move=./history/${date:now:MM_yyyy}/${file:onlyname}
)Feeds the processed file for transaction import mapping directory and adds the mapping name to the processed file name extension (
custom_transactions.custom-reader.csv
). The route knows which reader format configuration to apply by matching the import reader configuration name and the file name, in this case they arecustom-reader
.
<routes xmlns="http://camel.apache.org/schema/spring"> <route id="customTransactionImportMapping"> <from uri="file:{{back.writable.dir}}/integrations/customFiles/?antInclude=*Transactions.csv&autoCreate=true&charset=iso-8859-1&readLock=changed&readLockCheckInterval=5000&moveFailed=.failed&move=./history/${date:now:MM_yyyy}/${file:onlyname}"/> <to uri="file:{{back.writable.dir}}/fa/import/general/csv-auto/mapped-transactions?autoCreate=true&fileName=${file:onlyname.noext}.custom-reader.${file:ext}&charset=iso-8859-1"/> </route> </routes>