use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method removeSecurityHistory.
/**
* Remove a {@code SecurityHistoryNode} given a {@code Date}.
*
* @param node {@code SecurityNode} to remove history from
* @param date the search {@code Date}
* @return {@code true} if a {@code SecurityHistoryNode} was found and removed
*/
public boolean removeSecurityHistory(@NotNull final SecurityNode node, @NotNull final LocalDate date) {
dataLock.writeLock().lock();
boolean status = false;
try {
final Optional<SecurityHistoryNode> optional = node.getHistoryNode(date);
if (optional.isPresent()) {
status = node.removeHistoryNode(date);
if (status) {
// removal was a success, make sure we cleanup properly
moveObjectToTrash(optional.get());
status = getCommodityDAO().removeSecurityHistory(node, optional.get());
logInfo(ResourceUtils.getString("Message.RemovingSecurityHistory", date, node.getSymbol()));
}
}
Message message;
if (status) {
clearCachedAccountBalance(node);
message = new Message(MessageChannel.COMMODITY, ChannelEvent.SECURITY_HISTORY_REMOVE, this);
} else {
message = new Message(MessageChannel.COMMODITY, ChannelEvent.SECURITY_HISTORY_REMOVE_FAILED, this);
}
message.setObject(MessageProperty.COMMODITY, node);
messageBus.fireEvent(message);
return status;
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method addBudget.
public boolean addBudget(final Budget budget) {
boolean result;
dataLock.writeLock().lock();
try {
Message message;
result = getBudgetDAO().add(budget);
if (result) {
message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_ADD, this);
} else {
message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_ADD_FAILED, this);
}
message.setObject(MessageProperty.BUDGET, budget);
messageBus.fireEvent(message);
return result;
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method removeBudget.
public boolean removeBudget(final Budget budget) {
boolean result = false;
dataLock.writeLock().lock();
try {
moveObjectToTrash(budget);
Message message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_REMOVE, this);
message.setObject(MessageProperty.BUDGET, budget);
messageBus.fireEvent(message);
result = true;
} catch (final Exception ex) {
logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
} finally {
dataLock.writeLock().unlock();
}
return result;
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method setTransactionNumberList.
public void setTransactionNumberList(final List<String> list) {
dataLock.writeLock().lock();
try {
final Config transactionConfig = getConfig();
transactionConfig.setTransactionNumberList(list);
getConfigDAO().update(transactionConfig);
Message message = new Message(MessageChannel.CONFIG, ChannelEvent.CONFIG_MODIFY, this);
message.setObject(MessageProperty.CONFIG, transactionConfig);
messageBus.fireEvent(message);
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method setAccountCode.
/**
* Changes an Account's code.
*
* @param account Account to change
* @param code new code
* @return true is successful
*/
public boolean setAccountCode(final Account account, final int code) {
account.setAccountCode(code);
boolean result = getAccountDAO().updateAccount(account);
if (result) {
final Message message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
logInfo(rb.getString("Message.AccountModify"));
} else {
final Message message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY_FAILED, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
}
return result;
}
Aggregations