use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrencyModifyDialog method buildCommodityNode.
private CurrencyNode buildCommodityNode() {
CurrencyNode node = new CurrencyNode();
node.setDescription(descriptionField.getText());
node.setPrefix(prefixField.getText());
node.setScale(Byte.parseByte(scaleField.getText()));
node.setSuffix(suffixField.getText());
if (currentCurrency != null) {
node.setSymbol(currentCurrency.getSymbol());
} else {
node.setSymbol(symbolField.getText());
}
return node;
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrenciesPanel method customAction.
private void customAction() {
if (!customField.getText().isEmpty()) {
if (engine.getCurrency(customField.getText()) != null) {
ValidationFactory.showValidationError(rb.getString("Message.Error.Duplicate"), customField);
} else {
CurrencyNode node = DefaultCurrencies.buildCustomNode(customField.getText());
// the add could fail if the commodity symbol is a duplicate
if (engine.addCurrency(node)) {
cList.addElement(new CurrencyElement(node, true));
customField.setText(null);
return;
}
}
}
ValidationFactory.showValidationError(rb.getString("Message.Error.MissingSymbol"), customField);
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrenciesPanel method buildLists.
private void buildLists() {
Set<CurrencyNode> defaultNodes = DefaultCurrencies.generateCurrencies();
Set<CurrencyNode> activeNodes = engine.getActiveCurrencies();
List<CurrencyNode> availNodes = engine.getCurrencies();
availNodes.forEach(defaultNodes::remove);
aList = new SortedListModel<>(defaultNodes);
aJList = new JList<>(aList);
ArrayList<CurrencyElement> list = new ArrayList<>();
for (CurrencyNode node : availNodes) {
if (activeNodes.contains(node)) {
list.add(new CurrencyElement(node, false));
} else {
list.add(new CurrencyElement(node, true));
}
}
cList = new SortedListModel<>(list);
cJList = new JList<>(cList);
cJList.setCellRenderer(new CurrencyRenderer(cJList.getCellRenderer()));
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class GenericImport method importSecurities.
public static void importSecurities(final List<ImportSecurity> importSecurities, final CurrencyNode currencyNode) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
for (final ImportSecurity importSecurity : importSecurities) {
if (ImportUtils.matchSecurity(importSecurity).isEmpty()) {
// Import only if a match is not found
final SecurityNode securityNode = ImportUtils.createSecurityNode(importSecurity, currencyNode);
// link the security node
importSecurity.setSecurityNode(securityNode);
engine.addSecurity(securityNode);
// if the ImportSecurity has pricing information, import it as well
importSecurity.getLocalDate().ifPresent(localDate -> importSecurity.getUnitPrice().ifPresent(price -> {
SecurityHistoryNode securityHistoryNode = new SecurityHistoryNode(localDate, price, 0, price, price);
engine.addSecurityHistory(securityNode, securityHistoryNode);
}));
} else {
// check to see if the cuspid needs to be updated
// link the security node
ImportUtils.matchSecurity(importSecurity).ifPresent(importSecurity::setSecurityNode);
ImportUtils.matchSecurity(importSecurity).ifPresent(securityNode -> importSecurity.getId().ifPresent(securityId -> {
if (securityNode.getISIN() == null || securityNode.getISIN().isEmpty()) {
try {
final SecurityNode clone = (SecurityNode) securityNode.clone();
clone.setISIN(securityId);
engine.updateCommodity(securityNode, clone);
Logger.getLogger(GenericImport.class.getName()).info("Assigning CUSPID");
} catch (final CloneNotSupportedException e) {
Logger.getLogger(GenericImport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}));
}
}
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class OfxImport method matchAccount.
public static Account matchAccount(final OfxBank bank) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final String number = bank.accountId;
final CurrencyNode node = engine.getCurrency(bank.currency);
Account account = null;
if (node != null) {
for (Account a : engine.getAccountList()) {
if (a.getAccountNumber() != null && a.getAccountNumber().equals(number) && a.getCurrencyNode().equals(node)) {
account = a;
break;
}
}
} else if (number != null) {
for (Account a : engine.getAccountList()) {
if (a.getAccountNumber().equals(number)) {
account = a;
break;
}
}
}
return account;
}
Aggregations