diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/CentralRepoContextMenuActionsProvider.java b/Core/src/org/sleuthkit/autopsy/centralrepository/CentralRepoContextMenuActionsProvider.java index 65a980558c..bfeae53ca6 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/CentralRepoContextMenuActionsProvider.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/CentralRepoContextMenuActionsProvider.java @@ -25,7 +25,7 @@ import javax.swing.Action; import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.centralrepository.datamodel.EamArtifactUtil; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider; import org.sleuthkit.datamodel.AbstractFile; @@ -46,7 +46,7 @@ public class CentralRepoContextMenuActionsProvider implements ContextMenuActions } for (AbstractFile file : selectedFiles) { - if (EamDbUtil.useCentralRepo() && EamArtifactUtil.isSupportedAbstractFileType(file) && file.isFile()) { + if (EamDb.isEnabled() && EamArtifactUtil.isSupportedAbstractFileType(file) && file.isFile()) { AddEditCentralRepoCommentAction action = new AddEditCentralRepoCommentAction(file); if (action.getCorrelationAttribute() == null) { action.setEnabled(false); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java index 191d1c3bc6..6082dce81b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java @@ -71,7 +71,6 @@ import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskData; @@ -891,7 +890,7 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi private void rightClickPopupMenuPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_rightClickPopupMenuPopupMenuWillBecomeVisible boolean enableCentralRepoActions = false; - if (EamDbUtil.useCentralRepo() && otherCasesTable.getSelectedRowCount() == 1) { + if (EamDb.isEnabled() && otherCasesTable.getSelectedRowCount() == 1) { int rowIndex = otherCasesTable.getSelectedRow(); OtherOccurrenceNodeData selectedNode = (OtherOccurrenceNodeData) tableModel.getRow(rowIndex); if (selectedNode instanceof OtherOccurrenceNodeInstanceData) { diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 27c6407b5d..2f090edfc0 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -40,6 +40,7 @@ import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil.updateSchemaVersion; import org.sleuthkit.autopsy.coreutils.Logger; @@ -60,7 +61,7 @@ abstract class AbstractSqlEamDb implements EamDb { static final String SCHEMA_MINOR_VERSION_KEY = "SCHEMA_MINOR_VERSION"; static final String CREATION_SCHEMA_MAJOR_VERSION_KEY = "CREATION_SCHEMA_MAJOR_VERSION"; static final String CREATION_SCHEMA_MINOR_VERSION_KEY = "CREATION_SCHEMA_MINOR_VERSION"; - static final CaseDbSchemaVersionNumber CURRENT_DB_SCHEMA_VERSION = new CaseDbSchemaVersionNumber(1, 2); + static final CaseDbSchemaVersionNumber SOFTWARE_CR_DB_SCHEMA_VERSION = new CaseDbSchemaVersionNumber(1, 2); protected final List defaultCorrelationTypes; @@ -3170,8 +3171,9 @@ abstract class AbstractSqlEamDb implements EamDb { * * @throws EamDbException */ + @Messages({"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."}) @Override - public void upgradeSchema() throws EamDbException, SQLException { + public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException { ResultSet resultSet = null; Statement statement = null; @@ -3220,11 +3222,18 @@ abstract class AbstractSqlEamDb implements EamDb { * schema updates that may already have been done once. */ CaseDbSchemaVersionNumber dbSchemaVersion = new CaseDbSchemaVersionNumber(majorVersion, minorVersion); - if (dbSchemaVersion.equals(CURRENT_DB_SCHEMA_VERSION)) { + + //compare the major versions for compatability + //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 IncompatibleCentralRepoException(Bundle.AbstractSqlEamDb_upgradeSchema_incompatible()); + } + if (dbSchemaVersion.equals(SOFTWARE_CR_DB_SCHEMA_VERSION)) { logger.log(Level.INFO, "Central Repository is up to date"); return; } - if (dbSchemaVersion.compareTo(CURRENT_DB_SCHEMA_VERSION) > 0) { + if (dbSchemaVersion.compareTo(SOFTWARE_CR_DB_SCHEMA_VERSION) > 0) { logger.log(Level.INFO, "Central Repository is of newer version than software creates"); return; } @@ -3386,8 +3395,8 @@ abstract class AbstractSqlEamDb implements EamDb { * column having a UNIQUE constraint. The name column could now * be used as the primary key, but the essentially useless id * column is retained for the sake of backwards compatibility. - * Note that the creation schema version number is set to 0.0 - * to indicate that it is unknown. + * Note that the creation schema version number is set to 0.0 to + * indicate that it is unknown. */ String creationMajorVer; resultSet = statement.executeQuery("SELECT value FROM db_info WHERE name = '" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "'"); @@ -3417,7 +3426,7 @@ abstract class AbstractSqlEamDb implements EamDb { updateSchemaVersion(conn); conn.commit(); - logger.log(Level.INFO, String.format("Central Repository schema updated to version %s", CURRENT_DB_SCHEMA_VERSION)); + logger.log(Level.INFO, String.format("Central Repository schema updated to version %s", SOFTWARE_CR_DB_SCHEMA_VERSION)); } catch (SQLException | EamDbException ex) { try { @@ -3425,7 +3434,7 @@ abstract class AbstractSqlEamDb implements EamDb { conn.rollback(); } } catch (SQLException ex2) { - logger.log(Level.SEVERE, String.format("Central Repository rollback of failed schema update to %s failed", CURRENT_DB_SCHEMA_VERSION), ex2); + logger.log(Level.SEVERE, String.format("Central Repository rollback of failed schema update to %s failed", SOFTWARE_CR_DB_SCHEMA_VERSION), ex2); } throw ex; } finally { diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java index b1d48d07b2..5b38c8a39e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java @@ -98,7 +98,7 @@ public class CorrelationDataSource implements Serializable { } CorrelationDataSource correlationDataSource = null; - boolean useCR = EamDbUtil.useCentralRepo(); + boolean useCR = EamDb.isEnabled(); if (useCR) { correlationDataSource = EamDb.getInstance().getDataSource(correlationCase, dataSource.getId()); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java index 16cc5b58c7..46696bad94 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/DataSourceUpdateService.java @@ -51,7 +51,7 @@ public class DataSourceUpdateService implements AutopsyService { //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())) { + if (((DataSource) dataSource).getDeviceId().equals(correlationDataSource.getDeviceID()) && dataSource.getName().equals(correlationDataSource.getName())) { centralRepository.addDataSourceObjectId(correlationDataSource.getID(), dataSource.getId()); break; } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 0793a8f696..c633dc5adc 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -41,7 +41,7 @@ public interface EamDb { static EamDb getInstance() throws EamDbException { EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.DISABLED; - if (EamDbUtil.useCentralRepo()) { + if (EamDbUtil.allowUseOfCentralRepository()) { selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); } switch (selectedPlatform) { @@ -92,7 +92,7 @@ public interface EamDb { * @return Is the database enabled */ static boolean isEnabled() { - return EamDbUtil.useCentralRepo() + return EamDbUtil.allowUseOfCentralRepository() && EamDbPlatformEnum.getSelectedPlatform() != EamDbPlatformEnum.DISABLED; } @@ -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 6e629b52e2..d7e611ae3c 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java @@ -25,11 +25,12 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.List; import java.util.logging.Level; -import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.CURRENT_DB_SCHEMA_VERSION; +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; import org.sleuthkit.autopsy.coreutils.ModuleSettings; +import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.SOFTWARE_CR_DB_SCHEMA_VERSION; /** * @@ -134,8 +135,8 @@ public class EamDbUtil { */ static void updateSchemaVersion(Connection conn) throws SQLException { try (Statement statement = conn.createStatement()) { - statement.execute("UPDATE db_info SET value = '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "'"); - statement.execute("UPDATE db_info SET value = '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "'"); + statement.execute("UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "'"); + statement.execute("UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "'"); } } @@ -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. @@ -197,13 +199,17 @@ public class EamDbUtil { EamDb.getInstance().shutdownConnections(); } } catch (EamDbException ex2) { - LOGGER.log(Level.SEVERE, "Error shutting down central repo connection pool", ex); + LOGGER.log(Level.SEVERE, "Error shutting down central repo connection pool", ex2); } 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 { @@ -213,7 +219,6 @@ public class EamDbUtil { } } } - return true; } /** @@ -268,12 +273,16 @@ public class EamDbUtil { } /** - * If the Central Repos use has been enabled. + * If the option to use a central repository has been selected, does not + * indicate the central repository is configured for use simply that the + * checkbox allowing configuration is checked on the options panel. * * @return true if the Central Repo may be configured, false if it should * not be able to be */ - public static boolean useCentralRepo() { + public static boolean allowUseOfCentralRepository() { + //In almost all situations EamDb.isEnabled() should be used instead of this method + //as EamDb.isEnabled() will call this method as well as checking that the selected type of central repository is not DISABLED return Boolean.parseBoolean(ModuleSettings.getConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY)); } 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/PostgresEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java index 14a5719f52..9a431f8011 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java @@ -28,11 +28,11 @@ import java.util.List; import java.util.Properties; import java.util.logging.Level; import java.util.regex.Pattern; -import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.CURRENT_DB_SCHEMA_VERSION; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.TextConverter; import org.sleuthkit.autopsy.coreutils.TextConverterException; +import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.SOFTWARE_CR_DB_SCHEMA_VERSION; /** * Settings for the Postgres implementation of the Central Repository database @@ -437,10 +437,10 @@ public final class PostgresEamDbSettings { * name column could be the primary key. */ stmt.execute("CREATE TABLE db_info (id SERIAL, name TEXT UNIQUE NOT NULL, value TEXT NOT NULL)"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "')"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "')"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "')"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')"); // Create a separate instance and reference table for each correlation type List DEFAULT_CORRELATION_TYPES = CorrelationAttributeInstance.getDefaultCorrelationTypes(); 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/datamodel/SqliteEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java index 4851e51b51..4baa423a04 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java @@ -29,10 +29,10 @@ import java.sql.Statement; import java.util.List; import java.util.logging.Level; import java.util.regex.Pattern; -import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.CURRENT_DB_SCHEMA_VERSION; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; +import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.SOFTWARE_CR_DB_SCHEMA_VERSION; /** * Settings for the sqlite implementation of the Central Repository database @@ -386,10 +386,10 @@ public final class SqliteEamDbSettings { * name column could be the primary key. */ stmt.execute("CREATE TABLE db_info (id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL, value TEXT NOT NULL)"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "')"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "')"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "')"); - stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')"); + stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')"); // Create a separate instance and reference table for each artifact type List DEFAULT_CORRELATION_TYPES = CorrelationAttributeInstance.getDefaultCorrelationTypes(); 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/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 826e66ecbc..19b1c4c8e5 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -90,7 +90,7 @@ public class EamDbSettingsDialog extends JDialog { initComponents(); fcDatabasePath.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fcDatabasePath.setAcceptAllFileFilterUsed(false); - fcDatabasePath.setDialogTitle(Bundle.EamDbSettingsDialog_fcDatabasePath_title()); + fcDatabasePath.setDialogTitle(Bundle.EamDbSettingsDialog_fcDatabasePath_title()); fcDatabasePath.setFileFilter(new FileFilter() { @Override public boolean accept(File pathname) { @@ -369,7 +369,7 @@ public class EamDbSettingsDialog extends JDialog { case POSTGRESQL: if (dbSettingsPostgres.verifyConnection()) { if (dbSettingsPostgres.verifyDatabaseExists()) { - if( dbSettingsPostgres.verifyDatabaseSchema()) { + if (dbSettingsPostgres.verifyDatabaseSchema()) { testingStatus = DatabaseTestResult.TESTEDOK; } else { testingStatus = DatabaseTestResult.SCHEMA_INVALID; @@ -382,8 +382,8 @@ public class EamDbSettingsDialog extends JDialog { } break; case SQLITE: - if (dbSettingsSqlite.dbFileExists()){ - if(dbSettingsSqlite.verifyConnection()) { + if (dbSettingsSqlite.dbFileExists()) { + if (dbSettingsSqlite.verifyConnection()) { if (dbSettingsSqlite.verifyDatabaseSchema()) { testingStatus = DatabaseTestResult.TESTEDOK; } else { @@ -418,10 +418,10 @@ public class EamDbSettingsDialog extends JDialog { } if (!result) { // Remove the incomplete database - if(dbCreated){ + if (dbCreated) { dbSettingsPostgres.deleteDatabase(); } - + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message(), Bundle.EamDbSettingsDialog_okButton_createDbError_title(), @@ -439,10 +439,10 @@ public class EamDbSettingsDialog extends JDialog { && dbSettingsSqlite.insertDefaultDatabaseContent(); } if (!result) { - if(dbCreated){ + if (dbCreated) { dbSettingsSqlite.deleteDatabase(); } - + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message(), Bundle.EamDbSettingsDialog_okButton_createDbError_title(), @@ -455,10 +455,13 @@ public class EamDbSettingsDialog extends JDialog { testingStatus = DatabaseTestResult.TESTEDOK; valid(); } + /** - * 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 + * 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 */ boolean wasConfigurationChanged() { return configurationChanged; @@ -481,12 +484,12 @@ public class EamDbSettingsDialog extends JDialog { Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(), Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(), JOptionPane.WARNING_MESSAGE); - } else if (testingStatus == DatabaseTestResult.SCHEMA_INVALID){ + } else if (testingStatus == DatabaseTestResult.SCHEMA_INVALID) { // There's an existing database or file, but it's not in our format. JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_message(), Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_title(), - JOptionPane.WARNING_MESSAGE); + JOptionPane.WARNING_MESSAGE); } else if (testingStatus == DatabaseTestResult.DB_DOES_NOT_EXIST) { //database doesn't exist do you want to create if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), @@ -580,10 +583,10 @@ public class EamDbSettingsDialog extends JDialog { customizeComponents(); }//GEN-LAST:event_cbDatabaseTypeActionPerformed - private void updateFullDbPath(){ + private void updateFullDbPath() { lbFullDbPath.setText(tfDatabasePath.getText() + File.separator + CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT); } - + private void displayDatabaseSettings(boolean isPostgres) { lbDatabasePath.setVisible(!isPostgres); tfDatabasePath.setVisible(!isPostgres); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form index 13ba7876cd..b83c9782a1 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form @@ -117,7 +117,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index b51e751930..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)); } @@ -149,9 +147,9 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i org.openide.awt.Mnemonics.setLocalizedText(lbCentralRepository, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.lbCentralRepository.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(cbUseCentralRepo, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.cbUseCentralRepo.text")); // NOI18N - cbUseCentralRepo.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cbUseCentralRepoActionPerformed(evt); + cbUseCentralRepo.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + useCentralRepoStateChanged(evt); } }); @@ -433,15 +431,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i } }//GEN-LAST:event_bnDbConfigureActionPerformed - private void cbUseCentralRepoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbUseCentralRepoActionPerformed - //if saved setting is disabled checkbox should be disabled already - store(); - updateDatabase(); - load(); - this.ingestStateUpdated(Case.isCaseOpen()); - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - }//GEN-LAST:event_cbUseCentralRepoActionPerformed - private void manageOrganizationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageOrganizationButtonActionPerformed store(); ManageOrganizationsDialog manageOrganizationsDialog = new ManageOrganizationsDialog(); @@ -452,13 +441,22 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i ManageCasesDialog.displayManageCasesDialog(); }//GEN-LAST:event_showCasesButtonActionPerformed + private void useCentralRepoStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_useCentralRepoStateChanged + //if saved setting is disabled checkbox should be disabled already + store(); + updateDatabase(); + load(); + this.ingestStateUpdated(Case.isCaseOpen()); + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + }//GEN-LAST:event_useCentralRepoStateChanged + @Override @Messages({"GlobalSettingsPanel.validationerrMsg.mustConfigure=Configure the database to enable this module."}) public void load() { tbOops.setText(""); enableButtonSubComponents(false); EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); - cbUseCentralRepo.setSelected(EamDbUtil.useCentralRepo()); // NON-NLS + cbUseCentralRepo.setSelected(EamDbUtil.allowUseOfCentralRepository()); // NON-NLS switch (selectedPlatform) { case POSTGRESQL: PostgresEamDbSettings dbSettingsPg = new PostgresEamDbSettings(); diff --git a/Core/src/org/sleuthkit/autopsy/communications/RelationshipNode.java b/Core/src/org/sleuthkit/autopsy/communications/RelationshipNode.java index 9cee18d5f9..3fc7e36e4e 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/RelationshipNode.java +++ b/Core/src/org/sleuthkit/autopsy/communications/RelationshipNode.java @@ -24,7 +24,6 @@ import java.util.logging.Level; import org.apache.commons.lang3.StringUtils; import org.openide.nodes.Sheet; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.BlackboardArtifactNode; @@ -74,12 +73,12 @@ final class RelationshipNode extends BlackboardArtifactNode { addScoreProperty(sheetSet, tags); CorrelationAttributeInstance correlationAttribute = null; - if (EamDbUtil.useCentralRepo() && UserPreferences.hideCentralRepoCommentsAndOccurrences()== false) { + if (UserPreferences.hideCentralRepoCommentsAndOccurrences()== false) { correlationAttribute = getCorrelationAttributeInstance(); } addCommentProperty(sheetSet, tags, correlationAttribute); - if (EamDbUtil.useCentralRepo() && UserPreferences.hideCentralRepoCommentsAndOccurrences()== false) { + if (UserPreferences.hideCentralRepoCommentsAndOccurrences()== false) { addCountProperty(sheetSet, correlationAttribute); } final BlackboardArtifact artifact = getArtifact(); diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/MessageContentViewer.java b/Core/src/org/sleuthkit/autopsy/contentviewers/MessageContentViewer.java index cf2695dc2e..ef631eeb02 100644 --- a/Core/src/org/sleuthkit/autopsy/contentviewers/MessageContentViewer.java +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/MessageContentViewer.java @@ -38,16 +38,12 @@ import org.openide.nodes.Node; import org.openide.nodes.Sheet; import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; -import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.corecomponents.DataResultPanel; import org.sleuthkit.autopsy.corecomponents.TableFilterNode; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.AbstractAbstractFileNode; import org.sleuthkit.autopsy.datamodel.FileNode; -import org.sleuthkit.autopsy.datamodel.NodeProperty; import org.sleuthkit.autopsy.directorytree.DataResultFilterNode; import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; import org.sleuthkit.datamodel.AbstractFile; @@ -71,7 +67,6 @@ import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHO import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO; import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT; import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TskCoreException; /** diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/ViewPreferencesPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/ViewPreferencesPanel.java index cdea98caf6..e65373ab76 100755 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/ViewPreferencesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/ViewPreferencesPanel.java @@ -26,7 +26,7 @@ import javax.swing.JPanel; import org.netbeans.spi.options.OptionsPanelController; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.CasePreferences; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.TimeZoneUtils; import org.sleuthkit.autopsy.directorytree.DirectoryTreeTopComponent; @@ -75,8 +75,8 @@ public class ViewPreferencesPanel extends JPanel implements OptionsPanel { dataSourcesHideSlackCheckbox.setSelected(UserPreferences.hideSlackFilesInDataSourcesTree()); viewsHideSlackCheckbox.setSelected(UserPreferences.hideSlackFilesInViewsTree()); - commentsOccurencesColumnsCheckbox.setEnabled(EamDbUtil.useCentralRepo()); - commentsOccurencesColumnWrapAroundText.setEnabled(EamDbUtil.useCentralRepo()); + commentsOccurencesColumnsCheckbox.setEnabled(EamDb.isEnabled()); + commentsOccurencesColumnWrapAroundText.setEnabled(EamDb.isEnabled()); commentsOccurencesColumnsCheckbox.setSelected(UserPreferences.hideCentralRepoCommentsAndOccurrences()); hideOtherUsersTagsCheckbox.setSelected(UserPreferences.showOnlyCurrentUserTags()); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java index ce00c55433..76113cb76b 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java @@ -48,7 +48,6 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeNor import org.sleuthkit.autopsy.centralrepository.datamodel.EamArtifactUtil; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable; import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable.HasCommentStatus; @@ -572,7 +571,7 @@ public abstract class AbstractAbstractFileNode extends A CorrelationAttributeInstance getCorrelationAttributeInstance() { CorrelationAttributeInstance attribute = null; - if (EamDbUtil.useCentralRepo() && !UserPreferences.hideCentralRepoCommentsAndOccurrences()) { + if (EamDb.isEnabled() && !UserPreferences.hideCentralRepoCommentsAndOccurrences()) { attribute = EamArtifactUtil.getInstanceFromContent(content); } return attribute; diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java index 17e36ff5a3..55e81acd17 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java @@ -54,7 +54,6 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeNor import org.sleuthkit.autopsy.centralrepository.datamodel.EamArtifactUtil; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable.Score; import org.sleuthkit.autopsy.coreutils.Logger; @@ -572,7 +571,7 @@ public class BlackboardArtifactNode extends AbstractContentNode { - refreshTables(); - }); + if (!scheduledRefreshStarted.getAndSet(true)) { + scheduledRefreshThreadPoolExecutor.scheduleWithFixedDelay(() -> { + EventQueue.invokeLater(() -> { + refreshTables(); + }); + }, AIN_DELAY_BEFORE_FIRST_REFRESH, AIN_REFRESH_INTERVAL_SECS, TimeUnit.SECONDS); } } } diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestDashboard.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestDashboard.java index 8d993f4dc9..754a9c3ad7 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestDashboard.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestDashboard.java @@ -18,9 +18,8 @@ */ package org.sleuthkit.autopsy.experimental.autoingest; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.awt.Cursor; -import java.util.Observable; -import java.util.Observer; import java.util.logging.Level; import java.awt.Color; import java.awt.EventQueue; @@ -29,8 +28,13 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.nio.file.Paths; import java.util.HashSet; +import java.util.Observable; +import java.util.Observer; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.JPanel; import javax.swing.SwingWorker; import javax.swing.UIManager; @@ -46,15 +50,20 @@ import org.sleuthkit.autopsy.experimental.autoingest.AutoIngestNodeRefreshEvents */ @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives final class AutoIngestDashboard extends JPanel implements Observer { - + private final static String ADMIN_ACCESS_FILE_NAME = "_aiaa"; // NON-NLS private final static String ADMIN_ACCESS_FILE_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), ADMIN_ACCESS_FILE_NAME).toString(); + private final static String AID_REFRESH_THREAD_NAME = "AID-refresh-jobs-%d"; + private final static int AID_REFRESH_INTERVAL_SECS = 30; + private final static int AID_DELAY_BEFORE_FIRST_REFRESH = 0; private static final long serialVersionUID = 1L; private static final Logger LOGGER = Logger.getLogger(AutoIngestDashboard.class.getName()); private AutoIngestMonitor autoIngestMonitor; private AutoIngestJobsPanel pendingJobsPanel; private AutoIngestJobsPanel runningJobsPanel; private AutoIngestJobsPanel completedJobsPanel; + private final ScheduledThreadPoolExecutor scheduledRefreshThreadPoolExecutor; + private AtomicBoolean scheduledRefreshStarted = new AtomicBoolean(false); /** * Maintain a mapping of each service to it's last status update. @@ -88,7 +97,7 @@ final class AutoIngestDashboard extends JPanel implements Observer { private AutoIngestDashboard() { this.statusByService = new ConcurrentHashMap<>(); - + scheduledRefreshThreadPoolExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(AID_REFRESH_THREAD_NAME).build()); initComponents(); statusByService.put(ServicesMonitor.Service.REMOTE_CASE_DATABASE.toString(), NbBundle.getMessage(AutoIngestDashboard.class, "AutoIngestDashboard.tbServicesStatusMessage.Message.Down")); statusByService.put(ServicesMonitor.Service.REMOTE_KEYWORD_SEARCH.toString(), NbBundle.getMessage(AutoIngestDashboard.class, "AutoIngestDashboard.tbServicesStatusMessage.Message.Down")); @@ -240,6 +249,7 @@ final class AutoIngestDashboard extends JPanel implements Observer { new Thread(() -> { try { autoIngestMonitor.startUp(); + } catch (AutoIngestMonitor.AutoIngestMonitorException ex) { LOGGER.log(Level.SEVERE, "Unable to start up Auto Ingest Monitor", ex); } @@ -257,18 +267,19 @@ final class AutoIngestDashboard extends JPanel implements Observer { @Override public void update(Observable observable, Object arg) { - if (arg == null ) { - EventQueue.invokeLater(() -> { - refreshTables(); - }); + if (!scheduledRefreshStarted.getAndSet(true)) { + scheduledRefreshThreadPoolExecutor.scheduleWithFixedDelay(() -> { + EventQueue.invokeLater(() -> { + refreshTables(); + }); + }, AID_DELAY_BEFORE_FIRST_REFRESH, AID_REFRESH_INTERVAL_SECS, TimeUnit.SECONDS); } } /** - * Reloads the table models using a jobs snapshot and refreshes the JTables + * Reloads the table models using a RefreshChildrenEvent and refreshes the JTables * that use the models. * - * @param nodeStateSnapshot The jobs snapshot. */ void refreshTables() { pendingJobsPanel.refresh(new RefreshChildrenEvent(autoIngestMonitor)); diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestJobsPanel.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestJobsPanel.java index 18fb8171b2..6962057541 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestJobsPanel.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestJobsPanel.java @@ -164,7 +164,7 @@ final class AutoIngestJobsPanel extends javax.swing.JPanel implements ExplorerMa * Update the contents of this AutoIngestJobsPanel while retaining currently * selected node. * - * @param jobsSnapshot - the JobsSnapshot which will provide the new + * @param refreshEvent - the AutoIngestRefreshEvent which will provide the new * contents */ void refresh(AutoIngestRefreshEvent refreshEvent) { diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java index 84eaa5fcdf..8f7a9c0696 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java @@ -198,6 +198,7 @@ final class AutoIngestMonitor extends Observable implements PropertyChangeListen runningJob.setModuleRuntimesSnapshot(job.getModuleRunTimes()); runningJob.setProcessingStage(job.getProcessingStage(), job.getProcessingStageStartDate()); runningJob.setProcessingStatus(job.getProcessingStatus()); + break; } } setChanged(); @@ -734,7 +735,7 @@ final class AutoIngestMonitor extends Observable implements PropertyChangeListen stopWatch.start(); eventPublisher.publishRemotely(new AutoIngestCaseDeletedEvent(caseName, LOCAL_HOST_NAME, AutoIngestManager.getSystemUserNameProperty())); stopWatch.stop(); - LOGGER.log(Level.INFO, String.format("Used %d s to publish job deletion event for case %s at %s", stopWatch.getElapsedTimeSecs(), caseName,caseDirectoryPath)); + LOGGER.log(Level.INFO, String.format("Used %d s to publish job deletion event for case %s at %s", stopWatch.getElapsedTimeSecs(), caseName, caseDirectoryPath)); } return CaseDeletionResult.FULLY_DELETED;