diff options
10 files changed, 175 insertions, 74 deletions
diff --git a/idrop-swing/pom.xml b/idrop-swing/pom.xml index cefd137..1ba0c16 100644 --- a/idrop-swing/pom.xml +++ b/idrop-swing/pom.xml @@ -77,6 +77,12 @@ <groupId>org.swinglabs</groupId> <artifactId>swing-layout</artifactId> </dependency> + <dependency> + <groupId>org.irods.jargon.transfer</groupId> + <artifactId>jargon-transfer-dao-api</artifactId> + <version>2.4.1-SNAPSHOT</version> + <type>jar</type> + </dependency> </dependencies> <build> <plugins> diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/IDROPCore.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/IDROPCore.java index 32b99bd..fd753a1 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/IDROPCore.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/IDROPCore.java @@ -11,6 +11,7 @@ import org.irods.jargon.core.pub.IRODSAccessObjectFactory; import org.irods.jargon.core.pub.IRODSFileSystem; import org.irods.jargon.core.pub.io.IRODSFileFactory; import org.irods.jargon.idrop.desktop.systraygui.services.IconManager; +import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationService; import org.irods.jargon.idrop.desktop.systraygui.utils.IdropConfig; import org.irods.jargon.idrop.exceptions.IdropRuntimeException; import org.irods.jargon.transfer.engine.TransferManager; @@ -31,7 +32,15 @@ public class IDROPCore { private TransferManager transferManager = null; private IconManager iconManager = null; private Timer queueTimer = new Timer(); - private Preferences preferences = Preferences.userRoot(); + private IdropConfigurationService idropConfigurationService = null; + + public IdropConfigurationService getIdropConfigurationService() { + return idropConfigurationService; + } + + public void setIdropConfigurationService(IdropConfigurationService idropConfigurationService) { + this.idropConfigurationService = idropConfigurationService; + } public IDROPCore() { super(); @@ -77,16 +86,6 @@ public class IDROPCore { this.queueTimer = queueTimer; } - @Deprecated - public Preferences getPreferences() { - return preferences; - } - - @Deprecated - public void setPreferences(final Preferences preferences) { - this.preferences = preferences; - } - /** * Handy method that delegates the process of getting an * <code>IRODSAccessObjectFactory</code>. diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/LoginDialog.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/LoginDialog.java index e15c17b..2cc283d 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/LoginDialog.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/LoginDialog.java @@ -15,7 +15,11 @@ import org.irods.jargon.core.connection.IRODSAccount; import org.irods.jargon.core.exception.JargonException; import org.irods.jargon.core.pub.IRODSFileSystem; import org.irods.jargon.core.pub.UserAO; +import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationService; import org.irods.jargon.idrop.desktop.systraygui.utils.IdropPropertiesHelper; +import org.irods.jargon.idrop.exceptions.IdropException; +import org.irods.jargon.idrop.exceptions.IdropRuntimeException; +import org.openide.util.Exceptions; import org.slf4j.LoggerFactory; /** @@ -28,10 +32,6 @@ public class LoginDialog extends JDialog { * */ private static final long serialVersionUID = 1L; - private static final String PREF_LOGIN_HOST = "login.host"; - private static final String PREF_LOGIN_ZONE = "login.zone"; - private static final String PREF_LOGIN_RESOURCE = "login.resource"; - private static final String PREF_LOGIN_USERNAME = "login.username"; private iDrop iDrop = null; public static org.slf4j.Logger log = LoggerFactory.getLogger(LoginDialog.class); @@ -53,25 +53,17 @@ public class LoginDialog extends JDialog { private void loginNormally( final org.irods.jargon.idrop.desktop.systraygui.iDrop iDrop) { // predispose based on preferences - String host = iDrop.getiDropCore().getPreferences().get(PREF_LOGIN_HOST, null); - if (host == null || host.isEmpty()) { - txtHost.setText(host); - } - - String zone = iDrop.getiDropCore().getPreferences().get(PREF_LOGIN_ZONE, null); - if (zone == null || zone.isEmpty()) { - txtZone.setText(zone); - } - - String resource = iDrop.getiDropCore().getPreferences().get(PREF_LOGIN_RESOURCE, null); - if (resource == null || resource.isEmpty()) { - txtResource.setText(resource); - } + String host = iDrop.getiDropCore().getIdropConfig().getPropertyForKey(IdropConfigurationService.ACCOUNT_CACHE_HOST); + txtHost.setText(host); + String port = iDrop.getiDropCore().getIdropConfig().getPropertyForKey(IdropConfigurationService.ACCOUNT_CACHE_PORT); + txtPort.setText(port); + String zone = iDrop.getiDropCore().getIdropConfig().getPropertyForKey(IdropConfigurationService.ACCOUNT_CACHE_ZONE); + txtZone.setText(zone); + String resource = iDrop.getiDropCore().getIdropConfig().getPropertyForKey(IdropConfigurationService.ACCOUNT_CACHE_RESOURCE); + txtResource.setText(resource); + String username = iDrop.getiDropCore().getIdropConfig().getPropertyForKey(IdropConfigurationService.ACCOUNT_CACHE_USER_NAME); + txtUserName.setText(username); - String username = iDrop.getiDropCore().getPreferences().get(PREF_LOGIN_USERNAME, null); - if (username == null || username.isEmpty()) { - txtUserName.setText(username); - } } private void loginUsingPreset() { @@ -168,13 +160,6 @@ public class LoginDialog extends JDialog { return true; } - // I figure at this point, it's safe to set the preferences...note that - // we are not caching password - iDrop.getiDropCore().getPreferences().put(PREF_LOGIN_HOST, txtHost.getText()); - iDrop.getiDropCore().getPreferences().put(PREF_LOGIN_ZONE, txtZone.getText()); - iDrop.getiDropCore().getPreferences().put(PREF_LOGIN_RESOURCE, txtResource.getText()); - iDrop.getiDropCore().getPreferences().put(PREF_LOGIN_USERNAME, txtUserName.getText()); - IRODSFileSystem irodsFileSystem = null; try { @@ -182,6 +167,11 @@ public class LoginDialog extends JDialog { final UserAO userAO = irodsFileSystem.getIRODSAccessObjectFactory().getUserAO(irodsAccount); userAO.findByName(txtUserName.getText()); iDrop.setIrodsAccount(irodsAccount); + try { + iDrop.getiDropCore().getIdropConfigurationService().saveLogin(irodsAccount); + } catch (IdropException ex) { + throw new IdropRuntimeException("error saving irodsAccount", ex); + } this.dispose(); } catch (JargonException ex) { if (ex.getMessage().indexOf("Connection refused") > -1) { diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java index 5b1166e..b5b0f1b 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java @@ -101,6 +101,7 @@ public class StartupSequencer { try { IdropConfigurationService idropConfigurationService = new IdropConfigurationServiceImpl( derivedConfigHomeDirectory, idropCore); + idropCore.setIdropConfigurationService(idropConfigurationService); derivedProperties = idropConfigurationService.bootstrapConfiguration(); } catch (IdropAlreadyRunningException are) { @@ -125,7 +126,7 @@ public class StartupSequencer { "Configuration information gathered, logging in...", ++count); log.info("config properties derived..."); - idropCore.setIdropConfig(new IdropConfig(derivedProperties)); + idropCore.setIdropConfig(new IdropConfig(derivedProperties)); idropCore.getIdropConfig().setUpLogging(); log.info("logging in in splash background thread"); diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java index 6119c2c..3e1424d 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java @@ -524,7 +524,7 @@ public class iDrop extends javax.swing.JFrame implements ActionListener, aboutDialog.setLocation(x, y); aboutDialog.setVisible(true); } else if (e.getActionCommand().equals("Preferences")) { - showGUICheckBox.setSelected(getiDropCore().getPreferences().getBoolean("showGUI", true)); + showGUICheckBox.setSelected(getiDropCore().getIdropConfig().isShowGuiAtStartup()); newPreferencesDialog.setVisible(true); } else if (e.getActionCommand().equals("Synch")) { synchSetupDialog = new SynchSetupDialog(this, getiDropCore(), @@ -1976,8 +1976,14 @@ public class iDrop extends javax.swing.JFrame implements ActionListener, private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent e) { + /* getiDropCore().getPreferences().putBoolean("showGUI", showGUICheckBox.isSelected() ? true : false); + * FIXME: recast as database options + * + * + */ + newPreferencesDialog.setVisible(false); } }; diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationService.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationService.java index a58eb88..e0bb7cc 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationService.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationService.java @@ -5,6 +5,7 @@ package org.irods.jargon.idrop.desktop.systraygui.services; import java.util.Properties; +import org.irods.jargon.core.connection.IRODSAccount; import org.irods.jargon.idrop.exceptions.IdropException; @@ -14,12 +15,19 @@ import org.irods.jargon.idrop.exceptions.IdropException; */ public interface IdropConfigurationService { - String IDROP_PROPS_FILE_NAME = "idrop.properties"; - String FORCE_MODE = "force.mode"; - String FORCE_NO_SYNCH = "force.no.synch"; - String LOGIN_PRESET = "login.preset"; - String SHOW_STARTUP = "show.startup"; - String SHOW_GUI = "idrop.show.gui"; + public final String IDROP_PROPS_FILE_NAME = "idrop.properties"; + public final String FORCE_MODE = "force.mode"; + public final String FORCE_NO_SYNCH = "force.no.synch"; + public final String LOGIN_PRESET = "login.preset"; + public final String SHOW_STARTUP = "show.startup"; + public final String SHOW_GUI = "idrop.show.gui"; + // account info for cache + public final String ACCOUNT_CACHE_HOST = "irods.account.host"; + public final String ACCOUNT_CACHE_PORT = "irods.account.port"; + public final String ACCOUNT_CACHE_ZONE = "irods.account.zone"; + public final String ACCOUNT_CACHE_RESOURCE = "irods.account.resource"; + public final String ACCOUNT_CACHE_USER_NAME = "irods.account.user"; + public final String ACCOUNT_CACHE_ROOT_DIR = "irods.account.root.dir"; Properties bootstrapConfiguration() throws IdropException; @@ -29,4 +37,19 @@ public interface IdropConfigurationService { * @throws IdropException */ void saveConfigurationToPropertiesFile() throws IdropException; + + /** + * Update the configuration database, and update the cached configs, with the given information + * @param key + * @param value + * @throws IdropException + */ + void updateConfig(final String key, final String value) throws IdropException; + + /** + * Save a given iRODS account as a cached last login in the configuration database + * @param irodsAccount {@link IRODSAccount} to be cached + * @throws IdropException + */ + void saveLogin(final IRODSAccount irodsAccount) throws IdropException; } diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java index 803b5c1..496dcf8 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java @@ -3,9 +3,11 @@ package org.irods.jargon.idrop.desktop.systraygui.services; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Date; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; +import org.irods.jargon.core.connection.IRODSAccount; import org.irods.jargon.idrop.desktop.systraygui.IDROPCore; import org.irods.jargon.idrop.desktop.systraygui.utils.IdropPropertiesHelper; @@ -13,7 +15,9 @@ import org.irods.jargon.idrop.exceptions.IdropAlreadyRunningException; import org.irods.jargon.idrop.exceptions.IdropException; import org.irods.jargon.transfer.TransferEngineException; import org.irods.jargon.transfer.TransferServiceFactoryImpl; +import org.irods.jargon.transfer.dao.domain.ConfigurationProperty; import org.irods.jargon.transfer.engine.ConfigurationService; +import org.openide.util.Exceptions; import org.slf4j.LoggerFactory; /** @@ -204,4 +208,51 @@ public class IdropConfigurationServiceImpl implements IdropConfigurationService importGivenPropertiesIntoDatabase(properties); return properties; } + + @Override + public void saveLogin(final IRODSAccount irodsAccount) throws IdropException { + log.info("save login"); + if (irodsAccount == null) { + throw new IllegalArgumentException("null irodsAccount"); + } + log.info("saving irodsAccount:{}", irodsAccount); + + updateConfig(IdropConfigurationService.ACCOUNT_CACHE_HOST, irodsAccount.getHost()); + updateConfig(IdropConfigurationService.ACCOUNT_CACHE_PORT, String.valueOf(irodsAccount.getPort())); + updateConfig(IdropConfigurationService.ACCOUNT_CACHE_RESOURCE, irodsAccount.getDefaultStorageResource()); + updateConfig(IdropConfigurationService.ACCOUNT_CACHE_ROOT_DIR, irodsAccount.getHomeDirectory()); + updateConfig(IdropConfigurationService.ACCOUNT_CACHE_ZONE, irodsAccount.getZone()); + updateConfig(IdropConfigurationService.ACCOUNT_CACHE_USER_NAME, irodsAccount.getUserName()); + log.info("config updated"); + } + + @Override + public void updateConfig(final String key, final String value) throws IdropException { + if (key == null || key.isEmpty()) { + throw new IllegalArgumentException("null or empty key"); + } + try { + ConfigurationProperty configurationProperty = configurationService.findConfigurationServiceByKey(key); + + if (configurationProperty == null) { + log.info("not found, this is new configuration"); + configurationProperty = new ConfigurationProperty(); + configurationProperty.setPropertyKey(key); + configurationProperty.setPropertyValue(value); + configurationProperty.setCreatedAt(new Date()); + } else { + log.info("found config property:{}", configurationProperty); + configurationProperty.setPropertyValue(value); + configurationProperty.setUpdatedAt(new Date()); + } + + configurationService.updateConfigurationProperty(configurationProperty); + log.info("database updated...updating property cache"); + idropCore.getIdropConfig().setProperty(key, value); + log.info("property cache updated"); + + } catch (TransferEngineException ex) { + log.error("exception updating config", ex); + } + } } diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/IdropConfig.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/IdropConfig.java index 686aea5..2b9409d 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/IdropConfig.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/IdropConfig.java @@ -9,13 +9,39 @@ import org.apache.log4j.RollingFileAppender; import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationService; /** - * Access data about the configuration of Idrop + * Access data about the configuration of Idrop. This serves as a view to the loaded cache of properties that iDrop consults. + * The properties are originally 'bootstrapped' at load time and resolved from various sources to come up with the operative set. + * This bootstrapping is done by the {@link IdropConfigurationService}. + * <p/> + * In normal operation, this config class is queried by iDrop to save database accesses. When any configuration information is updated, this + * is through the <code>IdropConfigurationService</code>, which will make necessary database updates, and then update this cache. * * @author Mike Conway - DICE (www.irods.org) */ public class IdropConfig { private final Properties idropProperties; + + /** + * Given a key, get the value in the cached properties (this is not going against the config database) + * @param propKey <code>String</code> with the key of the property + * @return <code>String</code> with the resulting value, or <code>null</code> if not found + */ + public String getPropertyForKey(final String propKey) { + return idropProperties.getProperty(propKey); + } + + /** + * General method to set a property in the cached properties (this does not update the config database) + * @param propKey <code>String</code> with the name of the property, cannot be null + * @param propValue <code>String</code> with the value of the property, can be null + */ + public void setProperty(final String propKey, final String propValue) { + if (propKey == null) { + throw new IllegalArgumentException("null propKey"); + } + idropProperties.put(propKey, propValue); + } public Properties getIdropProperties() { return idropProperties; diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/SetupWizard.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/SetupWizard.java index d378f25..e8fde6d 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/SetupWizard.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/SetupWizard.java @@ -10,17 +10,32 @@ */ package org.irods.jargon.idrop.desktop.systraygui.viscomponents; +import org.irods.jargon.idrop.desktop.systraygui.IDROPCore; +import org.irods.jargon.idrop.desktop.systraygui.iDrop; +import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationService; +import org.irods.jargon.idrop.exceptions.IdropException; +import org.irods.jargon.idrop.exceptions.IdropRuntimeException; +import org.openide.util.Exceptions; +import org.slf4j.LoggerFactory; + /** * * @author mikeconway */ public class SetupWizard extends javax.swing.JDialog { + private final IDROPCore idropCore; + private final IdropConfigurationService idropConfigurationService; + private static final org.slf4j.Logger log = LoggerFactory.getLogger(SetupWizard.class); + /** Creates new form SetupWizard */ public SetupWizard(final java.awt.Frame parent, final boolean modal) { super(parent, modal); super.setLocationRelativeTo(parent); initComponents(); + iDrop idrop = (iDrop) parent; + idropCore = idrop.getiDropCore(); + idropConfigurationService = idropCore.getIdropConfigurationService(); } /** @@ -175,31 +190,15 @@ public class SetupWizard extends javax.swing.JDialog { private void btnSeeSystemTrayNoActionPerformed( final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnSeeSystemTrayNoActionPerformed - // TODO add your handling code here: + log.info("indicates system try not shown, set to always load gui"); + try { + idropConfigurationService.updateConfig(IdropConfigurationService.SHOW_GUI, "true"); + log.info("config is updated"); + } catch (IdropException ex) { + log.error("error updating configuration", ex); + throw new IdropRuntimeException("error updating configuration", ex); + } }// GEN-LAST:event_btnSeeSystemTrayNoActionPerformed - - /** - * @param args - * the command line arguments - */ - public static void main(final String args[]) { - java.awt.EventQueue.invokeLater(new Runnable() { - - @Override - public void run() { - SetupWizard dialog = new SetupWizard(new javax.swing.JFrame(), - true); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - - @Override - public void windowClosing(final java.awt.event.WindowEvent e) { - System.exit(0); - } - }); - dialog.setVisible(true); - } - }); - } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnSeeSystemTrayNo; private javax.swing.JButton btnSeeSystemTrayYes; diff --git a/idrop-swing/src/main/resources/idrop.properties b/idrop-swing/src/main/resources/idrop.properties index 5144ca5..674b76e 100644 --- a/idrop-swing/src/main/resources/idrop.properties +++ b/idrop-swing/src/main/resources/idrop.properties @@ -3,7 +3,7 @@ login.preset=false force.mode=false force.no.synch=false advanced.view=true -show.startup=false +show.startup=true idrop.show.gui=true transfer.database=transferDatabase login.preset.host=diamond.ils.unc.edu |