use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class ImportUtils method createSecurityNode.
static SecurityNode createSecurityNode(final ImportSecurity security, final CurrencyNode currencyNode) {
final SecurityNode securityNode = new SecurityNode(currencyNode);
securityNode.setSymbol(security.getTicker());
securityNode.setScale(currencyNode.getScale());
security.getSecurityName().ifPresent(securityNode::setDescription);
security.getId().ifPresent(securityNode::setISIN);
return securityNode;
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class SecuritiesHistoryDialog method changeNode.
private void changeNode() {
SecurityNode node = securityCombo.getSelectedSecurityNode();
if (node != null) {
updateChart();
model.setSecurity(node);
closeField.setScale(node.getScale());
lowField.setScale(node.getScale());
highField.setScale(node.getScale());
updateButton.setEnabled(node.getQuoteSource() != QuoteSource.NONE);
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class SecurityModifyPanel method messagePosted.
@Override
public void messagePosted(final Message event) {
if (event.getObject(MessageProperty.COMMODITY) instanceof SecurityNode) {
final SecurityNode node = event.getObject(MessageProperty.COMMODITY);
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case SECURITY_REMOVE:
model.removeElement(node);
clearForm();
break;
case SECURITY_REMOVE_FAILED:
String message = "Commodity " + node + " cannot be removed";
JOptionPane.showMessageDialog(SecurityModifyPanel.this, message, rb.getString("Message.Warn.CommodityInUse"), JOptionPane.WARNING_MESSAGE);
break;
case SECURITY_ADD:
clearForm();
model.addElement(node);
break;
case SECURITY_ADD_FAILED:
JOptionPane.showMessageDialog(SecurityModifyPanel.this, rb.getString("Message.Error.AddCommodity"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
case SECURITY_MODIFY:
clearForm();
// force load of new instance
model.removeElement(node);
model.addElement(node);
model.fireContentsChanged();
break;
case SECURITY_MODIFY_FAILED:
JOptionPane.showMessageDialog(SecurityModifyPanel.this, rb.getString("Message.Error.ModifyCommodity"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
default:
}
});
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class OfxImport method importInvestmentTransaction.
private static InvestmentTransaction importInvestmentTransaction(final OfxBank ofxBank, final ImportTransaction ofxTransaction, final Account investmentAccount) {
final SecurityNode securityNode = matchSecurity(ofxBank, ofxTransaction.getSecurityId());
final String memo = ofxTransaction.getMemo();
final LocalDate datePosted = ofxTransaction.getDatePosted();
final BigDecimal units = ofxTransaction.getUnits();
final BigDecimal unitPrice = ofxTransaction.getUnitPrice();
final Account incomeAccount = ofxTransaction.getGainsAccount();
final Account fessAccount = ofxTransaction.getFeesAccount();
Account cashAccount = ofxTransaction.getAccount();
// force use of cash balance
if (OfxTags.CASH.equals(ofxTransaction.getSubAccount())) {
cashAccount = investmentAccount;
}
final List<TransactionEntry> fees = new ArrayList<>();
final List<TransactionEntry> gains = new ArrayList<>();
if (ofxTransaction.getCommission().compareTo(BigDecimal.ZERO) != 0) {
final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getCommission().negate());
transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
fees.add(transactionEntry);
}
if (ofxTransaction.getFees().compareTo(BigDecimal.ZERO) != 0) {
final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getFees().negate());
transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
fees.add(transactionEntry);
}
InvestmentTransaction transaction = null;
if (securityNode != null) {
switch(ofxTransaction.getTransactionType()) {
case DIVIDEND:
final BigDecimal dividend = ofxTransaction.getAmount();
transaction = TransactionFactory.generateDividendXTransaction(incomeAccount, investmentAccount, cashAccount, securityNode, dividend, dividend, dividend, datePosted, memo);
break;
case REINVESTDIV:
// Create a gains entry of an account other than the investment account has been selected
if (incomeAccount != investmentAccount) {
final TransactionEntry gainsEntry = TransactionFactory.createTransactionEntry(incomeAccount, investmentAccount, ofxTransaction.getAmount().negate(), memo, TransactionTag.GAIN_LOSS);
gains.add(gainsEntry);
}
transaction = TransactionFactory.generateReinvestDividendXTransaction(investmentAccount, securityNode, unitPrice, units, datePosted, memo, fees, gains);
break;
case BUYSHARE:
transaction = TransactionFactory.generateBuyXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees);
break;
case SELLSHARE:
transaction = TransactionFactory.generateSellXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees, gains);
break;
default:
}
}
return transaction;
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class HistoricalImportController method handleStartAction.
@FXML
private void handleStartAction() {
disableUI.set(true);
final DateTimeFormatter dateTimeFormatter = DateUtils.getShortDateFormatter();
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
updateTask = new Task<>() {
@Override
protected Void call() {
final LocalDate startDate = startDatePicker.getValue();
final LocalDate endDate = endDatePicker.getValue();
final Map<SecurityNode, List<SecurityHistoryNode>> historyMap = new HashMap<>();
// create a defensive copy
final List<SecurityNode> securityNodes = new ArrayList<>(checkListView.getCheckedItems());
// need to determine the total count
long historyCount = 0;
// Collect and count the number of nodes
for (final SecurityNode securityNode : securityNodes) {
updateMessage(ResourceUtils.getString("Message.DownloadingX", securityNode.getSymbol()));
try {
final List<SecurityHistoryNode> historyNodes = UpdateFactory.downloadHistory(securityNode, startDate, endDate);
// reverse the sort order
Collections.reverse(historyNodes);
historyCount += historyNodes.size();
historyMap.put(securityNode, historyNodes);
} catch (final IllegalArgumentException iae) {
updateMessage(ResourceUtils.getString("Message.Error.DataSupplierToken", securityNode.getSymbol()));
this.cancel();
}
}
// need to track the total processed count
long processedHistory = 0;
for (final Map.Entry<SecurityNode, List<SecurityHistoryNode>> entry : historyMap.entrySet()) {
if (!requestCancel) {
for (final SecurityHistoryNode historyNode : entry.getValue()) {
if (!requestCancel) {
engine.addSecurityHistory(entry.getKey(), historyNode);
updateProgress(++processedHistory, historyCount);
updateMessage(ResourceUtils.getString("Message.UpdatedPriceDate", entry.getKey().getSymbol(), dateTimeFormatter.format(historyNode.getLocalDate())));
}
}
}
}
updateMessage("");
return null;
}
};
updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, event -> taskComplete());
updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_CANCELLED, event -> taskComplete());
updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_FAILED, event -> taskComplete());
progressBar.progressProperty().bind(updateTask.progressProperty());
messageLabel.textProperty().bind(updateTask.messageProperty());
final Thread thread = new Thread(updateTask);
thread.setDaemon(true);
thread.start();
}
Aggregations