jpl.mipl.mdms.FileService.komodo.ui.savannah
Class SavannahModel

java.lang.Object
  extended by jpl.mipl.mdms.FileService.komodo.ui.savannah.SavannahModel
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener

public class SavannahModel
extends java.lang.Object
implements java.beans.PropertyChangeListener

Purpose: Application model for the Savannah application.

 Copyright 2004, California Institute of Technology. 
 ALL RIGHTS RESERVED. 
 U.S. Government Sponsorship acknowledge. 2004.
 
 ============================================================================
 Modification History :  
 ---------------------- 
 Date             Who         What 
 ----------------------------------------------------------------------------
 06/02/2004       Nick        Initial Release
 08/22/2005       Nick        Added shutdown handler to close session and
                              terminate subscription manager.
 ============================================================================
 

Version:
$Id: SavannahModel.java,v 1.68 2008/09/17 19:06:07 ntt Exp $
Author:
Nicholas Toole (Nicholas.T.Toole@jpl.nasa.gov)

Field Summary
protected  UserAuthenticator _authenticator
          user authenticator instance
protected  java.beans.PropertyChangeSupport _changes
          Enables bean property change event handling
protected  java.lang.String _currentFeiGroup
          FEI server identifier
protected  java.lang.String _currentFeiType
          FEI file type
protected  java.lang.String _domainFileKey
          FEI Domain file property key
protected  java.net.URL _domainFileURL
          filename of FEI domain file
protected  FileType _fileType
          reference to FEI filetype connection
protected  SavannahFilterModel _filterModel
          Regular expression filename filter for local files
protected  boolean _isBusy
          flag indicating whether application is busy
protected  SavannahLogModel _logModel
          log history model
protected  LogMessagePublisher _logPublisher
          Logging publisher, log model is added as a listener
protected  java.lang.String _password
          FEI password
protected  ReceivalHistoryModel _receivalModel
          model for maintaining receival history
protected  java.awt.Component _relativeComponent
          Component used as reference for error messages, can be null
protected  java.util.List _serverGroups
          list of FEI server groups
protected  Session _session
          reference to FEI Session object
protected  SavannahSessionModel _sessionModel
          model for maintaining session settings
protected  java.lang.String _statusMessage
          status message
protected  MetaSubscriptionManager _subscriptionManager
          subscription manager field
protected  java.lang.Object _syncLock
          lock for synchronization
protected  SavannahTransferModel _transferModel
          transfer history model
protected  java.lang.String _username
          FEI username
static java.lang.String ABOUT_ICON_PATH
          animated icon
static java.lang.String APPLICATION_TITLE
          application title
static java.lang.String COPYRIGHT
          copyright string
static java.lang.String ICON_PATH
          application icon
static java.lang.String KOMODO_VERSION
          client version string
static int LOGIN_ATTEMPT_COUNT
          Maximum login attempt count
static int TARGET_FEI
           
static int TARGET_LOCAL
           
static java.lang.String VERSION_ID
          application version id
 
Constructor Summary
SavannahModel()
          Constructor.
 
Method Summary
protected  void _addToFei(java.lang.String[] filenames)
          Method to add a list of files to the current server
protected  void _changePassword(java.lang.String servergroup, java.lang.String username, java.lang.String oldPassword, java.lang.String newPassword)
           
protected  void _commentInFei(java.lang.String filename, java.lang.String comment)
          Sets or removes comment for an entry in FEI.
protected  void _deleteFromFei(java.lang.String[] filenames)
          This method deletes files from current file type.
protected  void _getFromFei(java.lang.String[] filenames, java.io.File dest)
          This method gets files from the server to local directory This is the synchronous version of copyFromFei.
protected  void _renameInFei(java.lang.String origName, java.lang.String newName)
          Renames an entry in FEI to a new name.
protected  void _replaceToFei(java.lang.String[] filenames)
          Method to replace a list of files to the current server.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds listener for property change of model.
 void addToFei(java.lang.String[] filenames)
          Method to add a list of files to the current server
 boolean canUserConnect(java.lang.String username, java.lang.String password, java.lang.String servergroup, java.lang.String filetype)
           
 boolean canUserConnectNoEx(java.lang.String username, java.lang.String password, java.lang.String servergroup, java.lang.String filetype)
           
protected  void changeDirectory(java.io.File dir)
          Change the local directory reference by Client object.
 boolean changePassword(java.lang.String servergroup, java.lang.String username, java.lang.String oldPassword, java.lang.String newPassword)
           
protected  void closeFileType(FileType filetype)
          Attempts to close filetype with parameter name.
 void commentInFei(java.lang.String filename, java.lang.String comment)
          Sets or removes comment for an entry in FEI.
protected  boolean connectToFileType(java.lang.String type)
          Attempts to connect to filetype after closing current filetype if necessary.
 void deleteFromFei(java.lang.String[] filenames)
          This method deletes files from current file type.
 void destroy()
          Closes all sessions and resets all references for sub-components.
 java.lang.String[] getAllFiletypes()
          Returns array of all filetypes defined in the domain file of the current session instance.
 java.util.List getAvailableFeiServers()
          Returns list of available FEI server groups.
 java.lang.String getCurrentFeiServer()
          Returns the name of the current fei server group
 java.lang.String getCurrentFeiType()
          Returns current FEI file type, null if none
 java.net.URL getDomainFile()
          Returns current FEI domain filename used for this session.
 java.util.List getFeiTypes()
          Returns a List of FEI types from the current FEI server
 SavannahFilterModel getFilterModel()
          Returns reference to the file filter model.
 void getFromFei(java.lang.String[] filenames)
          This method gets files from the server to local directory
 void getFromFei(java.lang.String[] filenames, java.io.File destination)
          This method gets files from the server to local directory
 java.io.File getLocalDirectory()
          Returns current status to be displayed as part of GUI.
 SavannahLogModel getLoggingModel()
          Returns reference to the logging model used by this object
 boolean getLoginInfo()
          Displays dialog for user to enter username and password
 java.lang.String getPassword(java.lang.String username)
           
 ReceivalHistoryModel getReceivalModel()
          Returns reference to the receival model.
 java.awt.Component getRelativeComponent()
          Returns reference to the relative component.
 SavannahSessionModel getSessionModel()
          Returns reference to the session model used to maintain session state between session instances.
 java.lang.String getStatusMessage()
          Returns current status to be displayed as part of GUI.
 MetaSubscriptionManager getSubscriptionManager()
          Returns reference to the subscription manager used by this object
 SavannahTransferModel getTransferModel()
          Returns reference to the transfer model used to track file transaction history.
 java.lang.String getUsername()
          Returns current username for session
protected  void init()
          Initializes model, loads properties, establishes server list
protected  void initSession()
          Initializes client information including SSL keystore and FEI domain lookup service.
 boolean isBusy()
          Returns model busy flag.
protected  boolean loadAuthenticator()
           
protected  boolean loadFeiServerGroups()
          Retrieves a list of server group names from the session object
protected  boolean loadSession(java.net.URL domainFileURL)
          Loads new session object and replaces old session object if necessarry.
protected  void login()
          Attempts to login to Client using username, password fields.
 void printDebug(java.lang.String msg)
          Prints debug message to standard out if debug enabled.
 void propertyChange(java.beans.PropertyChangeEvent pce)
          Implementation of the PropertyChangeListener interface.
 void refreshFeiServerGroups()
          Requests refresh of FEI server group listing
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes listener for property change of model.
 void renameInFei(java.lang.String origName, java.lang.String newName)
          Renames an entry in FEI to a new name.
 void replaceToFei(java.lang.String[] filenames)
          This method replaces a list of files to the current filetype
 void requestRefresh(int target)
          Convenience method that requests a refresh for a file list based on parameter.
 void setAvailableFeiServers(java.util.List serverGroups)
          Sets list of available FEI server groups.
 void setBusyFlag(boolean isBusy)
          Sets model busy flag.
 void setCurrentFeiGroup(java.lang.String groupName)
          Sets the current FEI server group according to the paraemeter
 void setCurrentFeiType(java.lang.String type)
          Set current FEI file type
 void setDomainFile(java.net.URL domainFileURL, boolean override)
          Sets the domain filename according to non-null parameter.
 void setLocalDirectory(java.io.File localDir)
          Set current local directory
 void setPassword(java.lang.String password)
          Sets password for connection to FEI server groups
 void setRelativeComponent(java.awt.Component c)
          Assign a relative component used for placement of error/warning messages.
 void setStatusMessage(java.lang.String statMsg)
          Set current status message.
 void setUsername(java.lang.String username)
          Sets username.
 java.util.List showFromFei()
          Returns a list fo the files present in the current file type.
protected  boolean tryAuthenticating(java.lang.String groupName)
           
 void unsetCurrentFeiGroup()
          Unsets the current FEI server group by assigning null to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TARGET_FEI

public static final int TARGET_FEI
See Also:
Constant Field Values

TARGET_LOCAL

public static final int TARGET_LOCAL
See Also:
Constant Field Values

VERSION_ID

public static final java.lang.String VERSION_ID
application version id

See Also:
Constant Field Values

APPLICATION_TITLE

public static final java.lang.String APPLICATION_TITLE
application title

See Also:
Constant Field Values

KOMODO_VERSION

public static final java.lang.String KOMODO_VERSION
client version string

See Also:
Constant Field Values

COPYRIGHT

public static final java.lang.String COPYRIGHT
copyright string

See Also:
Constant Field Values

ICON_PATH

public static final java.lang.String ICON_PATH
application icon

See Also:
Constant Field Values

ABOUT_ICON_PATH

public static final java.lang.String ABOUT_ICON_PATH
animated icon

See Also:
Constant Field Values

LOGIN_ATTEMPT_COUNT

public static final int LOGIN_ATTEMPT_COUNT
Maximum login attempt count

See Also:
Constant Field Values

_domainFileKey

protected java.lang.String _domainFileKey
FEI Domain file property key


_session

protected Session _session
reference to FEI Session object


_fileType

protected FileType _fileType
reference to FEI filetype connection


_syncLock

protected final java.lang.Object _syncLock
lock for synchronization


_username

protected java.lang.String _username
FEI username


_password

protected java.lang.String _password
FEI password


_currentFeiGroup

protected java.lang.String _currentFeiGroup
FEI server identifier


_currentFeiType

protected java.lang.String _currentFeiType
FEI file type


_statusMessage

protected java.lang.String _statusMessage
status message


_serverGroups

protected java.util.List _serverGroups
list of FEI server groups


_domainFileURL

protected java.net.URL _domainFileURL
filename of FEI domain file


_isBusy

protected boolean _isBusy
flag indicating whether application is busy


_changes

protected java.beans.PropertyChangeSupport _changes
Enables bean property change event handling


_relativeComponent

protected java.awt.Component _relativeComponent
Component used as reference for error messages, can be null


_transferModel

protected SavannahTransferModel _transferModel
transfer history model


_filterModel

protected SavannahFilterModel _filterModel
Regular expression filename filter for local files


_logPublisher

protected LogMessagePublisher _logPublisher
Logging publisher, log model is added as a listener


_logModel

protected SavannahLogModel _logModel
log history model


_subscriptionManager

protected MetaSubscriptionManager _subscriptionManager
subscription manager field


_receivalModel

protected ReceivalHistoryModel _receivalModel
model for maintaining receival history


_sessionModel

protected SavannahSessionModel _sessionModel
model for maintaining session settings


_authenticator

protected UserAuthenticator _authenticator
user authenticator instance

Constructor Detail

SavannahModel

public SavannahModel()
Constructor.

Method Detail

init

protected void init()
Initializes model, loads properties, establishes server list


initSession

protected void initSession()
Initializes client information including SSL keystore and FEI domain lookup service.


loadAuthenticator

protected boolean loadAuthenticator()

getTransferModel

public SavannahTransferModel getTransferModel()
Returns reference to the transfer model used to track file transaction history.

Returns:
Reference to model's SavannahTransferModel

getSessionModel

public SavannahSessionModel getSessionModel()
Returns reference to the session model used to maintain session state between session instances.

Returns:
Session model

getFilterModel

public SavannahFilterModel getFilterModel()
Returns reference to the file filter model.

Returns:
Filter model

getReceivalModel

public ReceivalHistoryModel getReceivalModel()
Returns reference to the receival model.

Returns:
Receival model

getLoggingModel

public SavannahLogModel getLoggingModel()
Returns reference to the logging model used by this object

Returns:
Reference to log model

getSubscriptionManager

public MetaSubscriptionManager getSubscriptionManager()
Returns reference to the subscription manager used by this object

Returns:
reference to MetaSubscriptionManager

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds listener for property change of model.

Parameters:
l - Object implementing the PropertyChangeListener interface to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes listener for property change of model.

Parameters:
l - Object implementing the PropertyChangeListener interface to be removed

destroy

public void destroy()
Closes all sessions and resets all references for sub-components. Once this method is called, instance should no longer receive method invocation requests.


loadFeiServerGroups

protected boolean loadFeiServerGroups()
Retrieves a list of server group names from the session object

Returns:
True if load was successful, false otherwise.

refreshFeiServerGroups

public void refreshFeiServerGroups()
Requests refresh of FEI server group listing


setUsername

public void setUsername(java.lang.String username)
Sets username.

Parameters:
username - New username

getUsername

public java.lang.String getUsername()
Returns current username for session

Returns:
current username

setPassword

public void setPassword(java.lang.String password)
Sets password for connection to FEI server groups

Parameters:
password - New password string, or null to reset

login

protected void login()
Attempts to login to Client using username, password fields.


getCurrentFeiServer

public java.lang.String getCurrentFeiServer()
Returns the name of the current fei server group

Returns:
current FEI server

unsetCurrentFeiGroup

public void unsetCurrentFeiGroup()
Unsets the current FEI server group by assigning null to it. This has the effect of "disconnecting" to the server.


setCurrentFeiGroup

public void setCurrentFeiGroup(java.lang.String groupName)
                        throws java.lang.IllegalArgumentException
Sets the current FEI server group according to the paraemeter

Parameters:
groupName - The name of the new FEI server group, or null to reset
Throws:
java.lang.IllegalArgumentException

tryAuthenticating

protected boolean tryAuthenticating(java.lang.String groupName)

loadSession

protected boolean loadSession(java.net.URL domainFileURL)
Loads new session object and replaces old session object if necessarry.

Parameters:
domainFileURL - URL of the FEI domain file
Returns:
True if connection was successful, false otherwise.

getLoginInfo

public boolean getLoginInfo()
Displays dialog for user to enter username and password


setAvailableFeiServers

public void setAvailableFeiServers(java.util.List serverGroups)
Sets list of available FEI server groups.

Parameters:
serverGroups - List of FEI server groups

getAvailableFeiServers

public java.util.List getAvailableFeiServers()
Returns list of available FEI server groups.

Returns:
List of FEI server groups

getFeiTypes

public java.util.List getFeiTypes()
Returns a List of FEI types from the current FEI server

Returns:
List of available FEI file types

addToFei

public void addToFei(java.lang.String[] filenames)
Method to add a list of files to the current server

Parameters:
filenames - String array of filenames to be added

_addToFei

protected void _addToFei(java.lang.String[] filenames)
Method to add a list of files to the current server

Parameters:
filenames - String array of filenames to be added

replaceToFei

public void replaceToFei(java.lang.String[] filenames)
This method replaces a list of files to the current filetype

Parameters:
filenames - Array of filenames to copy to FEI

_replaceToFei

protected void _replaceToFei(java.lang.String[] filenames)
Method to replace a list of files to the current server. This is the synchronous version of copyToFei. Called by asynchronous method on a new thread.

Parameters:
filenames - Array of filenames to copy to FEI

getFromFei

public void getFromFei(java.lang.String[] filenames,
                       java.io.File destination)
This method gets files from the server to local directory

Parameters:
filenames - Array of filenames to be retreived
destination - Absolute path to destination directory

getFromFei

public void getFromFei(java.lang.String[] filenames)
This method gets files from the server to local directory

Parameters:
filenames - Array of filenames to be retreived

_getFromFei

protected void _getFromFei(java.lang.String[] filenames,
                           java.io.File dest)
This method gets files from the server to local directory This is the synchronous version of copyFromFei. Called by asynchronous method on a new thread.

Parameters:
filenames - Array of filenames to be retreived
dest - Destination directory of files. If null, then local directory will be used. If different from local dir, session will use parameter to copy files, then reset to local directory before exiting.

deleteFromFei

public void deleteFromFei(java.lang.String[] filenames)
This method deletes files from current file type.

Parameters:
filenames - Array of filenames to be deleted

_deleteFromFei

protected void _deleteFromFei(java.lang.String[] filenames)
This method deletes files from current file type. This is the synchronous version of deleteFromFei. Called by asynchronous method on a new thread.

Parameters:
filenames - Array of filenames to be deleted

showFromFei

public java.util.List showFromFei()
Returns a list fo the files present in the current file type. NOTE: Max number of files bound by Integer.MAX_VALUE

Returns:
List of files present in the current file type

renameInFei

public void renameInFei(java.lang.String origName,
                        java.lang.String newName)
Renames an entry in FEI to a new name.

Parameters:
origName - Original name of the entry
newName - New name of the entry

_renameInFei

protected void _renameInFei(java.lang.String origName,
                            java.lang.String newName)
Renames an entry in FEI to a new name. This is the synchronous version of renameInFei. Called by asynchronous method on a new thread.

Parameters:
origName - Original name of the entry
newName - New name of the entry

commentInFei

public void commentInFei(java.lang.String filename,
                         java.lang.String comment)
Sets or removes comment for an entry in FEI.

Parameters:
filename - Filename of the entry
comment - New comment of the entry, null resets comment.

_commentInFei

protected void _commentInFei(java.lang.String filename,
                             java.lang.String comment)
Sets or removes comment for an entry in FEI. This is the synchronous version of commentInFei. Called by asynchronous method on a new thread.

Parameters:
fileame - Filename of the entry
Comment - New comment of the entry, null resets comment.

_changePassword

protected void _changePassword(java.lang.String servergroup,
                               java.lang.String username,
                               java.lang.String oldPassword,
                               java.lang.String newPassword)

changeDirectory

protected void changeDirectory(java.io.File dir)
                        throws SessionException
Change the local directory reference by Client object.

Parameters:
dir - The updated local directory
Throws:
SessionException

closeFileType

protected void closeFileType(FileType filetype)
Attempts to close filetype with parameter name.


connectToFileType

protected boolean connectToFileType(java.lang.String type)
                             throws SessionException
Attempts to connect to filetype after closing current filetype if necessary.

Parameters:
Filetype - name, or null to reset filetype to nothing.
Throws:
SessionException

setStatusMessage

public void setStatusMessage(java.lang.String statMsg)
Set current status message.

Parameters:
statMsg - Current status message.

getStatusMessage

public java.lang.String getStatusMessage()
Returns current status to be displayed as part of GUI.

Returns:
Status message, empty string if none.

setLocalDirectory

public void setLocalDirectory(java.io.File localDir)
Set current local directory

Parameters:
localDir - File pointing to new local directory

getLocalDirectory

public java.io.File getLocalDirectory()
Returns current status to be displayed as part of GUI.

Returns:
Status message, empty string if none.

setCurrentFeiType

public void setCurrentFeiType(java.lang.String type)
                       throws SessionException
Set current FEI file type

Parameters:
type - new fiel type, null to reset
Throws:
SessionException

getCurrentFeiType

public java.lang.String getCurrentFeiType()
Returns current FEI file type, null if none

Returns:
Current file type

setBusyFlag

public void setBusyFlag(boolean isBusy)
Sets model busy flag. Indicates a transaction in progress.

Parameters:
isBusy - True if busy, false otherwise.

isBusy

public boolean isBusy()
Returns model busy flag. Indicates a transaction in progress.


setRelativeComponent

public void setRelativeComponent(java.awt.Component c)
Assign a relative component used for placement of error/warning messages.

Parameters:
c - Relative component to use, can be null.

getRelativeComponent

public java.awt.Component getRelativeComponent()
Returns reference to the relative component.

Returns:
Component used for relative placement.

printDebug

public void printDebug(java.lang.String msg)
Prints debug message to standard out if debug enabled.

Parameters:
msg - Message to print.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent pce)
Implementation of the PropertyChangeListener interface.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getDomainFile

public java.net.URL getDomainFile()
Returns current FEI domain filename used for this session.

Returns:
Current FEI domain filename

setDomainFile

public void setDomainFile(java.net.URL domainFileURL,
                          boolean override)
Sets the domain filename according to non-null parameter. If filename is different from current, then a new Session is constructed and replaces the older session.

Parameters:
domainFilename - New FEI domain file
override - If domain filename is unchanged, override as true reloads current file.
Throws:
java.lang.IllegalArgumentException - if domainFilename is null or refers to a non-exising file.

requestRefresh

public void requestRefresh(int target)
Convenience method that requests a refresh for a file list based on parameter.

Parameters:
target - Refresh taret, one of TARGET_FEI or TARGET_LOCAL.

canUserConnect

public boolean canUserConnect(java.lang.String username,
                              java.lang.String password,
                              java.lang.String servergroup,
                              java.lang.String filetype)
                       throws SessionException
Throws:
SessionException

canUserConnectNoEx

public boolean canUserConnectNoEx(java.lang.String username,
                                  java.lang.String password,
                                  java.lang.String servergroup,
                                  java.lang.String filetype)

changePassword

public boolean changePassword(java.lang.String servergroup,
                              java.lang.String username,
                              java.lang.String oldPassword,
                              java.lang.String newPassword)

getAllFiletypes

public java.lang.String[] getAllFiletypes()
Returns array of all filetypes defined in the domain file of the current session instance.

Returns:
Sorted array of filetypes (e.g. groupname:filetype)

getPassword

public java.lang.String getPassword(java.lang.String username)