use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BayesImportClassifier method generateClassifier.
private static BayesClassifier<Account> generateClassifier(List<Transaction> transactions, final Account baseAccount) {
final BayesClassifier<Account> classifier = new BayesClassifier<>(baseAccount);
for (final Transaction t : transactions) {
final Set<Account> accountSet = t.getAccounts();
accountSet.remove(baseAccount);
for (final Account account : accountSet) {
if (!t.getPayee().isEmpty()) {
classifier.train(t.getPayee(), account);
}
if (!t.getMemo().isEmpty()) {
classifier.train(t.getMemo(), account);
}
}
}
return classifier;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class GenericImport method findFirstAvailableAccount.
public static Account findFirstAvailableAccount() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
for (final Account account : engine.getAccountList()) {
if (!account.isPlaceHolder() && !account.isLocked()) {
return account;
}
}
return null;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class QifImport method addAccounts.
/**
* All of the accounts must be added before the transactions are added because the category (account) must exist
* first
*/
private void addAccounts() {
logger.info("*** Importing Accounts ***");
List<QifAccount> list = parser.accountList;
// add all of the accounts first
for (QifAccount qAcc : list) {
Account acc;
if (!accountMap.containsKey(qAcc.name)) {
// add the account if it does not exist
acc = generateAccount(qAcc);
if (acc != null) {
engine.addAccount(engine.getRootAccount(), acc);
loadAccountMap(acc);
}
}
}
logger.info("*** Importing Transactions ***");
// go back and add the transactions;
for (QifAccount qAcc : list) {
Account acc = accountMap.get(qAcc.name);
// try and match the closest
if (acc == null) {
acc = engine.getAccountByName(qAcc.name);
}
// TODO Correct import of investment transactions
if (acc != null && acc.getAccountType() != AccountType.INVEST) {
addTransactions(qAcc, acc);
} else {
if (acc != null) {
logger.severe("Investment transactions not fully supported");
} else {
logger.log(Level.SEVERE, "Lost the account: {0}", qAcc.name);
}
}
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class QifImport method findBestParent.
/**
* Returns the Account of the best possible parent account for the supplied QifCategory
*
* @param cat imported QifCategory to match
* @param map cached account map
* @return best Account match
*/
private Account findBestParent(final QifCategory cat, final Map<String, Account> map) {
int i = cat.name.lastIndexOf(':');
if (i != -1) {
String pathName = cat.name.substring(0, i);
while (true) {
if (map.containsKey(pathName)) {
return map.get(pathName);
}
int j = pathName.lastIndexOf(':');
if (j != -1) {
pathName = pathName.substring(0, j);
} else {
break;
}
}
}
Account parent;
if (cat.type.equals("E")) {
parent = ImportUtils.getRootExpenseAccount();
} else {
parent = ImportUtils.getRootIncomeAccount();
}
if (parent != null) {
return parent;
}
return engine.getRootAccount();
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class QifImport method addCategories.
private void addCategories() {
List<QifCategory> list = parser.categories;
Map<String, Account> map;
for (QifCategory cat : list) {
Account acc = generateAccount(cat);
if (acc.getAccountType() == AccountType.EXPENSE) {
map = expenseMap;
} else {
map = incomeMap;
}
Account parent = findBestParent(cat, map);
engine.addAccount(parent, acc);
loadCategoryMap(acc, map);
}
}
Aggregations