Search in sources :

Example 11 with SecurityNode

use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.

the class SecurityModifyPanel method buildSecurityNode.

private SecurityNode buildSecurityNode() {
    SecurityNode node = new SecurityNode(currencyCombo.getSelectedNode());
    node.setDescription(descriptionField.getText());
    node.setScale(Byte.parseByte(scaleField.getText()));
    node.setSymbol(symbolField.getText().trim());
    node.setISIN(isinField.getText().trim());
    node.setQuoteSource((QuoteSource) sourceComboBox.getSelectedItem());
    return node;
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 12 with SecurityNode

use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.

the class SecurityModifyPanel method updateForm.

private void updateForm() {
    SecurityNode node = securityList.getSelectedValue();
    if (node != null) {
        symbolField.setText(node.getSymbol());
        isinField.setText(node.getISIN());
        descriptionField.setText(node.getDescription());
        scaleField.setText(Short.toString(node.getScale()));
        currencyCombo.setSelectedNode(node.getReportedCurrencyNode());
        sourceComboBox.setSelectedItem(node.getQuoteSource());
        isModifying = true;
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 13 with SecurityNode

use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.

the class AbstractRegisterPanel method messagePosted.

@Override
public void messagePosted(final Message event) {
    final Account account = getAccount();
    // must update on EDT or a deadlock can occur
    EventQueue.invokeLater(() -> {
        Account a = event.getObject(MessageProperty.ACCOUNT);
        if (account.equals(a)) {
            switch(event.getEvent()) {
                case ACCOUNT_MODIFY:
                    updateAccountState();
                    updateAccountInfo();
                    break;
                case TRANSACTION_ADD:
                    final Transaction t = event.getObject(MessageProperty.TRANSACTION);
                    final int index = account.indexOf(t);
                    if (index == account.getTransactionCount() - 1) {
                        autoScroll();
                    }
                    setSelectedTransaction(t);
                    updateAccountInfo();
                    break;
                case TRANSACTION_REMOVE:
                    updateAccountInfo();
                    break;
                default:
                    break;
            }
        }
        if (event.getEvent() == ChannelEvent.SECURITY_HISTORY_ADD || event.getEvent() == ChannelEvent.SECURITY_HISTORY_REMOVE) {
            SecurityNode node = event.getObject(MessageProperty.COMMODITY);
            if (account.containsSecurity(node)) {
                updateAccountInfo();
            }
        }
    });
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) SecurityNode(jgnash.engine.SecurityNode)

Example 14 with SecurityNode

use of jgnash.engine.SecurityNode 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);
                    }
                }
            }));
        }
    }
}
Also used : Engine(jgnash.engine.Engine) DateUtils(jgnash.time.DateUtils) NotNull(jgnash.util.NotNull) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) Logger(java.util.logging.Logger) SecurityNode(jgnash.engine.SecurityNode) Level(java.util.logging.Level) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) List(java.util.List) LocalDate(java.time.LocalDate) Account(jgnash.engine.Account) CurrencyNode(jgnash.engine.CurrencyNode) TransactionFactory(jgnash.engine.TransactionFactory) SecurityNode(jgnash.engine.SecurityNode) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Engine(jgnash.engine.Engine)

Example 15 with SecurityNode

use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.

the class ImportUtils method matchSecurity.

static Optional<SecurityNode> matchSecurity(final ImportSecurity security) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final SecurityNode securityNode : engine.getSecurities()) {
        if (securityNode.getSymbol().equals(security.getTicker())) {
            return Optional.of(securityNode);
        }
    }
    return Optional.empty();
}
Also used : SecurityNode(jgnash.engine.SecurityNode) Engine(jgnash.engine.Engine)

Aggregations

SecurityNode (jgnash.engine.SecurityNode)39 Engine (jgnash.engine.Engine)12 Account (jgnash.engine.Account)10 SecurityHistoryNode (jgnash.engine.SecurityHistoryNode)8 LocalDate (java.time.LocalDate)7 ArrayList (java.util.ArrayList)6 AbstractEngineTest (jgnash.engine.AbstractEngineTest)6 Test (org.junit.jupiter.api.Test)6 CurrencyNode (jgnash.engine.CurrencyNode)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 List (java.util.List)4 QuoteSource (jgnash.engine.QuoteSource)4 SecurityParser (jgnash.net.security.SecurityParser)4 FXML (javafx.fxml.FXML)3 InvestmentTransaction (jgnash.engine.InvestmentTransaction)3 SecurityHistoryEvent (jgnash.engine.SecurityHistoryEvent)3 Transaction (jgnash.engine.Transaction)3 IEXParser (jgnash.net.security.iex.IEXParser)3 InjectFXML (jgnash.uifx.util.InjectFXML)3 NotNull (jgnash.util.NotNull)3