Class AccountBook


  • public class AccountBook
    extends java.lang.Object
    AccountBook is the overall container for a data file in Moneydance. It contains references to all transactions, accounts, currencies, securities, budgets, etc.
    • Field Detail

      • DROPBOX_SYNC_UUID

        public static final java.lang.String DROPBOX_SYNC_UUID
        See Also:
        Constant Field Values
    • Method Detail

      • getLocalStorage

        public LocalStorage getLocalStorage()
        Returns an object that can be used to save information locally, such as preferences, network/syncing settings, and passwords (if the data file is encrypted). Note: data put into the local storage is not synced.
      • setLocalStorage

        public void setLocalStorage​(LocalStorage newStorage)
        Sets an object that can be used to save information locally, such as preferences, network/syncing settings, and passwords (if the data file is encrypted). This should be set only by the application if it wants to override how data is stored. Note: data put into the local storage is not synced.
      • getFileUUID

        public final java.lang.String getFileUUID()
        Get the unique ID for this data file. If there are any data files with the same ID then some not-great things may happen with syncing, so be careful when restoring backups and un-archiving files.
      • doInitialLoad

        public void doInitialLoad​(boolean isSyncMaster)
                           throws java.lang.Exception
        Load the set of accounts from storage
        Throws:
        java.lang.Exception
      • saveTrunkFile

        public void saveTrunkFile()
                           throws java.lang.Exception
        Saves a snapshot of the current data set in a "trunk" data file. If the resetTxnQueue parameter is true then any incremental transaction logs since the last save are wiped out. Therefore, the parameter should only be true if we're the master syncing node AND ve created a new data file for the first time or we want to reset the transaction queue for some other reason.
        Throws:
        java.lang.Exception
      • hasCompletedInitialSync

        public boolean hasCompletedInitialSync()
      • startSyncing

        public void startSyncing​(com.infinitekind.tiksync.SyncFolder syncFolder,
                                 com.infinitekind.tiksync.SyncDelegate callback,
                                 boolean isMasterSyncer)
                          throws java.lang.Exception
        If the syncing process hasn't already been established then this synchronously downloads the initial data set. It then kicks off a background thread to continuously sync this data file. If syncing has already started this does nothing.
        Parameters:
        syncFolder - The online "folder" in which sync files are stored
        isMasterSyncer - true if this data set is a master copy; that is, it's not a mobile device or secondary desktop copy
        Throws:
        java.lang.Exception - whenever it feels the urge
      • stopSyncing

        public void stopSyncing()
      • pauseSyncing

        public void pauseSyncing()
      • resumeSyncing

        public void resumeSyncing()
      • getCurrencyByUUID

        public final CurrencyType getCurrencyByUUID​(java.lang.String currencyID)
      • getAccountByUUID

        public final Account getAccountByUUID​(java.lang.String acctID)
      • getAccountByNum

        public final Account getAccountByNum​(int acctNum)
      • getAccountByUUIDOrLegacyNumber

        public final Account getAccountByUUIDOrLegacyNumber​(java.lang.String acctID)
        Lookup an account by either it's old account ID (if given a numeric value) or by it's UUID.
        Since:
        build 1204
      • getSyncer

        public com.infinitekind.tiksync.Syncer getSyncer()
        Get the syncer associated with this data set, if any.
        Returns:
        the syncer if this account book has started syncing, or null if not
      • initializeNewEmptyAccounts

        public void initializeNewEmptyAccounts​(java.lang.String defaultCurrencyID)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • initializeAccounts

        public void initializeAccounts​(Account rootAccount)
      • getName

        public java.lang.String getName()
      • getRootAccountFile

        public java.lang.String getRootAccountFile()
      • getAttachmentsFolder

        public java.lang.String getAttachmentsFolder()
      • getCheckpointsFolder

        public java.io.File getCheckpointsFolder()
      • getLastModified

        public long getLastModified()
      • getCheckpointFiles

        public java.util.List<java.io.File> getCheckpointFiles()
      • getRootFolder

        public java.io.File getRootFolder()
      • getTemporaryFolder

        public java.io.File getTemporaryFolder()
      • getEncryptedTemporaryFolder

        public java.io.File getEncryptedTemporaryFolder()
      • getUndoManager

        public UndoManagerInterface getUndoManager()
        Get the undo manager that is associated with the UI for this data file. Returns null if the UI hasn't set an undo manager.
        Since:
        Moneydance 2017.3 build 1605
      • setUndoManager

        public void setUndoManager​(UndoManagerInterface undoManager)
        Set the undo manager that is associated with the UI for this data file.
        Since:
        Moneydance 2017.3 build 1605
      • getRootAccount

        public Account getRootAccount()
      • getTransactionSet

        public TransactionSet getTransactionSet()
        Get the set of all transactions.
      • getCurrencies

        public CurrencyTable getCurrencies()
        Get the set of currencies associated with this file
      • getOnlineInfo

        public OnlineInfo getOnlineInfo()
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • createAccountBookStructure

        protected boolean createAccountBookStructure()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isValid

        public boolean isValid()
      • isValid

        public static boolean isValid​(AccountBook book)
      • accountBookForFolder

        public static AccountBook accountBookForFolder​(java.io.File folder)
      • isValidBookName

        public static boolean isValidBookName​(java.io.File baseFolder,
                                              java.lang.String bookName)
      • isValidBookFile

        public static boolean isValidBookFile​(java.lang.String filename)
      • setPublicMetaData

        public void setPublicMetaData​(StreamTable newMetaInfo)
        Set the public meta data that applies to this set of accounts. This should only be called by the objects that read the data from an input stream.
      • getPublicMetaData

        public StreamTable getPublicMetaData()
        Return public metadata about this set of accounts. This should include any information that is not in the encrypted part of the file. This will most likely only contain the encryption hint.
      • cleanUp

        public void cleanUp()
        Avoid lapsed listener leaks when successively opening multiple files. Clean up all fields that have back references to this object, and remove any listeners that were not already removed.
      • registerAttachmentForDeletion

        public void registerAttachmentForDeletion​(java.lang.String attachmentPath)
      • unregisterAttachmentForDeletion

        public void unregisterAttachmentForDeletion​(java.lang.String attachmentPath)
      • cleanupDeletedAttachments

        public void cleanupDeletedAttachments()
      • addFileListener

        public void addFileListener​(MDFileListener listener)
      • removeFileListener

        public void removeFileListener​(MDFileListener listener)
      • addAccountListener

        public final void addAccountListener​(AccountListener listener)
        add a listener to be notified when an account is modified.
      • removeAccountListener

        public final void removeAccountListener​(AccountListener listener)
        remove the specified object so that it doesn't get any more notifications when an account is modified.
      • notifyAccountModified

        public void notifyAccountModified​(Account acct)
        notify all listeners that the specified account has been modified.
      • refreshAccountBalances

        public boolean refreshAccountBalances()
        This will update the accounts balance from the "working" value and notify listeners if the balance has changed. Returns true if any of the balances have changed.
      • refreshAccountBalancesAsync

        public void refreshAccountBalancesAsync()
      • setRecalcBalances

        public void setRecalcBalances​(boolean doRecalcs)
        Tells the model whether or not all account balances should be recalculated whenever a transaction is modified. For performance reasons this should be set to false before adding/modifying/deleting a bunch of transactions and then set to true afterwards. DON'T FORGET TO SET TO TRUE WHEN DONE WITH THE OPERATION!!!!
      • getRecalcBalances

        public boolean getRecalcBalances()
      • logRemovedItem

        public boolean logRemovedItem​(MoneydanceSyncableItem removedItem)
        Record that the given item was removed, so that the removal of the item can be synced.
      • registerNewItemWithoutSyncing

        public void registerNewItemWithoutSyncing​(com.infinitekind.tiksync.SyncableItem newItem)
        Call this to add an item to the data set that is not yet synced. This should only be called when loading data in bulk. After this is called you should push a new trunk data set to the syncing system so that this item is not lost! This is useful when loading data from an older moneydance data file when you want the data loaded, but don't want it (yet) synced via an incremental update. Note: This must ensure that the item's UUID is not a duplicate of anything that is already in the data set.
      • logModifiedItem

        public boolean logModifiedItem​(MoneydanceSyncableItem modifiedItem)
        Record that the given item was changed, so that the change can be saved and synced.
      • logModifiedItems

        public boolean logModifiedItems​(java.util.List<MoneydanceSyncableItem> modifiedItems)
        Record that the given items were changed, so that the changes can be saved and synced.
      • save

        public boolean save()
        Save any pending queued changes, returning false if we couldn't save something
      • performPostLoadVerification

        public void performPostLoadVerification()
      • setFinishedInitialLoad

        public void setFinishedInitialLoad​(boolean b)
      • moveToFolder

        public void moveToFolder​(java.io.File newFolder)
                          throws java.io.IOException
        Move this account book to the given base folder. This is used for internal functions such as moving a provisional set of data from a temporary folder into it's permanent location.
        Throws:
        java.io.IOException
        Since:
        Moneydance build 1525
      • scheduleQueuePurgeInMillisecondsFromNow

        public void scheduleQueuePurgeInMillisecondsFromNow​(long inXMilliseconds)
      • hasLoggedChanges

        public boolean hasLoggedChanges()
      • resetLoggedChanges

        public final void resetLoggedChanges()
      • getItemForID

        public final MoneydanceSyncableItem getItemForID​(java.lang.String itemID)
        Returns the local item that has the given ID
      • getItemsWithType

        public java.util.List<com.infinitekind.tiksync.SyncableItem> getItemsWithType​(java.lang.String type)
      • fakeAccountBook

        public static AccountBook fakeAccountBook()
      • getUnusedFriendlyFileInBase

        public static java.io.File getUnusedFriendlyFileInBase​(java.io.File baseFolder)
      • getUnusedFileNameWithBase

        public static java.io.File getUnusedFileNameWithBase​(java.io.File containerFolder,
                                                             java.lang.String baseName)
        Return a unique internal account book file folder with a name based on the given base file name
      • getBookFileForName

        public static java.io.File getBookFileForName​(java.io.File containerFolder,
                                                      java.lang.String bookName)
      • stripNonFilenameSafeCharacters

        public static java.lang.String stripNonFilenameSafeCharacters​(java.lang.String filename)
        Strip all characters that should not appear in a filename (including path characters)