use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method setRetainedBackupLimit.
public void setRetainedBackupLimit(final int retainedBackupLimit) {
dataLock.writeLock().lock();
try {
final Config backupConfig = getConfig();
backupConfig.setRetainedBackupLimit(retainedBackupLimit);
getConfigDAO().update(backupConfig);
// clear stale cached reference
config = null;
Message message = new Message(MessageChannel.CONFIG, ChannelEvent.CONFIG_MODIFY, this);
message.setObject(MessageProperty.CONFIG, backupConfig);
messageBus.fireEvent(message);
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method toggleAccountVisibility.
/**
* Toggles the visibility of an account given its ID.
*
* @param account The account to toggle visibility
*/
public void toggleAccountVisibility(final Account account) {
dataLock.writeLock().lock();
try {
Message message;
account.setVisible(!account.isVisible());
if (getAccountDAO().toggleAccountVisibility(account)) {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_VISIBILITY_CHANGE, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
} else {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_VISIBILITY_CHANGE_FAILED, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
}
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method removeAccountSecurity.
/**
* Removes a SecurityNode from an InvestmentAccount.
*
* @param account Account to remove SecurityNode from
* @param node SecurityNode to remove
* @return true if successful
*/
private boolean removeAccountSecurity(final Account account, final SecurityNode node) {
Objects.requireNonNull(node);
dataLock.writeLock().lock();
try {
Message message;
boolean result = account.removeSecurity(node);
if (result) {
getAccountDAO().updateAccount(account);
}
if (result) {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_SECURITY_REMOVE, this);
} else {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_SECURITY_REMOVE_FAILED, this);
}
message.setObject(MessageProperty.ACCOUNT, account);
message.setObject(MessageProperty.COMMODITY, node);
messageBus.fireEvent(message);
return result;
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method removeExchangeRateHistory.
public void removeExchangeRateHistory(final ExchangeRate exchangeRate, final ExchangeRateHistoryNode history) {
dataLock.writeLock().lock();
try {
final Message message;
boolean result = false;
if (exchangeRate.contains(history)) {
if (exchangeRate.removeHistoryNode(history)) {
moveObjectToTrash(history);
result = getCommodityDAO().removeExchangeRateHistory(exchangeRate);
}
}
if (result) {
message = new Message(MessageChannel.COMMODITY, ChannelEvent.EXCHANGE_RATE_REMOVE, this);
} else {
message = new Message(MessageChannel.COMMODITY, ChannelEvent.EXCHANGE_RATE_REMOVE_FAILED, this);
}
message.setObject(MessageProperty.EXCHANGE_RATE, exchangeRate);
messageBus.fireEvent(message);
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method addSecurityHistoryEvent.
/**
* Add a SecurityHistoryNode node to a SecurityNode. If the SecurityNode already contains
* an equivalent SecurityHistoryNode, the old SecurityHistoryNode is removed first.
*
* @param node SecurityNode to add to
* @param historyEvent SecurityHistoryNode to add
* @return <tt>true</tt> if successful
*/
public boolean addSecurityHistoryEvent(@NotNull final SecurityNode node, @NotNull final SecurityHistoryEvent historyEvent) {
dataLock.writeLock().lock();
try {
// Remove old history event if it exists, equality is used to work around hibernate optimizations
// A defensive copy of the old events is used to prevent concurrent modification errors
new HashSet<>(node.getHistoryEvents()).stream().filter(event -> event.equals(historyEvent)).forEach(event -> removeSecurityHistoryEvent(node, historyEvent));
boolean status = node.addSecurityHistoryEvent(historyEvent);
if (status) {
status = getCommodityDAO().addSecurityHistoryEvent(node, historyEvent);
}
Message message;
if (status) {
clearCachedAccountBalance(node);
message = new Message(MessageChannel.COMMODITY, ChannelEvent.SECURITY_HISTORY_EVENT_ADD, this);
} else {
message = new Message(MessageChannel.COMMODITY, ChannelEvent.SECURITY_HISTORY_EVENT_ADD_FAILED, this);
}
message.setObject(MessageProperty.COMMODITY, node);
messageBus.fireEvent(message);
return status;
} finally {
dataLock.writeLock().unlock();
}
}
Aggregations