use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method setAccountSeparator.
public void setAccountSeparator(final String separator) {
dataLock.writeLock().lock();
try {
accountSeparator = separator;
Config localConfig = getConfig();
localConfig.setAccountSeparator(separator);
getConfigDAO().update(localConfig);
Message message = new Message(MessageChannel.CONFIG, ChannelEvent.CONFIG_MODIFY, this);
message.setObject(MessageProperty.CONFIG, localConfig);
messageBus.fireEvent(message);
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method removeReminder.
public boolean removeReminder(final Reminder reminder) {
boolean result = false;
if (moveObjectToTrash(reminder)) {
if (reminder.getTransaction() != null) {
moveObjectToTrash(reminder.getTransaction());
reminder.setTransaction(null);
}
Message message = new Message(MessageChannel.REMINDER, ChannelEvent.REMINDER_REMOVE, this);
message.setObject(MessageProperty.REMINDER, reminder);
messageBus.fireEvent(message);
result = true;
}
return result;
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method addAccount.
/**
* Adds a new account.
*
* @param parent The parent account
* @param child A new Account object
* @return true if successful
*/
public boolean addAccount(final Account parent, final Account child) {
Objects.requireNonNull(child);
Objects.requireNonNull(child.getUuid());
if (child.getAccountType() == AccountType.ROOT) {
throw new RuntimeException("Invalid Account");
}
dataLock.writeLock().lock();
try {
Message message;
boolean result;
result = parent.addChild(child);
if (result) {
result = getAccountDAO().addAccount(parent, child);
}
if (result) {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_ADD, this);
message.setObject(MessageProperty.ACCOUNT, child);
messageBus.fireEvent(message);
logInfo(rb.getString("Message.AccountAdd"));
result = true;
} else {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_ADD_FAILED, this);
message.setObject(MessageProperty.ACCOUNT, child);
messageBus.fireEvent(message);
result = false;
}
return result;
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method addSecurity.
/**
* Adds a new SecurityNode to the data set.
* <p>
* Checks and prevents the addition of a duplicate SecurityNode.
*
* @param node new SecurityNode to add
* @return {@code true} if the add it successful
*/
public boolean addSecurity(final SecurityNode node) {
dataLock.writeLock().lock();
try {
boolean status = isCommodityNodeValid(node);
if (status) {
if (getSecurity(node.getSymbol()) != null) {
logger.log(Level.INFO, "Prevented addition of a duplicate SecurityNode: {0}", node.getSymbol());
status = false;
}
}
if (status) {
status = getCommodityDAO().addCommodity(node);
logger.log(Level.FINE, "Adding: {0}", node.toString());
}
Message message;
if (status) {
message = new Message(MessageChannel.COMMODITY, ChannelEvent.SECURITY_ADD, this);
} else {
message = new Message(MessageChannel.COMMODITY, ChannelEvent.SECURITY_ADD_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 removeAccount.
/**
* Removes an existing account given it's ID.
*
* @param account The account to remove
* @return true if successful
*/
public boolean removeAccount(final Account account) {
dataLock.writeLock().lock();
try {
boolean result = false;
if (account.getTransactionCount() > 0 || account.getChildCount() > 0) {
result = false;
} else {
Account parent = account.getParent();
if (parent != null) {
result = parent.removeChild(account);
if (result) {
getAccountDAO().updateAccount(parent);
// clear budget history
purgeBudgetGoal(account);
}
}
moveObjectToTrash(account);
}
Message message;
if (result) {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_REMOVE, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
logInfo(rb.getString("Message.AccountRemove"));
} else {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_REMOVE_FAILED, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
}
return result;
} finally {
dataLock.writeLock().unlock();
}
}
Aggregations