Search in sources :

Example 1 with CurrencyNode

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

the class JpaCommodityDAO method getCurrencies.

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

Example 2 with CurrencyNode

use of jgnash.engine.CurrencyNode 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 3 with CurrencyNode

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

the class NewFileDialog method showDialog.

public static void showDialog(final Frame parent) {
    final class Setup extends SwingWorker<Void, Void> {

        NewFileDialog d;

        public Setup(NewFileDialog dialog) {
            d = dialog;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected Void doInBackground() throws Exception {
            final ResourceBundle rb = ResourceUtils.getBundle();
            UIApplication.getFrame().displayWaitMessage(rb.getString("Message.PleaseWait"));
            final String database = (String) d.getSetting(Settings.DATABASE_NAME);
            final Set<CurrencyNode> nodes = (Set<CurrencyNode>) d.getSetting(Settings.CURRENCIES);
            final CurrencyNode defaultCurrency = (CurrencyNode) d.getSetting(Settings.DEFAULT_CURRENCY);
            final DataStoreType type = (DataStoreType) d.getSetting(Settings.TYPE);
            final String password = (String) d.getSetting(Settings.PASSWORD);
            final List<RootAccount> accountList = (List<RootAccount>) d.getSetting(Settings.ACCOUNT_SET);
            try {
                NewFileUtility.buildNewFile(database, type, password.toCharArray(), defaultCurrency, nodes, accountList);
                // force a save and reload of the file
                EngineFactory.closeEngine(EngineFactory.DEFAULT);
                EngineFactory.bootLocalEngine(database, EngineFactory.DEFAULT, password.toCharArray());
            } catch (final IOException e) {
                StaticUIMethods.displayError(e.getMessage());
            }
            return null;
        }

        @Override
        protected void done() {
            UIApplication.getFrame().stopWaitMessage();
        }
    }
    class DisplayDialog extends SwingWorker<Set<CurrencyNode>, Object> {

        @Override
        public Set<CurrencyNode> doInBackground() {
            return DefaultCurrencies.generateCurrencies();
        }

        @Override
        protected void done() {
            try {
                NewFileDialog d = new NewFileDialog(parent);
                d.setSetting(NewFileDialog.Settings.DEFAULT_CURRENCIES, get());
                d.setSetting(NewFileDialog.Settings.DATABASE_NAME, EngineFactory.getDefaultDatabase());
                d.addTaskPage(new NewFileOne());
                d.addTaskPage(new NewFileTwo());
                d.addTaskPage(new NewFileThree());
                d.addTaskPage(new NewFileFour());
                d.addTaskPage(new NewFileSummary());
                d.setLocationRelativeTo(parent);
                d.setVisible(true);
                if (d.isWizardValid()) {
                    new Setup(d).execute();
                }
            } catch (InterruptedException | ExecutionException e) {
                Logger.getLogger(DisplayDialog.class.getName()).log(Level.SEVERE, null, e);
            }
        }
    }
    new DisplayDialog().execute();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Set(java.util.Set) IOException(java.io.IOException) DataStoreType(jgnash.engine.DataStoreType) RootAccount(jgnash.engine.RootAccount) SwingWorker(javax.swing.SwingWorker) ResourceBundle(java.util.ResourceBundle) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with CurrencyNode

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

the class NewFileThree method addAction.

private void addAction() {
    CurrencyNode obj = aJList.getSelectedValue();
    if (obj != null) {
        aList.removeElement(obj);
        cList.addElement(obj);
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode)

Example 5 with CurrencyNode

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

the class BudgetResultsExportTest method testExportBudgetResultsModel.

@Test
public void testExportBudgetResultsModel() throws Exception {
    final String file = Files.createTempFile("budget-", DataStoreType.XML.getDataStore().getFileExt()).toString();
    EngineFactory.deleteDatabase(file);
    Engine e = EngineFactory.bootLocalEngine(file, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD, DataStoreType.XML);
    e.setCreateBackups(false);
    CurrencyNode node = e.getDefaultCurrency();
    Account account1 = new Account(AccountType.EXPENSE, node);
    account1.setName("Expense 1");
    e.addAccount(e.getRootAccount(), account1);
    Account account2 = new Account(AccountType.EXPENSE, node);
    account2.setName("Expense 2");
    e.addAccount(e.getRootAccount(), account2);
    Budget budget = new Budget();
    budget.setName("My Budget");
    budget.setDescription("Test");
    budget.setBudgetPeriod(Period.MONTHLY);
    assertTrue(e.addBudget(budget));
    BudgetResultsModel model = new BudgetResultsModel(budget, 2012, node, false);
    final Path exportFile = Files.createTempFile("testworkbook", ".xls");
    BudgetResultsExport.exportBudgetResultsModel(exportFile, model);
    assertTrue(Files.exists(exportFile));
    Files.delete(exportFile);
    EngineFactory.closeEngine(EngineFactory.DEFAULT);
    Files.deleteIfExists(Paths.get(file));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Path(java.nio.file.Path) Account(jgnash.engine.Account) Engine(jgnash.engine.Engine) Test(org.junit.Test)

Aggregations

CurrencyNode (jgnash.engine.CurrencyNode)58 Account (jgnash.engine.Account)28 Engine (jgnash.engine.Engine)28 BigDecimal (java.math.BigDecimal)10 ArrayList (java.util.ArrayList)10 LocalDate (java.time.LocalDate)8 NumberFormat (java.text.NumberFormat)7 List (java.util.List)7 FXML (javafx.fxml.FXML)7 AccountGroup (jgnash.engine.AccountGroup)7 Transaction (jgnash.engine.Transaction)6 ResourceBundle (java.util.ResourceBundle)5 SecurityNode (jgnash.engine.SecurityNode)5 InjectFXML (jgnash.uifx.util.InjectFXML)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 ExecutionException (java.util.concurrent.ExecutionException)3