Search in sources :

Example 1 with SecurityNode

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

the class JpaCommodityDAO method getSecurities.

/*
     * @see jgnash.engine.dao.CommodityDAO#getSecurities()
     */
@Override
@NotNull
public List<SecurityNode> getSecurities() {
    List<SecurityNode> securityNodeList = Collections.emptyList();
    try {
        Future<List<SecurityNode>> future = executorService.submit(() -> {
            emLock.lock();
            try {
                final CriteriaBuilder cb = em.getCriteriaBuilder();
                final CriteriaQuery<SecurityNode> cq = cb.createQuery(SecurityNode.class);
                Root<SecurityNode> root = cq.from(SecurityNode.class);
                cq.select(root);
                TypedQuery<SecurityNode> q = em.createQuery(cq);
                return stripMarkedForRemoval(new ArrayList<>(q.getResultList()));
            } finally {
                emLock.unlock();
            }
        });
        securityNodeList = future.get();
    } catch (final InterruptedException | ExecutionException e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    return securityNodeList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SecurityNode(jgnash.engine.SecurityNode) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) NotNull(jgnash.util.NotNull)

Example 2 with SecurityNode

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

the class AccountSecuritiesPanel method setSecuritiesList.

void setSecuritiesList(final Set<SecurityNode> list) {
    selectedModel = new SortedListModel<>();
    if (account != null) {
        Set<SecurityNode> used = account.getUsedSecurities();
        for (SecurityNode node : list) {
            if (used.contains(node)) {
                selectedModel.addElement(new SecurityElement(node, false));
            } else {
                selectedModel.addElement(new SecurityElement(node, true));
            }
        }
    } else {
        for (SecurityNode node : list) {
            selectedModel.addElement(new SecurityElement(node, true));
        }
    }
    selectedJList.setModel(selectedModel);
    buildAvailableList();
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 3 with SecurityNode

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

the class AccountTools method createAccount.

static void createAccount(final Account account) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Account parentAccount = account;
    final ResourceBundle rb = ResourceUtils.getBundle();
    if (parentAccount == null) {
        parentAccount = engine.getRootAccount();
        if (parentAccount == null) {
            // no root account at all, file was closed
            return;
        }
    }
    AccountDialog dlg = new AccountDialog();
    dlg.setParentAccount(parentAccount);
    dlg.setAccountType(parentAccount.getAccountType());
    dlg.setTitle(rb.getString("Title.NewAccount"));
    dlg.setVisible(true);
    if (dlg.returnStatus()) {
        CurrencyNode currency = dlg.getCurrency();
        AccountType accType = dlg.getAccountType();
        if (currency == null) {
            currency = engine.getRootAccount().getCurrencyNode();
            Logger.getLogger(AccountTools.class.getName()).warning("Forcing use of the default currency");
        }
        Account newAccount = new Account(accType, currency);
        if (accType.getAccountGroup() == AccountGroup.INVEST) {
            Collection<SecurityNode> collection = dlg.getAccountSecurities();
            collection.forEach(newAccount::addSecurity);
        }
        newAccount.setName(dlg.getAccountName());
        newAccount.setAccountCode(dlg.getAccountCode());
        newAccount.setAccountNumber(dlg.getAccountNumber());
        newAccount.setBankId(dlg.getBankId());
        newAccount.setDescription(dlg.getAccountDescription());
        newAccount.setNotes(dlg.getAccountNotes());
        newAccount.setLocked(dlg.isAccountLocked());
        newAccount.setPlaceHolder(dlg.isAccountPlaceholder());
        newAccount.setVisible(dlg.isAccountVisible());
        newAccount.setExcludedFromBudget(dlg.isExcludedFromBudget());
        engine.addAccount(dlg.getParentAccount(), newAccount);
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) Engine(jgnash.engine.Engine)

Example 4 with SecurityNode

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

the class AccountPanel method updateCommodityText.

private void updateCommodityText() {
    if (!commodityList.isEmpty()) {
        StringBuilder buf = new StringBuilder();
        Iterator<SecurityNode> it = commodityList.iterator();
        SecurityNode node = it.next();
        buf.append(node.getSymbol());
        while (it.hasNext()) {
            buf.append(", ");
            node = it.next();
            buf.append(node.getSymbol());
        }
        securityButton.setText(buf.toString());
        securityButton.setToolTipText(buf.toString());
    } else {
        securityButton.setText(rb.getString("Word.None"));
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 5 with SecurityNode

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

the class YahooSecurityHistoryImportDialog method doImport.

private void doImport() {
    bar.setIndeterminate(true);
    // do not allow another start
    okButton.setEnabled(false);
    final LocalDate start = startField.getLocalDate();
    final LocalDate end = endField.getLocalDate();
    int[] list = securityList.getSelectedIndices();
    SecurityNode[] nodes = new SecurityNode[list.length];
    for (int i = 0; i < list.length; i++) {
        nodes[i] = securityList.getModel().getElementAt(list[i]);
    }
    // create the runnable and start the thread
    run = new ImportRun(nodes, start, end);
    new Thread(run, "doImport").start();
}
Also used : SecurityNode(jgnash.engine.SecurityNode) LocalDate(java.time.LocalDate)

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