jgnash.imports.qif
Class QifImport

java.lang.Object
  extended by jgnash.imports.qif.QifImport

public class QifImport
extends java.lang.Object

QifImport takes a couple of simple steps to prevent importing a duplicate account. Other than that, duplicate transactions will be imported. At this time, it would require a lot of extra and normally unused data to be stored with each transaction and account to prevent duplication. This import utility is ideal for importing an existing data set, but not for importing monthly bank statements. A more specialized import utility may be useful/required for more advanced imports

Version:
$Id$
Author:
Craig Cavanaugh

Field Summary
private  java.util.HashMap<java.lang.String,Account> accountMap
           
private  java.util.ArrayList<Transaction> duplicates
          A holder for duplicate transactions
private  int duplicatesFound
          Holds the number of duplicate transactions that were stripped during the import
private  Engine engine
           
private  java.util.HashMap<java.lang.String,Account> expenseMap
           
private  java.util.HashMap<java.lang.String,Account> incomeMap
           
private  java.util.logging.Logger logger
           
private  QifParser parser
           
private  boolean stripDuplicates
           
private  Account unassignedExpense
           
private  Account unassignedIncome
           
 
Constructor Summary
QifImport()
           
 
Method Summary
private  void addAccounts()
          All of the accounts must be added before the transactions are added because the category (account) must exist first
private  void addCategories()
           
private  void addTransactions(QifAccount qAcc, Account acc)
           
 void doFullImport()
           
 void doFullParse(java.io.File file, java.lang.String dateFormat)
           
 void doPartialImport(Account account)
           
 void doPartialParse(java.io.File file)
           
 void dumpStats()
           
private  Account findBestAccount(java.lang.String category)
          Returns the best matching account
private  Account findBestParent(QifCategory cat, java.util.Map<java.lang.String,Account> map)
          Returns the Account of the best possible parent account for the supplied QifCategory
private  Account generateAccount(QifAccount acc)
           
private  Account generateAccount(QifCategory cat)
           
private  TransactionEntry generateSplitTransaction(QifSplitTransaction qTran, Account acc)
          Generates a Transaction given a QifSplitTransaction
private  Transaction generateTransaction(QifTransaction qTran, Account acc)
          Generates a transaction Notes: If a QifTransaction does not specify an account, then assume it is a single entry transaction for the supplied Account.
 int getDuplicateCount()
          Returns the number of duplicate transactions that were stripped during the import
 Transaction[] getDuplicates()
          Return an array of duplicate transactions that were found
 QifParser getParser()
           
private  void importAccounts()
           
private  void importCategories()
           
private  boolean isAccount(java.lang.String category)
          Determines if the supplied String represents a QIF account
private  boolean isDuplicate(Transaction t, Account a)
           
private  void loadAccountMap()
           
private  void loadAccountMap(Account acc)
           
private  void loadCategoryMap(Account acc, java.util.Map<java.lang.String,Account> map)
           
private  void loadCategoryMap(java.util.List<Account> list, java.util.Map<java.lang.String,Account> map)
           
private  void reduceCategories()
           
private  void removeMirrorSplitTransaction(QifSplitTransaction qTran)
           
private  void removeMirrorTransaction(QifTransaction qTran, Account acc)
           
 void setStripDuplicates(boolean strip)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

private QifParser parser

engine

private Engine engine

expenseMap

private java.util.HashMap<java.lang.String,Account> expenseMap

incomeMap

private java.util.HashMap<java.lang.String,Account> incomeMap

accountMap

private java.util.HashMap<java.lang.String,Account> accountMap

stripDuplicates

private boolean stripDuplicates

duplicates

private java.util.ArrayList<Transaction> duplicates
A holder for duplicate transactions


duplicatesFound

private int duplicatesFound
Holds the number of duplicate transactions that were stripped during the import


logger

private java.util.logging.Logger logger

unassignedExpense

private Account unassignedExpense

unassignedIncome

private Account unassignedIncome
Constructor Detail

QifImport

public QifImport()
Method Detail

getParser

public QifParser getParser()

setStripDuplicates

public void setStripDuplicates(boolean strip)

doFullParse

public void doFullParse(java.io.File file,
                        java.lang.String dateFormat)
                 throws NoAccountException
Throws:
NoAccountException

doFullImport

public void doFullImport()

doPartialParse

public void doPartialParse(java.io.File file)

doPartialImport

public void doPartialImport(Account account)

dumpStats

public void dumpStats()

importCategories

private void importCategories()

importAccounts

private void importAccounts()

loadCategoryMap

private void loadCategoryMap(java.util.List<Account> list,
                             java.util.Map<java.lang.String,Account> map)

loadCategoryMap

private void loadCategoryMap(Account acc,
                             java.util.Map<java.lang.String,Account> map)

loadAccountMap

private void loadAccountMap()

loadAccountMap

private void loadAccountMap(Account acc)

addAccounts

private void addAccounts()
All of the accounts must be added before the transactions are added because the category (account) must exist first


addTransactions

private void addTransactions(QifAccount qAcc,
                             Account acc)

isDuplicate

private boolean isDuplicate(Transaction t,
                            Account a)

getDuplicateCount

public int getDuplicateCount()
Returns the number of duplicate transactions that were stripped during the import

Returns:
number of duplicates found

getDuplicates

public Transaction[] getDuplicates()
Return an array of duplicate transactions that were found


addCategories

private void addCategories()

findBestParent

private Account findBestParent(QifCategory cat,
                               java.util.Map<java.lang.String,Account> map)
Returns the Account of the best possible parent account for the supplied QifCategory


findBestAccount

private Account findBestAccount(java.lang.String category)
Returns the best matching account


isAccount

private boolean isAccount(java.lang.String category)
Determines if the supplied String represents a QIF account


reduceCategories

private void reduceCategories()

generateAccount

private Account generateAccount(QifCategory cat)

generateAccount

private Account generateAccount(QifAccount acc)

generateTransaction

private Transaction generateTransaction(QifTransaction qTran,
                                        Account acc)
Generates a transaction Notes: If a QifTransaction does not specify an account, then assume it is a single entry transaction for the supplied Account. The transaction most likely came from a online banking source.


generateSplitTransaction

private TransactionEntry generateSplitTransaction(QifSplitTransaction qTran,
                                                  Account acc)
Generates a Transaction given a QifSplitTransaction


removeMirrorTransaction

private void removeMirrorTransaction(QifTransaction qTran,
                                     Account acc)

removeMirrorSplitTransaction

private void removeMirrorSplitTransaction(QifSplitTransaction qTran)