From b61a6114fcbb0d1c8941d86f1880a9ddd6fc4f26 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 19 Mar 2020 14:15:47 -0400 Subject: [PATCH 1/4] 6108 central repo schema updates in app service --- .../datamodel/Bundle.properties-MERGED | 8 +- .../datamodel/CentralRepositoryService.java | 119 ++++++++++++++++++ .../datamodel/DataSourceUpdateService.java | 68 ---------- .../eventlisteners/Installer.java | 31 +---- 4 files changed, 128 insertions(+), 98 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java delete mode 100644 Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/Bundle.properties-MERGED index 345d5a420e..44f4462515 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/Bundle.properties-MERGED @@ -7,7 +7,14 @@ AbstractSqlEamDb.cannotUpgrage.message=Currently selected database platform "{0} AbstractSqlEamDb.failedToReadMajorVersion.message=Failed to read schema version for Central Repository. AbstractSqlEamDb.failedToReadMinorVersion.message=Failed to read schema minor version for Central Repository. AbstractSqlEamDb.upgradeSchema.incompatible=The selected Central Repository is not compatible with the current version of the application, please upgrade the application if you wish to use this Central Repository. +CentralRepoDbChoice.Disabled.Text=Disabled +CentralRepoDbChoice.PostgreSQL.Text=Custom PostgreSQL +CentralRepoDbChoice.PostgreSQL_Multiuser.Text=PostgreSQL using multi-user settings +CentralRepoDbChoice.Sqlite.Text=SQLite CentralRepoDbManager.connectionErrorMsg.text=Failed to connect to central repository database. +CentralRepositoryService.progressMsg.updatingDataSourcesTable=Checking for v1.2 data updates... +CentralRepositoryService.progressMsg.updatingSchema=Updating schema... +CentralRepositoryService.serviceName=Central Repository Service CorrelationAttributeInstance.invalidName.message=Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'. CorrelationAttributeInstance.nullName.message=Database name is null. CorrelationAttributeUtil.emailaddresses.text=Email Addresses @@ -21,7 +28,6 @@ CorrelationType.MAC.displayName=MAC Addresses CorrelationType.PHONE.displayName=Phone Numbers CorrelationType.SSID.displayName=Wireless Networks CorrelationType.USBID.displayName=USB Devices -DataSourceUpdateService.serviceName.text=Update Central Repository Data Sources EamArtifactInstances.knownStatus.bad=Bad EamArtifactInstances.knownStatus.known=Known EamArtifactInstances.knownStatus.unknown=Unknown diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java new file mode 100644 index 0000000000..6413a377f6 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java @@ -0,0 +1,119 @@ +/* + * Central Repository + * + * Copyright 2018-2020 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.centralrepository.datamodel; + +import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; +import org.sleuthkit.autopsy.appservices.AutopsyService; +import org.sleuthkit.autopsy.progress.ProgressIndicator; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.DataSource; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * The Autopsy application service for the central repository. + */ +@ServiceProvider(service = AutopsyService.class) +public class CentralRepositoryService implements AutopsyService { + + @Override + @NbBundle.Messages({ + "CentralRepositoryService.serviceName=Central Repository Service" + }) + public String getServiceName() { + return Bundle.CentralRepositoryService_serviceName(); + } + + @NbBundle.Messages({ + "CentralRepositoryService.progressMsg.updatingSchema=Updating schema...", + "CentralRepositoryService.progressMsg.updatingDataSourcesTable=Checking for v1.2 data updates...",}) + @Override + public void openCaseResources(CaseContext context) throws AutopsyServiceException { + if (!CentralRepository.isEnabled()) { + return; + } + + /* + * TODO (Jira-6108): We should consider adding coordination service + * locking to the central repository in collaborative environments. + */ + ProgressIndicator progress = context.getProgressIndicator(); + progress.progress(Bundle.CentralRepositoryService_progressMsg_updatingSchema()); + updateSchema(); + + if (context.cancelRequested()) { + return; + } + + progress.progress(Bundle.CentralRepositoryService_progressMsg_updatingDataSourcesTable()); + dataUpgradeForVersion1dot2(context.getCase()); + } + + /** + * Updates the central repository schema to the latest version. + * + * @throws AutopsyServiceException + */ + private void updateSchema() throws AutopsyServiceException { + try { + CentralRepoDbManager.upgradeDatabase(); + } catch (CentralRepoException ex) { + throw new AutopsyServiceException("Failed to update the Central Repository schema", ex); + } + } + + /** + * Adds missing data source object IDs from data sources in this case to the + * corresponding records in the central repository. This is a data update to + * go with the v1.2 schema update. + * + * @throws AutopsyServiceException + */ + private void dataUpgradeForVersion1dot2(Case currentCase) throws AutopsyServiceException { + try { + /* + * If the case is in the central repository, there may be missing + * data source object IDs in the data_sources.datasource_obj_id + * column that was added in the version 1.2 schema update. + */ + CentralRepository centralRepository = CentralRepository.getInstance(); + CorrelationCase correlationCase = centralRepository.getCase(currentCase); + if (correlationCase != null) { + for (CorrelationDataSource correlationDataSource : centralRepository.getDataSources()) { + /* + * ResultSet.getLong returns zero when the value in the + * result set is NULL. + */ + if (correlationDataSource.getCaseID() == correlationCase.getID() && correlationDataSource.getDataSourceObjectID() == 0) { + for (Content dataSource : currentCase.getDataSources()) { + if (((DataSource) dataSource).getDeviceId().equals(correlationDataSource.getDeviceID()) && dataSource.getName().equals(correlationDataSource.getName())) { + centralRepository.addDataSourceObjectId(correlationDataSource.getID(), dataSource.getId()); + break; + } + } + } + } + } + } catch (CentralRepoException | TskCoreException ex) { + throw new AutopsyServiceException("Failed to update data sources in the Central Repository for schema v1.2", ex); + } + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java deleted file mode 100644 index 2450ca3440..0000000000 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Central Repository - * - * Copyright 2018 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.centralrepository.datamodel; - -import org.openide.util.NbBundle; -import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.appservices.AutopsyService; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.DataSource; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Class which updates the data sources in the central repository to include the - * object id which ties them to the current case. - * - */ -@ServiceProvider(service = AutopsyService.class) -public class DataSourceUpdateService implements AutopsyService { - - @Override - @NbBundle.Messages({"DataSourceUpdateService.serviceName.text=Update Central Repository Data Sources"}) - public String getServiceName() { - return Bundle.DataSourceUpdateService_serviceName_text(); - } - - @Override - public void openCaseResources(CaseContext context) throws AutopsyServiceException { - if (CentralRepository.isEnabled()) { - try { - CentralRepository centralRepository = CentralRepository.getInstance(); - CorrelationCase correlationCase = centralRepository.getCase(context.getCase()); - //if the case isn't in the central repository yet there won't be data sources in it to update - if (correlationCase != null) { - for (CorrelationDataSource correlationDataSource : centralRepository.getDataSources()) { - //ResultSet.getLong has a value of 0 when the value is null - if (correlationDataSource.getCaseID() == correlationCase.getID() && correlationDataSource.getDataSourceObjectID() == 0) { - for (Content dataSource : context.getCase().getDataSources()) { - if (((DataSource) dataSource).getDeviceId().equals(correlationDataSource.getDeviceID()) && dataSource.getName().equals(correlationDataSource.getName())) { - centralRepository.addDataSourceObjectId(correlationDataSource.getID(), dataSource.getId()); - break; - } - } - } - } - } - } catch (CentralRepoException | TskCoreException ex) { - throw new AutopsyServiceException("Unabe to update datasources in central repository", ex); - } - } - } - -} \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index 9f888e43f2..da58e8936b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -39,16 +39,6 @@ import org.sleuthkit.autopsy.coreutils.Version; * central repository, sets up a default, single-user SQLite central repository * if no central repository is configured, and updates the central repository * schema as required. - * - * TODO (Jira-6108): At first glance, this package seems to have become a rather - * strange package for the "package installer" for the CR to reside in. The - * org.sleuthkit.autopsy.centralrepository package would seem to be more - * appropriate with so much going on. However, having a central repository - * schema update occur in a "package installer" with no user feedback is not - * optimal. Furthermore, for a multi-user (collaborative) installation, a schema - * update should be done in a more controlled way by acquiring an exclusive - * coordination service lock and requiring shared locks to be acquired by nodes - * with open cases. */ public class Installer extends ModuleInstall { @@ -84,9 +74,8 @@ public class Installer extends ModuleInstall { /* * Adds/removes application event listeners responsible for adding data to - * the central repository, sets up a default, single-user SQLite central - * repository if no central repository is configured, and updates the - * central repository schema as required. + * the central repository and sets up a default, single-user SQLite central + * repository if no central repository is configured. * * Called by the registered Installer for the Autopsy-Core module located in * the org.sleuthkit.autopsy.core package when the already installed @@ -105,8 +94,6 @@ public class Installer extends ModuleInstall { if (Version.getBuildType() == Version.Type.RELEASE) { setupDefaultCentralRepository(); } - - updateCentralRepoSchema(); } /** @@ -198,20 +185,6 @@ public class Installer extends ModuleInstall { manager.setupDefaultSqliteDb(); } - /** - * Update the central repository schema. - */ - private void updateCentralRepoSchema() { - try { - CentralRepoDbManager.upgradeDatabase(); - } catch (CentralRepoException ex) { - logger.log(Level.SEVERE, "An error occurred updating the central repository schema", ex); - if (RuntimeProperties.runningWithGUI()) { - doMessageBoxIfRunningInGUI(ex); - } - } - } - /** * Display a central repository exception in a message box if running with a * GUI. From 1b77e34e705e539b65542cb67030b329b475e48a Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 19 Mar 2020 14:55:38 -0400 Subject: [PATCH 2/4] 6108 central repo schema updates in app service --- .../optionspanel/Bundle.properties-MERGED | 1 - .../optionspanel/GlobalSettingsPanel.java | 41 +------------------ 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties-MERGED index 9ea90a452a..395330b4db 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties-MERGED @@ -39,7 +39,6 @@ GlobalSettingsPanel.onMultiUserChange.disabledMu.title=Central Repository Change GlobalSettingsPanel.onMultiUserChange.enable.description=Do you want to update the Central Repository to use this PostgreSQL database? GlobalSettingsPanel.onMultiUserChange.enable.description2=The Central Repository stores hash values and accounts from past cases. GlobalSettingsPanel.onMultiUserChange.enable.title=Use with Central Repository? -GlobalSettingsPanel.updateFailed.title=Central repository disabled GlobalSettingsPanel.validationErrMsg.ingestRunning=You cannot change settings while ingest is running. GlobalSettingsPanel.validationerrMsg.mustConfigure=Configure the database to enable this module. ManageCasesDialog.title.text=Manage Cases diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 78b2e9ca87..4f37b7905a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -74,8 +74,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i ingestStateUpdated(evt.getNewValue() != null); }); } - - + private void customizeComponents() { setName(NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.pnCorrelationProperties.border.title")); } @@ -84,10 +83,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i IngestManager.getInstance().addIngestJobEventListener(INGEST_JOB_EVENTS_OF_INTEREST, ingestJobEventListener); ingestStateUpdated(Case.isCaseOpen()); } - - private void updateDatabase() { - updateDatabase(this); - } /** * This method invokes central repository database choice selection as well as input for necessary configuration. @@ -102,7 +97,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i new EamDbSettingsDialog(); if (dialog.wasConfigurationChanged()) { - updateDatabase(parent); return true; } @@ -208,43 +202,12 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i } } - private static void handleDbChange(Component parent) { SwingUtilities.invokeLater(() -> { boolean successful = EamDbSettingsDialog.testStatusAndCreate(parent, new CentralRepoDbManager()); - if (successful) { - updateDatabase(parent); - } - else { - // disable central repository due to error - CentralRepoDbManager.disableDueToFailure(); - } }); } - - @Messages({"GlobalSettingsPanel.updateFailed.title=Central repository disabled"}) - private static void updateDatabase(Component parent) { - if (CentralRepoDbChoice.DISABLED.equals(CentralRepoDbManager.getSavedDbChoice())) { - return; - } - parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - try { - CentralRepoDbManager.upgradeDatabase(); - parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } catch (CentralRepoException ex) { - parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - JOptionPane.showMessageDialog(parent, - ex.getUserMessage(), - NbBundle.getMessage(GlobalSettingsPanel.class, - "GlobalSettingsPanel.updateFailed.title"), - JOptionPane.WARNING_MESSAGE); - } finally { - parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -598,8 +561,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.DISABLED); } - - updateDatabase(); load(); this.ingestStateUpdated(Case.isCaseOpen()); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); From f4cdb6e8e5fb51c22de3996d14c08eec05227c43 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 19 Mar 2020 14:57:29 -0400 Subject: [PATCH 3/4] 6108 central repo schema updates in app service --- .../centralrepository/datamodel/CentralRepositoryService.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java index 6413a377f6..8b442efc24 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepositoryService.java @@ -50,10 +50,6 @@ public class CentralRepositoryService implements AutopsyService { return; } - /* - * TODO (Jira-6108): We should consider adding coordination service - * locking to the central repository in collaborative environments. - */ ProgressIndicator progress = context.getProgressIndicator(); progress.progress(Bundle.CentralRepositoryService_progressMsg_updatingSchema()); updateSchema(); From eef8736fadfe02c1a833f883a6577cc55ff87180 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 19 Mar 2020 15:02:33 -0400 Subject: [PATCH 4/4] 6108 central repo schema updates in app service --- .../optionspanel/GlobalSettingsPanel.java | 161 +++++++++--------- 1 file changed, 80 insertions(+), 81 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 4f37b7905a..c3ffa0be00 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -50,20 +50,18 @@ import java.util.logging.Level; */ @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel implements OptionsPanel { - + private static final long serialVersionUID = 1L; private static final Logger logger = Logger.getLogger(GlobalSettingsPanel.class.getName()); private static final Set INGEST_JOB_EVENTS_OF_INTEREST = EnumSet.of(IngestManager.IngestJobEvent.STARTED, IngestManager.IngestJobEvent.CANCELLED, IngestManager.IngestJobEvent.COMPLETED); private final IngestJobEventPropertyChangeListener ingestJobEventListener; - - - + /** * Creates new form EamOptionsPanel */ public GlobalSettingsPanel() { ingestJobEventListener = new IngestJobEventPropertyChangeListener(); - + // listen for change events in currently saved choice CentralRepoDbManager.addPropertyChangeListener((PropertyChangeEvent evt) -> ingestStateUpdated(Case.isCaseOpen())); initComponents(); @@ -74,7 +72,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i ingestStateUpdated(evt.getNewValue() != null); }); } - + private void customizeComponents() { setName(NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.pnCorrelationProperties.border.title")); } @@ -83,35 +81,37 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i IngestManager.getInstance().addIngestJobEventListener(INGEST_JOB_EVENTS_OF_INTEREST, ingestJobEventListener); ingestStateUpdated(Case.isCaseOpen()); } - + /** - * This method invokes central repository database choice selection as well as input for necessary configuration. - * @param parent The parent component for displaying dialogs. - * @param initialSelection If non-null, the menu item will be set to this choice; if null, - * the currently selected db choice will be selected. - * @return True if there was a change. + * This method invokes central repository database choice selection as well + * as input for necessary configuration. + * + * @param parent The parent component for displaying dialogs. + * @param initialSelection If non-null, the menu item will be set to this + * choice; if null, the currently selected db choice + * will be selected. + * + * @return True if there was a change. */ private static boolean invokeCrChoice(Component parent, CentralRepoDbChoice initialSelection) { - EamDbSettingsDialog dialog = (initialSelection != null) ? - new EamDbSettingsDialog(initialSelection) : - new EamDbSettingsDialog(); - - if (dialog.wasConfigurationChanged()) { - return true; - } - - return false; + EamDbSettingsDialog dialog = (initialSelection != null) + ? new EamDbSettingsDialog(initialSelection) + : new EamDbSettingsDialog(); + return dialog.wasConfigurationChanged(); } - - + /** - * When multi user settings are updated, this function triggers pertinent updates for central repository. - * NOTE: If multi user settings were previously enabled and multi user settings are currently selected, this function assumes - * there is a change in the postgres connectivity. - * - * @param parent The swing component that serves as a parent for dialogs that may arise. - * @param muPreviouslySelected If multi user settings were previously enabled. - * @param muCurrentlySelected If multi user settings are currently enabled as of most recent change. + * When multi user settings are updated, this function triggers pertinent + * updates for central repository. NOTE: If multi user settings were + * previously enabled and multi user settings are currently selected, this + * function assumes there is a change in the postgres connectivity. + * + * @param parent The swing component that serves as a parent + * for dialogs that may arise. + * @param muPreviouslySelected If multi user settings were previously + * enabled. + * @param muCurrentlySelected If multi user settings are currently enabled + * as of most recent change. */ @NbBundle.Messages({ "GlobalSettingsPanel.onMultiUserChange.enable.title=Use with Central Repository?", @@ -122,33 +122,31 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i boolean crEnabled = CentralRepoDbUtil.allowUseOfCentralRepository(); boolean crMultiUser = CentralRepoDbManager.getSavedDbChoice() == CentralRepoDbChoice.POSTGRESQL_MULTIUSER; boolean crDisabledDueToFailure = CentralRepoDbManager.isDisabledDueToFailure(); - + if (!muPreviouslySelected && muCurrentlySelected) { SwingUtilities.invokeLater(() -> { - if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(parent, - "" + - "
" + - "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.enable.description") + "

" + - "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.enable.description2") + "

" + - "
" + - "", - NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.enable.title"), - JOptionPane.YES_NO_OPTION)) { - - // setup database for CR - CentralRepoDbUtil.setUseCentralRepo(true); - CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.POSTGRESQL_MULTIUSER); - handleDbChange(parent); - } + if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(parent, + "" + + "
" + + "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.enable.description") + "

" + + "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.enable.description2") + "

" + + "
" + + "", + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.enable.title"), + JOptionPane.YES_NO_OPTION)) { + + // setup database for CR + CentralRepoDbUtil.setUseCentralRepo(true); + CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.POSTGRESQL_MULTIUSER); + handleDbChange(parent); + } }); - } - // moving from selected to not selected && 'PostgreSQL using multi-user settings' is selected + } // moving from selected to not selected && 'PostgreSQL using multi-user settings' is selected else if (muPreviouslySelected && !muCurrentlySelected && crEnabled && crMultiUser) { SwingUtilities.invokeLater(() -> { askForCentralRepoDbChoice(parent); }); - } - // changing multi-user settings connection && 'PostgreSQL using multi-user settings' is selected && + } // changing multi-user settings connection && 'PostgreSQL using multi-user settings' is selected && // central repo either enabled or was disabled due to error else if (muPreviouslySelected && muCurrentlySelected && crMultiUser && (crEnabled || crDisabledDueToFailure)) { // test databse for CR change @@ -157,10 +155,12 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i } } - /** - * This method is called when a user must select a new database other than using database from multi user settings. - * @param parent The parent component to use for displaying dialogs in reference. + * This method is called when a user must select a new database other than + * using database from multi user settings. + * + * @param parent The parent component to use for displaying dialogs in + * reference. */ @NbBundle.Messages({ "GlobalSettingsPanel.onMultiUserChange.disabledMu.title=Central Repository Change Necessary", @@ -171,21 +171,21 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i // disable central repository until user makes choice CentralRepoDbUtil.setUseCentralRepo(false); CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.DISABLED, false); - + Object[] options = { "Use SQLite", "Configure PostgreSQL", "Disable Central Repository" }; - + int result = JOptionPane.showOptionDialog( parent, - "" + - "
" + - "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.disabledMu.description") + "

" + - "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.disabledMu.description2") + "

" + - "
" + - "", + "" + + "
" + + "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.disabledMu.description") + "

" + + "

" + NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.disabledMu.description2") + "

" + + "
" + + "", NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.onMultiUserChange.disabledMu.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, @@ -193,21 +193,22 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i options, options[0] ); - + if (JOptionPane.YES_OPTION == result) { invokeCrChoice(parent, CentralRepoDbChoice.SQLITE); - } - else if (JOptionPane.NO_OPTION == result) { + } else if (JOptionPane.NO_OPTION == result) { invokeCrChoice(parent, CentralRepoDbChoice.POSTGRESQL_CUSTOM); } } - + private static void handleDbChange(Component parent) { SwingUtilities.invokeLater(() -> { - boolean successful = EamDbSettingsDialog.testStatusAndCreate(parent, new CentralRepoDbManager()); + if (!EamDbSettingsDialog.testStatusAndCreate(parent, new CentralRepoDbManager())) { + CentralRepoDbManager.disableDueToFailure(); + } }); } - + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -552,15 +553,15 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i private void cbUseCentralRepoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbUseCentralRepoActionPerformed //if saved setting is disabled checkbox should be disabled already store(); - + // if moving to using CR, multi-user mode is disabled and selection is multiuser settings, set to disabled - if (cbUseCentralRepo.isSelected() && - !CentralRepoDbManager.isPostgresMultiuserAllowed() && - CentralRepoDbManager.getSavedDbChoice() == CentralRepoDbChoice.POSTGRESQL_MULTIUSER) { - + if (cbUseCentralRepo.isSelected() + && !CentralRepoDbManager.isPostgresMultiuserAllowed() + && CentralRepoDbManager.getSavedDbChoice() == CentralRepoDbChoice.POSTGRESQL_MULTIUSER) { + CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.DISABLED); } - + load(); this.ingestStateUpdated(Case.isCaseOpen()); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); @@ -581,20 +582,17 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i lbDbNameValue.setText(""); lbDbLocationValue.setText(""); tbOops.setText(Bundle.GlobalSettingsPanel_validationerrMsg_mustConfigure()); - } - else { + } else { enableButtonSubComponents(cbUseCentralRepo.isSelected()); if (selectedDb == CentralRepoPlatforms.POSTGRESQL) { try { - PostgresCentralRepoSettings dbSettingsPg = new PostgresCentralRepoSettings(); + PostgresCentralRepoSettings dbSettingsPg = new PostgresCentralRepoSettings(); lbDbNameValue.setText(dbSettingsPg.getDbName()); lbDbLocationValue.setText(dbSettingsPg.getHost()); - } - catch (CentralRepoException e) { + } catch (CentralRepoException e) { logger.log(Level.WARNING, "Unable to load settings into global panel for postgres settings", e); } - } - else if (selectedDb == CentralRepoPlatforms.SQLITE) { + } else if (selectedDb == CentralRepoPlatforms.SQLITE) { SqliteCentralRepoSettings dbSettingsSqlite = new SqliteCentralRepoSettings(); lbDbNameValue.setText(dbSettingsSqlite.getDbName()); lbDbLocationValue.setText(dbSettingsSqlite.getDbDirectory()); @@ -608,7 +606,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i } /** - * This method validates that the dialog/panel is filled out correctly for our usage. + * This method validates that the dialog/panel is filled out correctly for + * our usage. * * @return True if it is okay, false otherwise. */