use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method updateBudget.
public boolean updateBudget(final Budget budget) {
boolean result;
dataLock.writeLock().lock();
try {
Message message;
result = getBudgetDAO().update(budget);
if (result) {
message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_UPDATE, this);
} else {
message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_UPDATE_FAILED, this);
}
message.setObject(MessageProperty.BUDGET, budget);
messageBus.fireEvent(message);
logger.log(Level.FINE, "Budget updated");
return result;
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method setCreateBackups.
public void setCreateBackups(final boolean createBackups) {
dataLock.writeLock().lock();
try {
final Config backupConfig = getConfig();
backupConfig.setCreateBackups(createBackups);
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();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method modifyAccount.
/**
* Modifies an existing account given an account as a template. The type of the account cannot be changed.
*
* @param template The Account object to use as a template
* @param account The existing account
* @return true if successful
*/
public boolean modifyAccount(final Account template, final Account account) {
boolean result;
Message message;
dataLock.writeLock().lock();
try {
account.setName(template.getName());
account.setDescription(template.getDescription());
account.setNotes(template.getNotes());
account.setLocked(template.isLocked());
account.setPlaceHolder(template.isPlaceHolder());
account.setVisible(template.isVisible());
account.setExcludedFromBudget(template.isExcludedFromBudget());
account.setAccountNumber(template.getAccountNumber());
account.setBankId(template.getBankId());
account.setAccountCode(template.getAccountCode());
if (account.getAccountType().isMutable()) {
account.setAccountType(template.getAccountType());
}
// allow allow a change if the account does not contain transactions
if (account.getTransactionCount() == 0) {
account.setCurrencyNode(template.getCurrencyNode());
}
result = getAccountDAO().updateAccount(account);
if (result) {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
logInfo(rb.getString("Message.AccountModify"));
} else {
message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY_FAILED, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
}
/* Check to see if the account needs to be moved */
if (account.parentAccount != template.parentAccount && template.parentAccount != null && result) {
if (!moveAccount(account, template.parentAccount)) {
logWarning(rb.getString("Message.Error.MoveAccount"));
result = false;
}
}
// Force clearing of any budget goals if an empty account has been changed to become a place holder
if (account.isPlaceHolder()) {
purgeBudgetGoal(account);
}
return result;
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class EngineFactory method bootClientEngine.
public static synchronized Engine bootClientEngine(final String host, final int port, final char[] password, final String engineName) throws Exception {
if (engineMap.get(engineName) != null) {
throw new RuntimeException("A stale engine was found in the map");
}
final Preferences pref = Preferences.userNodeForPackage(EngineFactory.class);
Engine engine = null;
// start the client message bus
if (MessageBus.getInstance(engineName).setRemote(host, port + JpaNetworkServer.MESSAGE_SERVER_INCREMENT, password)) {
pref.putInt(LAST_PORT, port);
pref.put(LAST_HOST, host);
pref.putBoolean(LAST_REMOTE, true);
final MessageBus messageBus = MessageBus.getInstance(engineName);
// after starting the remote message bus, it should receive the path on the server
final String remoteDataBasePath = messageBus.getRemoteDataBasePath();
final DataStoreType dataStoreType = messageBus.getRemoteDataStoreType();
if (remoteDataBasePath == null || remoteDataBasePath.isEmpty() || dataStoreType == null) {
throw new Exception("Invalid connection wih the message bus");
}
logger.log(Level.INFO, "Remote path was {0}", remoteDataBasePath);
logger.log(Level.INFO, "Remote data store was {0}", dataStoreType.name());
logger.log(Level.INFO, "Engine name was {0}", engineName);
DataStore dataStore = dataStoreType.getDataStore();
// connect to the remote server
engine = dataStore.getClientEngine(host, port, password, remoteDataBasePath);
if (engine != null) {
logger.info(ResourceUtils.getString("Message.EngineStart"));
engineMap.put(engineName, engine);
dataStoreMap.put(engineName, dataStore);
// remember if the user used a password for the last session
pref.putBoolean(USED_PASSWORD, password.length > 0);
final Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.FILE_LOAD_SUCCESS, engine);
MessageBus.getInstance(engineName).fireEvent(message);
}
}
return engine;
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method updateReminder.
private boolean updateReminder(final Reminder reminder) {
final boolean result = getReminderDAO().updateReminder(reminder);
final Message message;
if (result) {
message = new Message(MessageChannel.REMINDER, ChannelEvent.REMINDER_UPDATE, this);
} else {
message = new Message(MessageChannel.REMINDER, ChannelEvent.REMINDER_UPDATE_FAILED, this);
}
message.setObject(MessageProperty.REMINDER, reminder);
messageBus.fireEvent(message);
return result;
}
Aggregations