mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 01:07:42 +00:00
updates from PR
This commit is contained in:
parent
d093a2169b
commit
167c12f00c
@ -18,23 +18,22 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.centralrepository.datamodel;
|
||||
|
||||
import org.openide.util.NbBundle.Messages;
|
||||
|
||||
/**
|
||||
* the database choices available for central repo
|
||||
*/
|
||||
public class CentralRepoDbChoice {
|
||||
public static final CentralRepoDbChoice DISABLED = new CentralRepoDbChoice("Disabled", CentralRepoPlatforms.DISABLED);
|
||||
|
||||
public static final CentralRepoDbChoice SQLITE = new CentralRepoDbChoice("Sqlite", "SQLite", CentralRepoPlatforms.SQLITE);
|
||||
|
||||
public static final CentralRepoDbChoice POSTGRESQL_MULTIUSER =
|
||||
new CentralRepoDbChoice("PostgreSQL_Multiuser", "PostgreSQL using multi-user settings", CentralRepoPlatforms.POSTGRESQL);
|
||||
|
||||
public static final CentralRepoDbChoice POSTGRESQL_CUSTOM =
|
||||
new CentralRepoDbChoice("PostgreSQL", "Custom PostgreSQL", CentralRepoPlatforms.POSTGRESQL);
|
||||
|
||||
public static final CentralRepoDbChoice[] CHOICES = new CentralRepoDbChoice[]{
|
||||
DISABLED, SQLITE, POSTGRESQL_MULTIUSER, POSTGRESQL_CUSTOM
|
||||
};
|
||||
@Messages({
|
||||
"CentralRepoDbChoice.Disabled.Text=Disabled",
|
||||
"CentralRepoDbChoice.Sqlite.Text=SQLite",
|
||||
"CentralRepoDbChoice.PostgreSQL_Multiuser.Text=PostgreSQL using multi-user settings",
|
||||
"CentralRepoDbChoice.PostgreSQL.Text=Custom PostgreSQL",
|
||||
})
|
||||
public enum CentralRepoDbChoice {
|
||||
DISABLED("Disabled", Bundle.CentralRepoDbChoice_Disabled_Text(), CentralRepoPlatforms.DISABLED),
|
||||
SQLITE("Sqlite", Bundle.CentralRepoDbChoice_Sqlite_Text(), CentralRepoPlatforms.SQLITE),
|
||||
POSTGRESQL_MULTIUSER("PostgreSQL_Multiuser", Bundle.CentralRepoDbChoice_PostgreSQL_Multiuser_Text(), CentralRepoPlatforms.POSTGRESQL),
|
||||
POSTGRESQL_CUSTOM("PostgreSQL", Bundle.CentralRepoDbChoice_PostgreSQL_Text(), CentralRepoPlatforms.POSTGRESQL);
|
||||
|
||||
public static final CentralRepoDbChoice[] DB_CHOICES = new CentralRepoDbChoice[]{
|
||||
SQLITE, POSTGRESQL_MULTIUSER, POSTGRESQL_CUSTOM
|
||||
@ -50,10 +49,6 @@ public class CentralRepoDbChoice {
|
||||
this.title = title;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
CentralRepoDbChoice(String key, CentralRepoPlatforms platform) {
|
||||
this(key, key, platform);
|
||||
}
|
||||
|
||||
public String getSettingKey() {
|
||||
return settingKey;
|
||||
|
@ -37,14 +37,14 @@ public class CentralRepoDbManager {
|
||||
|
||||
|
||||
|
||||
private static volatile CentralRepoDbChoice SAVED_CHOICE = null;
|
||||
private static volatile CentralRepoDbChoice savedChoice = null;
|
||||
|
||||
/**
|
||||
* Save the selected platform to the config file.
|
||||
*/
|
||||
public static synchronized CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) {
|
||||
choice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice;
|
||||
SAVED_CHOICE = choice;
|
||||
savedChoice = choice;
|
||||
ModuleSettings.setConfigSetting("CentralRepository", "db.selectedPlatform", choice.getSettingKey());
|
||||
return choice;
|
||||
}
|
||||
@ -53,17 +53,17 @@ public class CentralRepoDbManager {
|
||||
* Load the selectedPlatform boolean from the config file, if it is set.
|
||||
*/
|
||||
public static synchronized CentralRepoDbChoice getSavedDbChoice() {
|
||||
if (SAVED_CHOICE == null) {
|
||||
if (savedChoice == null) {
|
||||
String selectedPlatformString = ModuleSettings.getConfigSetting("CentralRepository", "db.selectedPlatform"); // NON-NLS
|
||||
SAVED_CHOICE = fromKey(selectedPlatformString);
|
||||
savedChoice = fromKey(selectedPlatformString);
|
||||
}
|
||||
|
||||
return SAVED_CHOICE;
|
||||
return savedChoice;
|
||||
}
|
||||
|
||||
|
||||
private static CentralRepoDbChoice fromKey(String keyName) {
|
||||
for (CentralRepoDbChoice dbChoice : CentralRepoDbChoice.CHOICES) {
|
||||
for (CentralRepoDbChoice dbChoice : CentralRepoDbChoice.values()) {
|
||||
if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
|
||||
return dbChoice;
|
||||
}
|
||||
@ -201,8 +201,8 @@ public class CentralRepoDbManager {
|
||||
|
||||
public CentralRepoDbManager() {
|
||||
selectedDbChoice = getSavedDbChoice();
|
||||
dbSettingsPostgres = new PostgresCentralRepoSettings(PostgresSettingsLoader.CUSTOM_LOADER);
|
||||
dbSettingsMultiUser = new PostgresCentralRepoSettings(PostgresSettingsLoader.MULTIUSER_LOADER);
|
||||
dbSettingsPostgres = new PostgresCentralRepoSettings(PostgresSettingsLoader.CUSTOM_SETTINGS_LOADER);
|
||||
dbSettingsMultiUser = new PostgresCentralRepoSettings(PostgresSettingsLoader.MULTIUSER_SETTINGS_LOADER);
|
||||
dbSettingsSqlite = new SqliteCentralRepoSettings();
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ public class CentralRepoDbManager {
|
||||
}
|
||||
|
||||
// the only successful setup status is tested ok
|
||||
if (curStatus != DatabaseTestResult.TESTEDOK) {
|
||||
if (curStatus != DatabaseTestResult.TESTED_OK) {
|
||||
throw new CentralRepoException("Unable to successfully create sqlite database");
|
||||
}
|
||||
|
||||
@ -320,7 +320,7 @@ public class CentralRepoDbManager {
|
||||
throw new CentralRepoException(schemaError);
|
||||
}
|
||||
|
||||
testingStatus = DatabaseTestResult.TESTEDOK;
|
||||
testingStatus = DatabaseTestResult.TESTED_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ public class CentralRepoDbManager {
|
||||
selectedDbSettings.saveSettings();
|
||||
// Load those newly saved settings into the postgres db manager instance
|
||||
// in case we are still using the same instance.
|
||||
if (selectedDbChoice != null && selectedDbSettings != CentralRepoDbChoice.DISABLED) {
|
||||
if (selectedDbChoice != null && selectedDbChoice != CentralRepoDbChoice.DISABLED) {
|
||||
try {
|
||||
logger.info("Saving central repo settings for db: " + selectedDbSettings);
|
||||
CentralRepository.getInstance().updateSettings();
|
||||
|
@ -81,7 +81,7 @@ public class CentralRepoPostgresSettingsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleTry(TryHandler handler) {
|
||||
private static void logException(TryHandler handler) {
|
||||
try {
|
||||
handler.operation();
|
||||
}
|
||||
@ -109,14 +109,14 @@ public class CentralRepoPostgresSettingsUtil {
|
||||
return settings;
|
||||
}
|
||||
|
||||
handleTry(() -> settings.setHost(valOrDefault(muConn.getHost(), DEFAULT_HOST)));
|
||||
handleTry(() -> settings.setDbName(DEFAULT_DBNAME));
|
||||
handleTry(() -> settings.setUserName(valOrDefault(muConn.getUserName(), DEFAULT_USERNAME)));
|
||||
logException(() -> settings.setHost(valOrDefault(muConn.getHost(), DEFAULT_HOST)));
|
||||
logException(() -> settings.setDbName(DEFAULT_DBNAME));
|
||||
logException(() -> settings.setUserName(valOrDefault(muConn.getUserName(), DEFAULT_USERNAME)));
|
||||
|
||||
handleTry(() -> settings.setPort(valOrDefault(muConn.getPort(), DEFAULT_PORT, 1, 65535)));
|
||||
handleTry(() -> settings.setBulkThreshold(RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD));
|
||||
logException(() -> settings.setPort(valOrDefault(muConn.getPort(), DEFAULT_PORT, 1, 65535)));
|
||||
logException(() -> settings.setBulkThreshold(RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD));
|
||||
|
||||
handleTry(() -> settings.setPassword(valOrDefault(muConn.getPassword(), DEFAULT_PASSWORD)));
|
||||
logException(() -> settings.setPassword(valOrDefault(muConn.getPassword(), DEFAULT_PASSWORD)));
|
||||
|
||||
return settings;
|
||||
}
|
||||
@ -127,12 +127,12 @@ public class CentralRepoPostgresSettingsUtil {
|
||||
Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY);
|
||||
|
||||
|
||||
handleTry(() -> settings.setHost(valOrDefault(keyVals.get(HOST_KEY), DEFAULT_HOST)));
|
||||
handleTry(() -> settings.setDbName(valOrDefault(keyVals.get(DBNAME_KEY), DEFAULT_DBNAME)));
|
||||
handleTry(() -> settings.setUserName(valOrDefault(keyVals.get(USER_KEY), DEFAULT_USERNAME)));
|
||||
logException(() -> settings.setHost(valOrDefault(keyVals.get(HOST_KEY), DEFAULT_HOST)));
|
||||
logException(() -> settings.setDbName(valOrDefault(keyVals.get(DBNAME_KEY), DEFAULT_DBNAME)));
|
||||
logException(() -> settings.setUserName(valOrDefault(keyVals.get(USER_KEY), DEFAULT_USERNAME)));
|
||||
|
||||
handleTry(() -> settings.setPort(valOrDefault(keyVals.get(PORT_KEY), DEFAULT_PORT, 1, 65535)));
|
||||
handleTry(() -> settings.setBulkThreshold(valOrDefault(keyVals.get(BULK_THRESHOLD_KEY), RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD, 1, null)));
|
||||
logException(() -> settings.setPort(valOrDefault(keyVals.get(PORT_KEY), DEFAULT_PORT, 1, 65535)));
|
||||
logException(() -> settings.setBulkThreshold(valOrDefault(keyVals.get(BULK_THRESHOLD_KEY), RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD, 1, null)));
|
||||
|
||||
String passwordHex = keyVals.get(PASSWORD_KEY);
|
||||
String password;
|
||||
@ -145,7 +145,7 @@ public class CentralRepoPostgresSettingsUtil {
|
||||
|
||||
final String finalPassword = password;
|
||||
|
||||
handleTry(() -> settings.setPassword(finalPassword));
|
||||
logException(() -> settings.setPassword(finalPassword));
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,6 @@ public enum DatabaseTestResult {
|
||||
CONNECTION_FAILED,
|
||||
SCHEMA_INVALID,
|
||||
DB_DOES_NOT_EXIST,
|
||||
TESTEDOK;
|
||||
TESTED_OK;
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,9 @@ public final class PostgresCentralRepoSettings implements CentralRepoDbConnectiv
|
||||
private static PostgresSettingsLoader getLoaderFromSaved() throws CentralRepoException {
|
||||
CentralRepoDbChoice choice = CentralRepoDbManager.getSavedDbChoice();
|
||||
if (choice == CentralRepoDbChoice.POSTGRESQL_CUSTOM)
|
||||
return PostgresSettingsLoader.CUSTOM_LOADER;
|
||||
return PostgresSettingsLoader.CUSTOM_SETTINGS_LOADER;
|
||||
else if (choice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER)
|
||||
return PostgresSettingsLoader.MULTIUSER_LOADER;
|
||||
return PostgresSettingsLoader.MULTIUSER_SETTINGS_LOADER;
|
||||
else
|
||||
throw new CentralRepoException("cannot load or save postgres settings for selection: " + choice);
|
||||
}
|
||||
@ -362,7 +362,7 @@ public final class PostgresCentralRepoSettings implements CentralRepoDbConnectiv
|
||||
if (verifyConnection()) {
|
||||
if (verifyDatabaseExists()) {
|
||||
if (verifyDatabaseSchema()) {
|
||||
return DatabaseTestResult.TESTEDOK;
|
||||
return DatabaseTestResult.TESTED_OK;
|
||||
} else {
|
||||
return DatabaseTestResult.SCHEMA_INVALID;
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ public interface PostgresSettingsLoader {
|
||||
PostgresConnectionSettings loadSettings();
|
||||
void saveSettings(PostgresConnectionSettings settings);
|
||||
|
||||
PostgresSettingsLoader CUSTOM_LOADER = new Custom();
|
||||
PostgresSettingsLoader MULTIUSER_LOADER = new MultiUser();
|
||||
PostgresSettingsLoader CUSTOM_SETTINGS_LOADER = new Custom();
|
||||
PostgresSettingsLoader MULTIUSER_SETTINGS_LOADER = new MultiUser();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -358,7 +358,7 @@ public final class SqliteCentralRepoSettings implements CentralRepoDbConnectivit
|
||||
if (dbFileExists()) {
|
||||
if (verifyConnection()) {
|
||||
if (verifyDatabaseSchema()) {
|
||||
return DatabaseTestResult.TESTEDOK;
|
||||
return DatabaseTestResult.TESTED_OK;
|
||||
} else {
|
||||
return DatabaseTestResult.SCHEMA_INVALID;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public class EamDbSettingsDialog extends JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
return (manager.getStatus() == DatabaseTestResult.TESTEDOK);
|
||||
return (manager.getStatus() == DatabaseTestResult.TESTED_OK);
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,7 +75,6 @@ public final class UserPreferences {
|
||||
public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
|
||||
public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
|
||||
public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
|
||||
private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
|
||||
public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
|
||||
public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
|
||||
public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
|
||||
@ -266,7 +265,7 @@ public final class UserPreferences {
|
||||
}
|
||||
|
||||
public static boolean displayTranslatedFileNames() {
|
||||
return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT);
|
||||
return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user