diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 76b9d54381..3f66069e98 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -3171,7 +3171,7 @@ abstract class AbstractSqlEamDb implements EamDb { * @throws EamDbException */ @Override - public void upgradeSchema() throws EamDbException, SQLException { + public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException { ResultSet resultSet = null; Statement statement = null; @@ -3225,7 +3225,7 @@ abstract class AbstractSqlEamDb implements EamDb { //we can not use the CaseDbSchemaVersionNumber.isCompatible method //because it is specific to case db schema versions only supporting major versions greater than 1 if (SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() < dbSchemaVersion.getMajor()) { - throw new EamDbException("The selected Central Repository is not compatable with the current version of the application, please upgrade the application if you wish to use this Central Repository"); + throw new IncompatibleCentralRepoException("The selected Central Repository is not compatable with the current version of the application, please upgrade the application if you wish to use this Central Repository"); } if (dbSchemaVersion.equals(SOFTWARE_CR_DB_SCHEMA_VERSION)) { logger.log(Level.INFO, "Central Repository is up to date"); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 7a54ee656c..c633dc5adc 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -710,7 +710,7 @@ public interface EamDb { * * @throws EamDbException */ - public void upgradeSchema() throws EamDbException, SQLException; + public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException; /** * Gets an exclusive lock (if applicable). Will return the lock if diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java index d1edcc15c3..300b44a015 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java @@ -25,6 +25,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.List; import java.util.logging.Level; +import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.coordinationservice.CoordinationService; import org.sleuthkit.autopsy.coordinationservice.CoordinationService.CoordinationServiceException; import org.sleuthkit.autopsy.coreutils.Logger; @@ -172,9 +173,10 @@ public class EamDbUtil { * * @return true if the upgrade succeeds, false otherwise. */ - public static boolean upgradeDatabase() { + @Messages({"EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade central repository. It has been disabled."}) + public static void upgradeDatabase() throws EamDbException { if (!EamDb.isEnabled()) { - return true; + return; } CoordinationService.Lock lock = null; @@ -188,7 +190,7 @@ public class EamDbUtil { db.upgradeSchema(); - } catch (EamDbException | SQLException ex) { + } catch (EamDbException | SQLException | IncompatibleCentralRepoException ex) { LOGGER.log(Level.SEVERE, "Error updating central repository", ex); // Disable the central repo and clear the current settings. @@ -196,15 +198,18 @@ public class EamDbUtil { if (null != EamDb.getInstance()) { EamDb.getInstance().shutdownConnections(); } - } catch (EamDbException ex2) { + } catch (EamDbException ignored) { LOGGER.log(Level.SEVERE, "Error shutting down central repo connection pool", ex); } setUseCentralRepo(false); EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.DISABLED.name()); EamDbPlatformEnum.saveSelectedPlatform(); - - return false; + String messageForDialog = Bundle.EamDbUtil_centralRepoUpgradeFailed_message(); + if (ex instanceof IncompatibleCentralRepoException) { + messageForDialog = ex.getMessage() + "\n\n" + messageForDialog; + } + throw new EamDbException(messageForDialog); } finally { if (lock != null) { try { @@ -214,7 +219,6 @@ public class EamDbUtil { } } } - return true; } /** diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/IncompatibleCentralRepoException.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/IncompatibleCentralRepoException.java new file mode 100644 index 0000000000..3d96189ea8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/IncompatibleCentralRepoException.java @@ -0,0 +1,53 @@ +/* + * + * Autopsy Forensic Browser + * + * 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; + +/** + * Exception to denote that the Central Repo is not compatable with the current version of the software. + */ +public class IncompatibleCentralRepoException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * Construct an exception with the given message. + * @param message error message + */ + public IncompatibleCentralRepoException(String message){ + super(message); + } + + /** + * Construct an exception with the given message and inner exception. + * @param message error message + * @param cause inner exception + */ + public IncompatibleCentralRepoException(String message, Throwable cause){ + super(message, cause); + } + + /** + * Construct an exception with the given inner exception. + * @param cause inner exception + */ + public IncompatibleCentralRepoException(Throwable cause){ + super(cause); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index 36484d2f2d..69826a3355 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -1118,7 +1118,7 @@ final class SqliteEamDb extends AbstractSqlEamDb { * @throws EamDbException */ @Override - public void upgradeSchema() throws EamDbException, SQLException { + public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException { try { acquireExclusiveLock(); super.upgradeSchema(); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index 7ca97535d9..b887dea359 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -23,6 +23,7 @@ import org.openide.modules.ModuleInstall; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; @@ -50,21 +51,20 @@ public class Installer extends ModuleInstall { super(); } - @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository upgrade failed", - "Installer.centralRepoUpgradeFailed.message=Failed to upgrade central repository. It has been disabled." - }) + @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository upgrade failed"}) @Override public void restored() { Case.addPropertyChangeListener(pcl); ieListener.installListeners(); // Perform the database upgrade and inform the user if it fails - if (!EamDbUtil.upgradeDatabase()) { + try { + EamDbUtil.upgradeDatabase(); + } catch (EamDbException ex) { if (RuntimeProperties.runningWithGUI()) { WindowManager.getDefault().invokeWhenUIReady(() -> { JOptionPane.showMessageDialog(null, - NbBundle.getMessage(this.getClass(), - "Installer.centralRepoUpgradeFailed.message"), + ex.getMessage(), NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"), JOptionPane.ERROR_MESSAGE); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 7c24da62c4..dec84dfb51 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -30,6 +30,7 @@ import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; @@ -75,9 +76,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i ingestStateUpdated(Case.isCaseOpen()); } - @Messages({"GlobalSettingsPanel.updateFailed.title=Update failed", - "GlobalSettingsPanel.updateFailed.message=Failed to update database. Central repository has been disabled." - }) + @Messages({"GlobalSettingsPanel.updateFailed.title=Central repository upgrade failed"}) private void updateDatabase() { if (EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)) { @@ -86,16 +85,15 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { - boolean result = EamDbUtil.upgradeDatabase(); + EamDbUtil.upgradeDatabase(); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - if (!result) { - JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "GlobalSettingsPanel.updateFailed.message"), - NbBundle.getMessage(this.getClass(), - "GlobalSettingsPanel.updateFailed.title"), - JOptionPane.WARNING_MESSAGE); - } + } catch (EamDbException ex) { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + JOptionPane.showMessageDialog(this, + ex.getMessage(), + NbBundle.getMessage(this.getClass(), + "GlobalSettingsPanel.updateFailed.title"), + JOptionPane.WARNING_MESSAGE); } finally { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }