Search in sources :

Example 21 with Message

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

Example 22 with Message

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

Example 23 with Message

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;
}
Also used : Message(jgnash.engine.message.Message) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with Message

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

Example 25 with Message

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;
}
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