Search in sources :

Example 16 with Message

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();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 17 with Message

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;
}
Also used : Message(jgnash.engine.message.Message)

Example 18 with Message

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();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 19 with Message

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();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 20 with Message

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();
    }
}
Also used : Message(jgnash.engine.message.Message)

Aggregations

Message (jgnash.engine.message.Message)46 MessageBus (jgnash.engine.message.MessageBus)9 List (java.util.List)7 Objects (java.util.Objects)7 MessageChannel (jgnash.engine.message.MessageChannel)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ResourceBundle (java.util.ResourceBundle)6 Level (java.util.logging.Level)6 Logger (java.util.logging.Logger)6 ResourceUtils (jgnash.util.ResourceUtils)6 BigDecimal (java.math.BigDecimal)5 Optional (java.util.Optional)5 ExecutionException (java.util.concurrent.ExecutionException)5 Budget (jgnash.engine.budget.Budget)5 ChannelEvent (jgnash.engine.message.ChannelEvent)5 MessageProperty (jgnash.engine.message.MessageProperty)5 LocalDate (java.time.LocalDate)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4