diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java
index 3fab7af47f..b0f288673b 100755
--- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java
+++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java
@@ -30,7 +30,8 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
/**
- * This class contains business logic for saving and validating settings for central repository.
+ * This class contains business logic for saving and validating settings for
+ * central repository.
*/
public class CentralRepoDbManager {
@@ -42,35 +43,40 @@ public class CentralRepoDbManager {
private static final String DISABLED_DUE_TO_FAILURE_KEY = "disabledDueToFailure";
private static volatile CentralRepoDbChoice savedChoice = null;
-
+
private static final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(CentralRepoDbManager.class);
-
+
private static final Object dbChoiceLock = new Object();
private static final Object disabledDueToFailureLock = new Object();
-
-
-
+
/**
- * This saves the currently selected database choice and clears any disabledDueToFailure flag.
- * @param choice The choice to save.
- * @return The newly saved choice.
+ * This saves the currently selected database choice and clears any
+ * disabledDueToFailure flag.
+ *
+ * @param choice The choice to save.
+ *
+ * @return The newly saved choice.
*/
public static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) {
return saveDbChoice(choice, true);
}
-
+
/**
* This saves the currently selected database choice.
- * @param choice The choice to save.
- * @param clearDisabledDueToError Whether or not to clear the 'disabledDueToFailure' settings key.
- * @return The newly saved choice.
+ *
+ * @param choice The choice to save.
+ * @param clearDisabledDueToError Whether or not to clear the
+ * 'disabledDueToFailure' settings key.
+ *
+ * @return The newly saved choice.
*/
public static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice, boolean clearDisabledDueToError) {
- synchronized(dbChoiceLock) {
+ synchronized (dbChoiceLock) {
// clear disabling due to a failure
- if (clearDisabledDueToError)
+ if (clearDisabledDueToError) {
setDisabledDueToFailure(false);
-
+ }
+
// change the settings
CentralRepoDbChoice newChoice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice;
CentralRepoDbChoice oldChoice = savedChoice;
@@ -81,55 +87,61 @@ public class CentralRepoDbManager {
}
}
-
+
/**
- * This method indicates whether or not 'PostgreSQL using multi-user settings' is a valid option.
- * @return True if 'PostgreSQL using multi-user settings' is valid.
+ * This method indicates whether or not 'PostgreSQL using multi-user
+ * settings' is a valid option.
+ *
+ * @return True if 'PostgreSQL using multi-user settings' is valid.
*/
public static boolean isPostgresMultiuserAllowed() {
// if multi user mode is not enabled, then this cannot be used
- if (!UserPreferences.getIsMultiUserModeEnabled())
+ if (!UserPreferences.getIsMultiUserModeEnabled()) {
return false;
-
+ }
// also validate the connection as well
- PostgresCentralRepoSettings multiUserSettings =
- new PostgresCentralRepoSettings(PostgresSettingsLoader.MULTIUSER_SETTINGS_LOADER);
-
+ PostgresCentralRepoSettings multiUserSettings
+ = new PostgresCentralRepoSettings(PostgresSettingsLoader.MULTIUSER_SETTINGS_LOADER);
+
return multiUserSettings.testStatus() == DatabaseTestResult.TESTED_OK;
}
-
/**
- * This method loads the selectedPlatform boolean from the config file if it is set.
+ * This method loads the selectedPlatform boolean from the config file if it
+ * is set.
*/
public static CentralRepoDbChoice getSavedDbChoice() {
- synchronized(dbChoiceLock) {
+ synchronized (dbChoiceLock) {
if (savedChoice == null) {
String selectedPlatformString = ModuleSettings.getConfigSetting(CENTRAL_REPOSITORY_SETTINGS_KEY, DB_SELECTED_PLATFORM_KEY); // NON-NLS
savedChoice = fromKey(selectedPlatformString);
}
- return savedChoice;
+ return savedChoice;
}
}
-
+
/**
- * This method disables the central repository and indicates through a flag that this was due to a failure during database setup.
- * This is used when re-enabling multi-user as a flag to determine whether or not CR should be re-enabled.
+ * This method disables the central repository and indicates through a flag
+ * that this was due to a failure during database setup. This is used when
+ * re-enabling multi-user as a flag to determine whether or not CR should be
+ * re-enabled.
*/
public static void disableDueToFailure() {
CentralRepoDbUtil.setUseCentralRepo(false);
setDisabledDueToFailure(true);
}
-
+
/**
- * This method sets whether or not the repository has been disabled due to a database setup issue;
- * This is used when re-enabling multi-user as a flag to determine whether or not CR should be re-enabled.
- *
- * @param disabledDueToFailure Whether or not the repository has been disabled due to a database setup issue.
+ * This method sets whether or not the repository has been disabled due to a
+ * database setup issue; This is used when re-enabling multi-user as a flag
+ * to determine whether or not CR should be re-enabled.
+ *
+ * @param disabledDueToFailure Whether or not the repository has been
+ * disabled due to a database setup issue.
*/
private static void setDisabledDueToFailure(boolean disabledDueToFailure) {
- synchronized(disabledDueToFailureLock) {
+ synchronized (disabledDueToFailureLock) {
boolean oldValue = isDisabledDueToFailure();
ModuleSettings.setConfigSetting(CENTRAL_REPOSITORY_SETTINGS_KEY, DISABLED_DUE_TO_FAILURE_KEY, Boolean.toString(disabledDueToFailure));
propertyChangeSupport.firePropertyChange("disabledDueToFailure", oldValue, disabledDueToFailure);
@@ -137,36 +149,38 @@ public class CentralRepoDbManager {
}
/**
- * This method retrieves setting whether or not the repository has been disabled due to a database setup issue;
- * this is used when re-enabling multi-user as a flag to determine whether or not CR should be re-enabled.
- *
- * @return Whether or not the repository has been disabled due to a database setup issue.
+ * This method retrieves setting whether or not the repository has been
+ * disabled due to a database setup issue; this is used when re-enabling
+ * multi-user as a flag to determine whether or not CR should be re-enabled.
+ *
+ * @return Whether or not the repository has been disabled due to a database
+ * setup issue.
*/
public static boolean isDisabledDueToFailure() {
- synchronized(disabledDueToFailureLock) {
+ synchronized (disabledDueToFailureLock) {
return Boolean.toString(true).equals(ModuleSettings.getConfigSetting(CENTRAL_REPOSITORY_SETTINGS_KEY, DISABLED_DUE_TO_FAILURE_KEY));
}
}
/**
- * This method adds a property change listener.
- * NOTE: currently only listening for changes in currently saved db choice and disabling due to failure.
- *
- * @param listener The listener for the event.
+ * This method adds a property change listener. NOTE: currently only
+ * listening for changes in currently saved db choice and disabling due to
+ * failure.
+ *
+ * @param listener The listener for the event.
*/
public static void addPropertyChangeListener(PropertyChangeListener listener) {
- propertyChangeSupport.addPropertyChangeListener(listener);
- }
+ propertyChangeSupport.addPropertyChangeListener(listener);
+ }
/**
* This method removes a propert change listener.
- * @param listener The listener to remove.
+ *
+ * @param listener The listener to remove.
*/
- public static void removePropertyChangeListener(PropertyChangeListener listener) {
- propertyChangeSupport.removePropertyChangeListener(listener);
- }
-
-
+ public static void removePropertyChangeListener(PropertyChangeListener listener) {
+ propertyChangeSupport.removePropertyChangeListener(listener);
+ }
private static CentralRepoDbChoice fromKey(String keyName) {
for (CentralRepoDbChoice dbChoice : CentralRepoDbChoice.values()) {
@@ -178,12 +192,11 @@ public class CentralRepoDbManager {
return CentralRepoDbChoice.DISABLED;
}
-
-
/**
* This method obtains the database connectivity for central repository.
*
* @return The CentralRepository object that will be used for connection.
+ *
* @throws CentralRepoException
*/
private static CentralRepository obtainCentralRepository() throws CentralRepoException {
@@ -203,8 +216,10 @@ public class CentralRepoDbManager {
/**
* This method obtains a central repository lock.
*
- * @param db The database connection.
- * @return The lock if acquired.
+ * @param db The database connection.
+ *
+ * @return The lock if acquired.
+ *
* @throws CentralRepoException
*/
private static CoordinationService.Lock obtainCentralRepoLock(CentralRepository db) throws CentralRepoException {
@@ -227,8 +242,9 @@ public class CentralRepoDbManager {
/**
* This method updates the central repository schema if necessary.
*
- * @param db The database connectivity object.
- * @param lock The acquired lock.
+ * @param db The database connectivity object.
+ * @param lock The acquired lock.
+ *
* @throws CentralRepoException
*/
private static void updatedDbSchema(CentralRepository db, CoordinationService.Lock lock) throws CentralRepoException {
@@ -257,9 +273,9 @@ public class CentralRepoDbManager {
}
/**
- * This method upgrades the current Central Reposity schema to the newest version. If the
- * upgrade fails, the Central Repository will be disabled and the current
- * settings will be cleared.
+ * This method upgrades the current Central Reposity schema to the newest
+ * version. If the upgrade fails, the Central Repository will be disabled
+ * and the current settings will be cleared.
*/
@NbBundle.Messages(value = {"EamDbUtil.centralRepoDisabled.message= The Central Repository has been disabled.", "EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade Central Repository.", "EamDbUtil.centralRepoConnectionFailed.message=Unable to connect to Central Repository.", "EamDbUtil.exclusiveLockAquisitionFailure.message=Unable to acquire exclusive lock for Central Repository."})
public static void upgradeDatabase() throws CentralRepoException {
@@ -296,8 +312,6 @@ public class CentralRepoDbManager {
}
}
-
-
private DatabaseTestResult testingStatus;
private CentralRepoDbChoice selectedDbChoice;
@@ -314,10 +328,10 @@ public class CentralRepoDbManager {
dbSettingsSqlite = new SqliteCentralRepoSettings();
}
-
/**
* This method retrieves the current multi-user database settings.
- * @return The current multi-user database settings.
+ *
+ * @return The current multi-user database settings.
*/
public PostgresCentralRepoSettings getDbSettingsMultiUser() {
return dbSettingsMultiUser;
@@ -325,15 +339,18 @@ public class CentralRepoDbManager {
/**
* This method retrieves the current custom postgres database settings.
- * @return The current custom postgres database settings.
+ *
+ * @return The current custom postgres database settings.
*/
public PostgresCentralRepoSettings getDbSettingsPostgres() {
return dbSettingsPostgres;
}
/**
- * This method returns the current SQLite database settings for central repository.
- * @return The current SQLite database settings
+ * This method returns the current SQLite database settings for central
+ * repository.
+ *
+ * @return The current SQLite database settings
*/
public SqliteCentralRepoSettings getDbSettingsSqlite() {
return dbSettingsSqlite;
@@ -341,7 +358,8 @@ public class CentralRepoDbManager {
/**
* This method sets up the sqlite database with default settings.
- * @throws CentralRepoException if unable to successfully set up database.
+ *
+ * @throws CentralRepoException if unable to successfully set up database.
*/
public void setupDefaultSqliteDb() throws CentralRepoException {
// change in-memory settings to default sqlite
@@ -354,67 +372,78 @@ public class CentralRepoDbManager {
createDb();
curStatus = testStatus();
}
-
+
// the only successful setup status is tested ok
if (curStatus != DatabaseTestResult.TESTED_OK) {
throw new CentralRepoException("Unable to successfully create sqlite database");
}
-
+
// if successfully got here, then save the settings
CentralRepoDbUtil.setUseCentralRepo(true);
saveNewCentralRepo();
}
/**
- * This method returns if changes to the central repository configuration were
- * successfully applied.
+ * This method returns if changes to the central repository configuration
+ * were successfully applied.
*
- * @return Returns true if the database configuration was successfully changed false
- * if it was not.
+ * @return Returns true if the database configuration was successfully
+ * changed false if it was not.
*/
public boolean wasConfigurationChanged() {
return configurationChanged;
}
private CentralRepoDbConnectivityManager getSelectedSettings() throws CentralRepoException {
- if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER)
+ if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER) {
return dbSettingsMultiUser;
- if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_CUSTOM)
+ }
+ if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_CUSTOM) {
return dbSettingsPostgres;
- if (selectedDbChoice == CentralRepoDbChoice.SQLITE)
+ }
+ if (selectedDbChoice == CentralRepoDbChoice.SQLITE) {
return dbSettingsSqlite;
- if (selectedDbChoice == CentralRepoDbChoice.DISABLED)
+ }
+ if (selectedDbChoice == CentralRepoDbChoice.DISABLED) {
return null;
-
- throw new CentralRepoException("Unknown database type: " + selectedDbChoice);
+ }
+
+ throw new CentralRepoException("Unknown database type: " + selectedDbChoice);
}
private RdbmsCentralRepoFactory getDbFactory() throws CentralRepoException {
- if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER)
+ if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER) {
return new RdbmsCentralRepoFactory(CentralRepoPlatforms.POSTGRESQL, dbSettingsMultiUser);
- if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_CUSTOM)
+ }
+ if (selectedDbChoice == CentralRepoDbChoice.POSTGRESQL_CUSTOM) {
return new RdbmsCentralRepoFactory(CentralRepoPlatforms.POSTGRESQL, dbSettingsPostgres);
- if (selectedDbChoice == CentralRepoDbChoice.SQLITE)
+ }
+ if (selectedDbChoice == CentralRepoDbChoice.SQLITE) {
return new RdbmsCentralRepoFactory(CentralRepoPlatforms.SQLITE, dbSettingsSqlite);
- if (selectedDbChoice == CentralRepoDbChoice.DISABLED)
+ }
+ if (selectedDbChoice == CentralRepoDbChoice.DISABLED) {
return null;
-
+ }
+
throw new CentralRepoException("Unknown database type: " + selectedDbChoice);
}
/**
* This method creates a central repo database if it does not already exist.
- * @return True if successful; false if unsuccessful.
+ *
+ * @return True if successful; false if unsuccessful.
+ *
* @throws CentralRepoException
*/
public boolean createDb() throws CentralRepoException {
CentralRepoDbConnectivityManager selectedDbSettings = getSelectedSettings();
- if (selectedDbSettings == null)
+ if (selectedDbSettings == null) {
throw new CentralRepoException("Unable to derive connectivity manager from settings: " + selectedDbChoice);
+ }
boolean result = false;
boolean dbCreated = true;
-
+
if (!selectedDbSettings.verifyDatabaseExists()) {
dbCreated = selectedDbSettings.createDatabase();
}
@@ -493,18 +522,20 @@ public class CentralRepoDbManager {
}
/**
- * This method retrieves the current status.
- * Note: this could be a dirty value if testing of the connection has not been performed.
- * @return The current status of the database connection.
+ * This method retrieves the current status. Note: this could be a dirty
+ * value if testing of the connection has not been performed.
+ *
+ * @return The current status of the database connection.
*/
public DatabaseTestResult getStatus() {
return testingStatus;
}
/**
- * This method retrieves the currently selected database choice.
- * NOTE: This choice may not align with the saved setting.
- * @return The currently selected database choice.
+ * This method retrieves the currently selected database choice. NOTE: This
+ * choice may not align with the saved setting.
+ *
+ * @return The currently selected database choice.
*/
public CentralRepoDbChoice getSelectedDbChoice() {
return selectedDbChoice;
@@ -518,8 +549,10 @@ public class CentralRepoDbManager {
}
/**
- * This method sets the currently selected database choice and sets the testing status to untested.
- * @param newSelected The new database choice.
+ * This method sets the currently selected database choice and sets the
+ * testing status to untested.
+ *
+ * @param newSelected The new database choice.
*/
public void setSelctedDbChoice(CentralRepoDbChoice newSelected) {
selectedDbChoice = newSelected;
@@ -527,8 +560,8 @@ public class CentralRepoDbManager {
}
/**
- * This method tests whether or not the settings have been filled in for the UI.
- * NOTE: This does not check the connectivity status of these settings.
+ * This method tests whether or not the settings have been filled in for the
+ * UI. NOTE: This does not check the connectivity status of these settings.
*
* @return True if database settings are valid.
*/
@@ -541,13 +574,11 @@ public class CentralRepoDbManager {
dbSettingsPostgres.setDbName(CENTRAL_REPO_DB_NAME);
dbSettingsPostgres.setUserName(tbDbUsername);
dbSettingsPostgres.setPassword(jpDbPassword);
- }
- else if (selectedDbChoice == CentralRepoDbChoice.SQLITE) {
+ } else if (selectedDbChoice == CentralRepoDbChoice.SQLITE) {
File databasePath = new File(tfDatabasePath);
dbSettingsSqlite.setDbName(SqliteCentralRepoSettings.DEFAULT_DBNAME);
dbSettingsSqlite.setDbDirectory(databasePath.getPath());
- }
- else if (selectedDbChoice != CentralRepoDbChoice.POSTGRESQL_MULTIUSER) {
+ } else if (selectedDbChoice != CentralRepoDbChoice.POSTGRESQL_MULTIUSER) {
throw new IllegalStateException("Central Repo has an unknown selected platform: " + selectedDbChoice);
}
@@ -555,19 +586,21 @@ public class CentralRepoDbManager {
}
/**
- * This method tests the current database settings to see if a valid connection can be made.
- * @return The result of testing the connection.
+ * This method tests the current database settings to see if a valid
+ * connection can be made.
+ *
+ * @return The result of testing the connection.
*/
public DatabaseTestResult testStatus() {
try {
CentralRepoDbConnectivityManager manager = getSelectedSettings();
- if (manager != null)
+ if (manager != null) {
testingStatus = manager.testStatus();
- }
- catch (CentralRepoException e) {
+ }
+ } catch (CentralRepoException e) {
logger.log(Level.WARNING, "unable to test status of db connection in central repo", e);
}
-
+
return testingStatus;
}
}
diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form
index 8d074c0ef3..d8460c48c7 100644
--- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form
+++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form
@@ -38,7 +38,7 @@
-
+
@@ -94,8 +94,11 @@
+
+
+
-
+
@@ -109,8 +112,11 @@
+
+
+
-
+
@@ -127,7 +133,7 @@
-
+
@@ -136,8 +142,11 @@
+
+
+
-
+
@@ -154,7 +163,7 @@
-
+
@@ -163,8 +172,11 @@
+
+
+
-
+
@@ -181,7 +193,7 @@
-
+
@@ -190,8 +202,11 @@
+
+
+
-
+
@@ -208,7 +223,7 @@
-
+
@@ -218,13 +233,13 @@
-
+
-
+
@@ -238,8 +253,11 @@
+
+
+
-
+
@@ -296,7 +314,7 @@
-
+
@@ -304,11 +322,11 @@
-
-
-
+
+
+
-
+
@@ -362,10 +380,10 @@
-
-
+
+
-
+
diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java
index fb78f049b5..675e7c8807 100644
--- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java
+++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java
@@ -41,7 +41,6 @@ import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;
-import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
@@ -61,15 +60,17 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteCentralRepoSettin
public class EamDbSettingsDialog extends JDialog {
private static final Logger logger = Logger.getLogger(EamDbSettingsDialog.class.getName());
-
+
private static final long serialVersionUID = 1L;
-
+
/**
- * This class handles displaying and rendering drop down menu for database choices in central repo.
+ * This class handles displaying and rendering drop down menu for database
+ * choices in central repo.
*/
private class DbChoiceRenderer extends JLabel implements ListCellRenderer, Serializable {
+
private static final long serialVersionUID = 1L;
-
+
@Override
public Component getListCellRendererComponent(
JList extends CentralRepoDbChoice> list, CentralRepoDbChoice value,
@@ -82,22 +83,20 @@ public class EamDbSettingsDialog extends JDialog {
return this;
}
}
-
-
+
private final Collection textBoxes;
private final TextBoxChangedListener textBoxChangedListener;
private final CentralRepoDbManager manager = new CentralRepoDbManager();
private final DbChoiceRenderer DB_CHOICE_RENDERER = new DbChoiceRenderer();
-
+
public EamDbSettingsDialog() {
this(null);
}
-
+
private boolean isDbChoiceSelectable(CentralRepoDbChoice item) {
- return (item != CentralRepoDbChoice.POSTGRESQL_MULTIUSER || manager.isPostgresMultiuserAllowed());
+ return (item != CentralRepoDbChoice.POSTGRESQL_MULTIUSER || CentralRepoDbManager.isPostgresMultiuserAllowed());
}
-
-
+
/**
* Creates new form EamDbSettingsDialog
*/
@@ -123,7 +122,7 @@ public class EamDbSettingsDialog extends JDialog {
if (pathname.isDirectory()) {
return true;
}
- return pathname.getName().equalsIgnoreCase(SqliteCentralRepoSettings.DEFAULT_DBNAME);
+ return pathname.getName().equalsIgnoreCase(SqliteCentralRepoSettings.DEFAULT_DBNAME);
}
@Override
@@ -131,32 +130,34 @@ public class EamDbSettingsDialog extends JDialog {
return "Directories and Central Repository databases";
}
});
-
+
setupDbChoice(initialMenuItem);
valid();
display();
}
-
private void setupDbChoice(CentralRepoDbChoice initialMenuItem) {
// setup initially selected item
- CentralRepoDbChoice toSelect = (initialMenuItem == null) ?
- (Arrays.asList(CentralRepoDbChoice.DB_CHOICES).contains(manager.getSelectedDbChoice())) ?
- manager.getSelectedDbChoice() :
- CentralRepoDbChoice.DB_CHOICES[0] :
- initialMenuItem;
-
+ CentralRepoDbChoice toSelect = (initialMenuItem == null)
+ ? (Arrays.asList(CentralRepoDbChoice.DB_CHOICES).contains(manager.getSelectedDbChoice()))
+ ? manager.getSelectedDbChoice()
+ : CentralRepoDbChoice.DB_CHOICES[0]
+ : initialMenuItem;
+
cbDatabaseType.setRenderer(DB_CHOICE_RENDERER);
changeDbSelection(toSelect);
}
-
-
-
- /**
- * This method prompts user based on testing status (i.e. failure to connect, invalid schema, db does not exist, etc.).
- * @param manager The manager to use when setting up the database.
- * @param dialog If non-null value, validates settings and updates 'okay' button enabled state.
- * @return Whether or not the ultimate status after prompts is okay to continue.
+
+ /**
+ * This method prompts user based on testing status (i.e. failure to
+ * connect, invalid schema, db does not exist, etc.).
+ *
+ * @param manager The manager to use when setting up the database.
+ * @param dialog If non-null value, validates settings and updates 'okay'
+ * button enabled state.
+ *
+ * @return Whether or not the ultimate status after prompts is okay to
+ * continue.
*/
@NbBundle.Messages({"EamDbSettingsDialog.okButton.corruptDatabaseExists.title=Error Loading Central Repository Database",
"EamDbSettingsDialog.okButton.corruptDatabaseExists.message=Central Repository Database exists but is not the right format. Manually delete it or choose a different path (if applicable).",
@@ -184,13 +185,13 @@ public class EamDbSettingsDialog extends JDialog {
}
return (manager.getStatus() == DatabaseTestResult.TESTED_OK);
- }
-
-
- /**
- * This method prompts the user whether or not they would like to create a database in the instance that
- * it doesn't exist.
- * @param manager The manager to use when setting up the database.
+ }
+
+ /**
+ * This method prompts the user whether or not they would like to create a
+ * database in the instance that it doesn't exist.
+ *
+ * @param manager The manager to use when setting up the database.
* @param dialog If non-null value, validates settings and updates 'okay'
* button enabled state.
*
@@ -204,26 +205,28 @@ public class EamDbSettingsDialog extends JDialog {
JOptionPane.YES_NO_OPTION)) {
try {
manager.createDb();
-
+
} catch (CentralRepoException e) {
onPromptStatusError(manager);
return false;
}
-
+
if (dialog != null) {
dialog.valid();
}
return true;
}
-
+
return manager.testStatus() == DatabaseTestResult.TESTED_OK;
}
-
/**
- * When an error occurs while going through promptTestStatusWarning, this method is called.
- * @param manager1 The manager to use as service class.
- * @throws HeadlessException
+ * When an error occurs while going through promptTestStatusWarning, this
+ * method is called.
+ *
+ * @param manager1 The manager to use as service class.
+ *
+ * @throws HeadlessException
*/
private static void onPromptStatusError(CentralRepoDbManager manager1) {
// in the event that there is a failure to connect, notify user with corresponding message
@@ -240,7 +243,6 @@ public class EamDbSettingsDialog extends JDialog {
Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
JOptionPane.WARNING_MESSAGE);
}
-
/**
* This method is called from within the constructor to initialize the form.
@@ -296,7 +298,8 @@ public class EamDbSettingsDialog extends JDialog {
pnSQLiteSettings.setLayout(new java.awt.GridBagLayout());
org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbDatabasePath.text")); // NOI18N
- lbDatabasePath.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbDatabasePath.setMaximumSize(new java.awt.Dimension(191, 16));
+ lbDatabasePath.setPreferredSize(new java.awt.Dimension(100, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
@@ -307,7 +310,8 @@ public class EamDbSettingsDialog extends JDialog {
pnSQLiteSettings.add(lbDatabasePath, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(lbHostName, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbHostName.text")); // NOI18N
- lbHostName.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbHostName.setMaximumSize(new java.awt.Dimension(195, 16));
+ lbHostName.setPreferredSize(new java.awt.Dimension(110, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
@@ -322,12 +326,14 @@ public class EamDbSettingsDialog extends JDialog {
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridheight = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 6);
pnSQLiteSettings.add(tbDbHostname, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(lbPort, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbPort.text")); // NOI18N
- lbPort.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbPort.setMaximumSize(new java.awt.Dimension(132, 16));
+ lbPort.setPreferredSize(new java.awt.Dimension(90, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
@@ -342,12 +348,14 @@ public class EamDbSettingsDialog extends JDialog {
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridheight = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 6);
pnSQLiteSettings.add(tbDbPort, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(lbUserName, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbUserName.text")); // NOI18N
- lbUserName.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbUserName.setMaximumSize(new java.awt.Dimension(172, 16));
+ lbUserName.setPreferredSize(new java.awt.Dimension(100, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 7;
@@ -362,12 +370,14 @@ public class EamDbSettingsDialog extends JDialog {
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 7;
gridBagConstraints.gridheight = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 6);
pnSQLiteSettings.add(tbDbUsername, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbUserPassword.text")); // NOI18N
- lbUserPassword.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbUserPassword.setMaximumSize(new java.awt.Dimension(194, 16));
+ lbUserPassword.setPreferredSize(new java.awt.Dimension(110, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 9;
@@ -382,14 +392,15 @@ public class EamDbSettingsDialog extends JDialog {
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 9;
gridBagConstraints.gridheight = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 6);
pnSQLiteSettings.add(jpDbPassword, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbDatabaseType.text")); // NOI18N
- lbDatabaseType.setMaximumSize(new java.awt.Dimension(80, 14));
+ lbDatabaseType.setMaximumSize(new java.awt.Dimension(180, 14));
lbDatabaseType.setMinimumSize(new java.awt.Dimension(80, 14));
- lbDatabaseType.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbDatabaseType.setPreferredSize(new java.awt.Dimension(100, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
@@ -400,7 +411,8 @@ public class EamDbSettingsDialog extends JDialog {
pnSQLiteSettings.add(lbDatabaseType, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseDesc, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbDatabaseDesc.text")); // NOI18N
- lbDatabaseDesc.setPreferredSize(new java.awt.Dimension(80, 14));
+ lbDatabaseDesc.setMaximumSize(new java.awt.Dimension(182, 16));
+ lbDatabaseDesc.setPreferredSize(new java.awt.Dimension(100, 14));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 11;
@@ -452,7 +464,7 @@ public class EamDbSettingsDialog extends JDialog {
pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pathPanelLayout.createSequentialGroup()
.addGap(0, 0, 0)
- .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(tfDatabasePath, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(bnDatabasePathFileOpen)
.addGap(0, 0, 0))
@@ -471,6 +483,7 @@ public class EamDbSettingsDialog extends JDialog {
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 6);
pnSQLiteSettings.add(pathPanel, gridBagConstraints);
@@ -492,9 +505,9 @@ public class EamDbSettingsDialog extends JDialog {
typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(typePanelLayout.createSequentialGroup()
.addGap(0, 0, 0)
- .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(cbDatabaseType, 0, 210, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
+ .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
typePanelLayout.setVerticalGroup(
@@ -545,7 +558,7 @@ public class EamDbSettingsDialog extends JDialog {
.addComponent(bnOk)
.addGap(11, 11, 11)
.addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE))
.addContainerGap())
);
@@ -575,12 +588,10 @@ public class EamDbSettingsDialog extends JDialog {
if (manager.getSelectedDbChoice() == CentralRepoDbChoice.SQLITE) {
updatePostgresFields(false);
updateSqliteFields(true);
- }
- else if (manager.getSelectedDbChoice() == CentralRepoDbChoice.POSTGRESQL_CUSTOM) {
+ } else if (manager.getSelectedDbChoice() == CentralRepoDbChoice.POSTGRESQL_CUSTOM) {
updatePostgresFields(true);
updateSqliteFields(false);
- }
- else {
+ } else {
updatePostgresFields(false);
updateSqliteFields(false);
}
@@ -615,53 +626,63 @@ public class EamDbSettingsDialog extends JDialog {
"EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.",
"EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to central repository database."})
private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOkActionPerformed
- if (testStatusAndCreate(this, manager, this))
+ if (testStatusAndCreate(this, manager, this)) {
dispose();
+ }
}//GEN-LAST:event_bnOkActionPerformed
-
/**
- * This method tests status for central repo db / creation and prompts user accordingly.
- * @param parent The parent component (the anchor for displaying dialogs).
- * @param manager The central repo db manager with settings to be tested and saved.
- * @return Whether or not central repo db was successfully be created or found.
+ * This method tests status for central repo db / creation and prompts user
+ * accordingly.
+ *
+ * @param parent The parent component (the anchor for displaying dialogs).
+ * @param manager The central repo db manager with settings to be tested and
+ * saved.
+ *
+ * @return Whether or not central repo db was successfully be created or
+ * found.
*/
public static boolean testStatusAndCreate(Component parent, CentralRepoDbManager manager) {
return testStatusAndCreate(parent, manager, null);
}
-
-
+
/**
- * This method tests status for central repo db / creation and prompts user accordingly.
- * @param parent The parent component (the anchor for displaying dialogs).
- * @param manager The central repo db manager with settings to be tested and saved.
- * @param dialog The db settings dialog; if non-null, will validate okay button state.
- * @return Whether or not central repo db was successfully be created or found.
+ * This method tests status for central repo db / creation and prompts user
+ * accordingly.
+ *
+ * @param parent The parent component (the anchor for displaying dialogs).
+ * @param manager The central repo db manager with settings to be tested and
+ * saved.
+ * @param dialog The db settings dialog; if non-null, will validate okay
+ * button state.
+ *
+ * @return Whether or not central repo db was successfully be created or
+ * found.
*/
private static boolean testStatusAndCreate(Component parent, CentralRepoDbManager manager, EamDbSettingsDialog dialog) {
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
manager.testStatus();
-
- if (dialog != null)
+
+ if (dialog != null) {
dialog.valid();
-
+ }
+
boolean testedOk = promptTestStatusWarnings(manager, dialog);
if (!testedOk) {
parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return false;
}
-
- try{
+
+ try {
manager.saveNewCentralRepo();
- }
- catch (CentralRepoException e) {
+ } catch (CentralRepoException e) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(parent,
- Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
- Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
- JOptionPane.WARNING_MESSAGE);
+ Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
+ Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
+ JOptionPane.WARNING_MESSAGE);
});
-
+
parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return false;
}
@@ -669,14 +690,13 @@ public class EamDbSettingsDialog extends JDialog {
parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return true;
}
-
-
+
/**
- * This method returns if changes to the central repository configuration were
- * successfully applied.
+ * This method returns if changes to the central repository configuration
+ * were successfully applied.
*
- * @return True if the database configuration was successfully changed; false
- * if it was not.
+ * @return True if the database configuration was successfully changed;
+ * false if it was not.
*/
public boolean wasConfigurationChanged() {
return manager.wasConfigurationChanged();
@@ -696,11 +716,10 @@ public class EamDbSettingsDialog extends JDialog {
if (isDbChoiceSelectable(selectedItem)) {
manager.setSelctedDbChoice(selectedItem);
cbDatabaseType.setSelectedItem(selectedItem);
- }
- else {
+ } else {
cbDatabaseType.setSelectedItem(manager.getSelectedDbChoice());
}
-
+
customizeComponents();
}
@@ -712,14 +731,14 @@ public class EamDbSettingsDialog extends JDialog {
private void displayDatabaseSettings(CentralRepoDbChoice choice) {
boolean isSqlite = choice == CentralRepoDbChoice.SQLITE;
boolean isPostgres = choice == CentralRepoDbChoice.POSTGRESQL_CUSTOM;
-
+
lbDatabasePath.setVisible(isSqlite);
tfDatabasePath.setVisible(isSqlite);
lbDatabaseDesc.setVisible(isSqlite);
dataBaseFileTextArea.setVisible(isSqlite);
lbSingleUserSqLite.setVisible(isSqlite);
bnDatabasePathFileOpen.setVisible(isSqlite);
-
+
lbHostName.setVisible(isPostgres);
tbDbHostname.setVisible(isPostgres);
lbPort.setVisible(isPostgres);
@@ -800,7 +819,7 @@ public class EamDbSettingsDialog extends JDialog {
* Adds a change listener to a collection of text fields.
*
* @param textFields The text fields.
- * @param listener The change listener.
+ * @param listener The change listener.
*/
private static void addDocumentListeners(Collection textFields, TextBoxChangedListener listener) {
textFields.forEach((textField) -> {
@@ -823,8 +842,7 @@ public class EamDbSettingsDialog extends JDialog {
// && !tbDbName.getText().trim().isEmpty()
&& !tbDbUsername.getText().trim().isEmpty()
&& 0 < jpDbPassword.getPassword().length;
- }
- else if (manager.getSelectedDbChoice() == CentralRepoDbChoice.SQLITE) {
+ } else if (manager.getSelectedDbChoice() == CentralRepoDbChoice.SQLITE) {
result = !tfDatabasePath.getText().trim().isEmpty();
}
@@ -841,7 +859,6 @@ public class EamDbSettingsDialog extends JDialog {
&& databaseSettingsAreValid();
}
-
/**
* Validates that the form is filled out correctly for our usage.
*
@@ -867,9 +884,7 @@ public class EamDbSettingsDialog extends JDialog {
return true;
}
-
-
-
+
/**
* Tests whether or not the database settings are valid.
*
@@ -878,16 +893,15 @@ public class EamDbSettingsDialog extends JDialog {
private boolean databaseSettingsAreValid() {
try {
manager.testDatabaseSettingsAreValid(
- tbDbHostname.getText().trim(),
- tbDbPort.getText().trim(),
- tbDbUsername.getText().trim(),
- tfDatabasePath.getText().trim(),
+ tbDbHostname.getText().trim(),
+ tbDbPort.getText().trim(),
+ tbDbUsername.getText().trim(),
+ tfDatabasePath.getText().trim(),
new String(jpDbPassword.getPassword()));
- }
- catch (CentralRepoException | NumberFormatException | IllegalStateException e) {
+ } catch (CentralRepoException | NumberFormatException | IllegalStateException e) {
return false;
}
-
+
return true;
}