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;
}
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);
}
}
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();
}
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);
}
}
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));
}
Aggregations