From c4518c3c178aa26e5e2be89dfcc2d8de37e4e5ba Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Thu, 10 Sep 2020 10:17:56 -0400 Subject: [PATCH] revisions --- .../datamodel/DataSourcePastCasesSummary.java | 47 ++++++++++++- .../datasourcesummary/ui/PastCasesPanel.java | 66 +++++++++---------- 2 files changed, 76 insertions(+), 37 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourcePastCasesSummary.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourcePastCasesSummary.java index b219049a6e..8d077f1fbf 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourcePastCasesSummary.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourcePastCasesSummary.java @@ -59,6 +59,21 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class DataSourcePastCasesSummary { + /** + * Exception that is thrown in the event that a data source has not been + * ingested with the Central Repository Ingest Module. + */ + public static class NotCentralRepoIngestedException extends Exception { + + /** + * Main constructor. + * @param string Error message. + */ + public NotCentralRepoIngestedException(String string) { + super(string); + } + } + private static final String CENTRAL_REPO_INGEST_NAME = CentralRepoIngestModuleFactory.getModuleName().toUpperCase().trim(); private static final BlackboardAttribute.Type TYPE_COMMENT = new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_COMMENT); @@ -162,9 +177,12 @@ public class DataSourcePastCasesSummary { * * @throws SleuthkitCaseProviderException * @throws TskCoreException + * @throws NotCentralRepoIngestedException */ private List> getPastCases(DataSource dataSource, ARTIFACT_TYPE artifactType) - throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException { + throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, NotCentralRepoIngestedException { + + throwOnNotCentralRepoIngested(dataSource); Collection> cases = this.caseProvider.get().getBlackboard().getArtifacts(artifactType.getTypeID(), dataSource.getId()) .stream() @@ -234,6 +252,27 @@ public class DataSourcePastCasesSummary { } + /** + * Throws an exception if the current data source has not been ingested with + * the Central Repository Ingest Module. + * + * @param dataSource The data source to check if it has been ingested with + * the Central Repository Ingest Module. + * + * @throws SleuthkitCaseProviderException + * @throws TskCoreException + * @throws NotCentralRepoIngestedException + */ + private void throwOnNotCentralRepoIngested(DataSource dataSource) + throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, NotCentralRepoIngestedException { + + if (!isCentralRepoIngested(dataSource)) { + String objectId = (dataSource == null) ? "" : String.valueOf(dataSource.getId()); + String message = String.format("Data source: %s has not been ingested with the Central Repository Ingest Module.", objectId); + throw new NotCentralRepoIngestedException(message); + } + } + /** * Get all cases that share notable files with the given data source. * @@ -245,9 +284,10 @@ public class DataSourcePastCasesSummary { * * @throws SleuthkitCaseProviderException * @throws TskCoreException + * @throws NotCentralRepoIngestedException */ public List> getPastCasesWithNotableFile(DataSource dataSource) - throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException { + throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, NotCentralRepoIngestedException { return getPastCases(dataSource, ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT); } @@ -263,9 +303,10 @@ public class DataSourcePastCasesSummary { * * @throws SleuthkitCaseProviderException * @throws TskCoreException + * @throws NotCentralRepoIngestedException */ public List> getPastCasesWithSameId(DataSource dataSource) - throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException { + throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, NotCentralRepoIngestedException { return getPastCases(dataSource, ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT); } } diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/PastCasesPanel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/PastCasesPanel.java index c61ade219d..6e578cd492 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/PastCasesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/PastCasesPanel.java @@ -20,22 +20,21 @@ package org.sleuthkit.autopsy.datasourcesummary.ui; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datasourcesummary.datamodel.DataSourcePastCasesSummary; -import org.sleuthkit.autopsy.datasourcesummary.datamodel.SleuthkitCaseProvider; +import org.sleuthkit.autopsy.datasourcesummary.datamodel.DataSourcePastCasesSummary.NotCentralRepoIngestedException; import org.sleuthkit.autopsy.datasourcesummary.uiutils.CellModelTableCellRenderer.DefaultCellModel; import org.sleuthkit.autopsy.datasourcesummary.uiutils.DataFetchResult; +import org.sleuthkit.autopsy.datasourcesummary.uiutils.DataFetchResult.ResultType; import org.sleuthkit.autopsy.datasourcesummary.uiutils.DataFetchWorker; import org.sleuthkit.autopsy.datasourcesummary.uiutils.DataFetchWorker.DataFetchComponents; import org.sleuthkit.autopsy.datasourcesummary.uiutils.JTablePanel; import org.sleuthkit.autopsy.datasourcesummary.uiutils.JTablePanel.ColumnModel; import org.sleuthkit.datamodel.DataSource; -import org.sleuthkit.datamodel.TskCoreException; /** * A tab shown in data source summary displaying information about a datasource @@ -81,29 +80,42 @@ public class PastCasesPanel extends BaseDataSourceSummaryPanel { this(new DataSourcePastCasesSummary()); } - private final DataSourcePastCasesSummary pastCaseData; - /** * Creates new form PastCasesPanel */ public PastCasesPanel(DataSourcePastCasesSummary pastCaseData) { - this.pastCaseData = pastCaseData; - // set up data acquisition methods dataFetchComponents = Arrays.asList( // hashset hits loading components new DataFetchWorker.DataFetchComponents<>( (dataSource) -> pastCaseData.getPastCasesWithNotableFile(dataSource), - (result) -> notableFileTable.showDataFetchResult(result)), + (result) -> handleResult(notableFileTable, result)), // keyword hits loading components new DataFetchWorker.DataFetchComponents<>( (dataSource) -> pastCaseData.getPastCasesWithSameId(dataSource), - (result) -> sameIdTable.showDataFetchResult(result)) + (result) -> handleResult(sameIdTable, result)) ); initComponents(); } + /** + * handles displaying the result for the table. If a + * NotCentralRepoIngestedException is thrown, then an appropriate message is + * shown. Otherwise, this method uses the tables default showDataFetchResult + * method. + * + * @param table The table. + * @param result The result. + */ + private void handleResult(JTablePanel table, DataFetchResult> result) { + if (result.getResultType() == ResultType.ERROR && result.getException() instanceof NotCentralRepoIngestedException) { + table.showMessage(Bundle.PastCasesPanel_onNoCrIngest_message()); + } else { + table.showDataFetchResult(result); + } + } + @Override protected void onNewDataSource(DataSource dataSource) { // if no data source is present or the case is not open, @@ -111,34 +123,20 @@ public class PastCasesPanel extends BaseDataSourceSummaryPanel { if (dataSource == null || !Case.isCaseOpen()) { this.dataFetchComponents.forEach((item) -> item.getResultHandler() .accept(DataFetchResult.getSuccessResult(null))); - return; - } - boolean centralRepoIngested = false; - try { - centralRepoIngested = this.pastCaseData.isCentralRepoIngested(dataSource); - } catch (SleuthkitCaseProvider.SleuthkitCaseProviderException | TskCoreException ex) { - logger.log(Level.WARNING, "There was an error while determining if dataSource has been central repo ingested.", ex); - } - - if (!centralRepoIngested) { + } else { // set tables to display loading screen - this.tables.forEach((table) -> table.showMessage(Bundle.PastCasesPanel_onNoCrIngest_message())); - return; + this.tables.forEach((table) -> table.showDefaultLoadingMessage()); + + // create swing workers to run for each table + List> workers = dataFetchComponents + .stream() + .map((components) -> new DataFetchWorker<>(components, dataSource)) + .collect(Collectors.toList()); + + // submit swing workers to run + submit(workers); } - - // set tables to display loading screen - this.tables.forEach((table) -> table.showDefaultLoadingMessage()); - - // create swing workers to run for each table - List> workers = dataFetchComponents - .stream() - .map((components) -> new DataFetchWorker<>(components, dataSource)) - .collect(Collectors.toList()); - - // submit swing workers to run - submit(workers); - } /**