Search in sources :

Example 6 with Message

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

Example 7 with Message

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

Example 8 with Message

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

Example 9 with Message

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

Example 10 with Message

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();
    }
}
Also used : EngineDAO(jgnash.engine.dao.EngineDAO) CurrencyUpdateFactory(jgnash.net.currency.CurrencyUpdateFactory) ScheduledFuture(java.util.concurrent.ScheduledFuture) UpdateFactory(jgnash.net.security.UpdateFactory) TimeoutException(java.util.concurrent.TimeoutException) LockManager(jgnash.engine.concurrent.LockManager) MessageBus(jgnash.engine.message.MessageBus) BigDecimal(java.math.BigDecimal) Nullable(jgnash.util.Nullable) Future(java.util.concurrent.Future) Budget(jgnash.engine.budget.Budget) MessageProperty(jgnash.engine.message.MessageProperty) RecurringIterator(jgnash.engine.recurring.RecurringIterator) MessageChannel(jgnash.engine.message.MessageChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) Path(java.nio.file.Path) AttachmentManager(jgnash.engine.attachment.AttachmentManager) NotNull(jgnash.util.NotNull) CancellationException(java.util.concurrent.CancellationException) Collection(java.util.Collection) Set(java.util.Set) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) PendingReminder(jgnash.engine.recurring.PendingReminder) Objects(java.util.Objects) BudgetGoal(jgnash.engine.budget.BudgetGoal) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Handler(java.util.logging.Handler) Message(jgnash.engine.message.Message) ConfigDAO(jgnash.engine.dao.ConfigDAO) TrashDAO(jgnash.engine.dao.TrashDAO) LocalDateTime(java.time.LocalDateTime) ResourceUtils(jgnash.util.ResourceUtils) MonthlyReminder(jgnash.engine.recurring.MonthlyReminder) Callable(java.util.concurrent.Callable) CommodityDAO(jgnash.engine.dao.CommodityDAO) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ChannelEvent(jgnash.engine.message.ChannelEvent) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) ResourceBundle(java.util.ResourceBundle) ExecutorService(java.util.concurrent.ExecutorService) DateUtils(jgnash.time.DateUtils) IOException(java.io.IOException) AccountDAO(jgnash.engine.dao.AccountDAO) TransactionDAO(jgnash.engine.dao.TransactionDAO) Reminder(jgnash.engine.recurring.Reminder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ChronoUnit(java.time.temporal.ChronoUnit) DayOfWeek(java.time.DayOfWeek) BudgetDAO(jgnash.engine.dao.BudgetDAO) Collections(java.util.Collections) CollectionUtils(jgnash.util.CollectionUtils) RecurringDAO(jgnash.engine.dao.RecurringDAO) 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