From dd5f2b4e40300ad53c949ee2654e174493cff67f Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Thu, 27 Aug 2020 19:26:18 -0400 Subject: [PATCH] revisions based on feedback --- .../ui/BaseDataSourceSummaryPanel.java | 10 +--- .../DataSourceSummaryUserActivityPanel.java | 2 +- .../uiutils/DataFetchResult.java | 40 ++++++++-------- .../uiutils/DataFetchWorker.java | 40 ++++++++-------- .../uiutils/DataFetcher.java | 16 +++---- .../uiutils/DataFetcherException.java | 47 ------------------- .../uiutils/JTablePanel.java | 13 ++--- 7 files changed, 53 insertions(+), 115 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcherException.java diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/BaseDataSourceSummaryPanel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/BaseDataSourceSummaryPanel.java index dc31c9a77f..9a0cddd05a 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/BaseDataSourceSummaryPanel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/BaseDataSourceSummaryPanel.java @@ -34,15 +34,6 @@ abstract class BaseDataSourceSummaryPanel extends JPanel { private final SwingWorkerSequentialExecutor executor = new SwingWorkerSequentialExecutor(); private DataSource dataSource; - /** - * The datasource currently used as the model in this panel. - * - * @return The datasource currently being used as the model in this panel. - */ - synchronized DataSource getDataSource() { - return dataSource; - } - /** * Sets datasource to visualize in the panel. * @@ -52,6 +43,7 @@ abstract class BaseDataSourceSummaryPanel extends JPanel { DataSource oldDataSource = this.dataSource; this.dataSource = dataSource; if (this.dataSource != oldDataSource) { + this.executor.cancelRunning(); onNewDataSource(this.dataSource); } } diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceSummaryUserActivityPanel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceSummaryUserActivityPanel.java index 393c429c46..eb3f09a81f 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceSummaryUserActivityPanel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceSummaryUserActivityPanel.java @@ -159,7 +159,7 @@ public class DataSourceSummaryUserActivityPanel extends BaseDataSourceSummaryPan // set results for tables to null. if (dataSource == null || !Case.isCaseOpen()) { this.dataFetchComponents.forEach((item) -> item.getResultHandler() - .accept(DataFetchResult.getLoadedResult(null))); + .accept(DataFetchResult.getSuccessResult(null))); } else { // set tables to display loading screen diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchResult.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchResult.java index 26b76f50f3..93cc24f5fe 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchResult.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchResult.java @@ -19,52 +19,52 @@ package org.sleuthkit.autopsy.datasourcesummary.uiutils; /** - * The intermediate or end result of a loading process. + * The result of a loading process. */ public final class DataFetchResult { /** - * The state of loading in the result. + * The type of result. */ - public enum ProcessorState { - LOADED, LOAD_ERROR + public enum ResultType { + SUCCESS, ERROR } /** - * Creates a DataLoadingResult of loaded data including the data. + * Creates a DataFetchResult of loaded data including the data. * * @param data The data. * * @return The loaded data result. */ - public static DataFetchResult getLoadedResult(R data) { - return new DataFetchResult<>(ProcessorState.LOADED, data, null); + public static DataFetchResult getSuccessResult(R data) { + return new DataFetchResult<>(ResultType.SUCCESS, data, null); } /** - * Returns a load error result. + * Returns an error result. * * @param e The exception (if any) present with the error. * - * @return + * @return The error result. */ - public static DataFetchResult getLoadErrorResult(DataFetcherException e) { - return new DataFetchResult<>(ProcessorState.LOAD_ERROR, null, e); + public static DataFetchResult getErrorResult(Throwable e) { + return new DataFetchResult<>(ResultType.ERROR, null, e); } - private final ProcessorState state; + private final ResultType state; private final R data; - private final DataFetcherException exception; + private final Throwable exception; /** * Main constructor for the DataLoadingResult. * * @param state The state of the result. - * @param data If the result is LOADED, the data related to this + * @param data If the result is SUCCESS, the data related to this * result. - * @param exception If the result is LOAD_ERROR, the related exception. + * @param exception If the result is ERROR, the related exception. */ - private DataFetchResult(ProcessorState state, R data, DataFetcherException exception) { + private DataFetchResult(ResultType state, R data, Throwable exception) { this.state = state; this.data = data; this.exception = exception; @@ -73,21 +73,21 @@ public final class DataFetchResult { /** * @return The current loading state. */ - public ProcessorState getState() { + public ResultType getResultType() { return state; } /** - * @return The data if the state is LOADED. + * @return The data if the state is SUCCESS. */ public R getData() { return data; } /** - * @return The exception if the state is LOAD_ERROR. + * @return The exception if the state is ERROR. */ - public DataFetcherException getException() { + public Throwable getException() { return exception; } } diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchWorker.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchWorker.java index b76579e44d..89f11f544c 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchWorker.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetchWorker.java @@ -25,39 +25,40 @@ import javax.swing.SwingWorker; import org.sleuthkit.autopsy.coreutils.Logger; /** - * A Swing worker that accepts an argument of a data processor and a result - * handler. + * A Swing worker that accepts an argument of a data fetcher and a result + * handler. If the data fetcher throws an InterruptedException, it is treated as + * a cancellation and not passed to the result handler. */ public class DataFetchWorker extends SwingWorker { /** - * Holds the functions necessary for a DataFetchWorker. Includes the - * processor and result handler. The args are not included since they are - * likely dynamic. + * Holds the functions necessary for a DataFetchWorker. Includes the fetcher + * and result handler. The args are not included since they are likely + * dynamic. */ public static class DataFetchComponents { - private final DataFetcher processor; + private final DataFetcher fetcher; private final Consumer> resultHandler; /** * Main constructor. * - * @param processor The processor to be used as an argument for the + * @param fetcher The fetcher to be used as an argument for the * DataFetchWorker. * @param resultHandler The result handler to be used as an argument for * the DataFetchWorker. */ - public DataFetchComponents(DataFetcher processor, Consumer> resultHandler) { - this.processor = processor; + public DataFetchComponents(DataFetcher fetcher, Consumer> resultHandler) { + this.fetcher = fetcher; this.resultHandler = resultHandler; } /** - * @return The function that processes or fetches the data. + * @return The function that fetches the data. */ - public DataFetcher getProcessor() { - return processor; + public DataFetcher getFetcher() { + return fetcher; } /** @@ -83,14 +84,16 @@ public class DataFetchWorker extends SwingWorker { * @param args The argument to be provided to the data processor. */ public DataFetchWorker(DataFetchComponents components, A args) { - this(components.getProcessor(), components.getResultHandler(), args); + this(components.getFetcher(), components.getResultHandler(), args); } /** * Main constructor for this swing worker. * - * @param processor The function that will do the processing of the data - * provided the given args. + * @param processor The function that will do the fetching of the data + * provided the given args. InterruptedException's are + * treated as cancellations and are not passed to the + * result handler. * @param resultHandler The ui function that will handle the result of the * data processing. * @param args The args provided to the data processor. @@ -133,9 +136,8 @@ public class DataFetchWorker extends SwingWorker { // otherwise, there is an error to log logger.log(Level.WARNING, "There was an error while fetching results.", ex); - if (inner instanceof DataFetcherException) { - resultHandler.accept(DataFetchResult.getLoadErrorResult((DataFetcherException) inner)); - } + // and pass the result to the client + resultHandler.accept(DataFetchResult.getErrorResult(inner)); return; } @@ -145,6 +147,6 @@ public class DataFetchWorker extends SwingWorker { } // if the data is loaded, send the data to the consumer. - resultHandler.accept(DataFetchResult.getLoadedResult(result)); + resultHandler.accept(DataFetchResult.getSuccessResult(result)); } } diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcher.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcher.java index bd16912cb1..6eabe79634 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcher.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcher.java @@ -21,25 +21,23 @@ package org.sleuthkit.autopsy.datasourcesummary.uiutils; /** * A function that accepts input of type I and outputs type O. This function is * meant to be utilized with DataFetchWorker and can therefore, throw an - * interrupted exception if the processing is cancelled or a - * DataProcessorException in the event that the processing encountered an error. + * interrupted exception if the processing is cancelled or an Exception of on + * another type in the event that the fetching encountered an error. */ @FunctionalInterface public interface DataFetcher { /** * A function that accepts an input argument and outputs a result. Since it - * is meant to be used with the DataFetchWorker, it throws an interrupted - * exception if the thread has been interrupted. It throws a data processing - * exception if there is an error during processing. + * is meant to be used with the DataFetchWorker, it may throw an interrupted + * exception if the thread has been interrupted. It throws another type of + * exception if there is an error during fetching. * * @param input The input argument. * * @return The output result. * - * @throws InterruptedException Thrown if the operation is cancelled. - * @throws DataFetcherException Thrown if there is an issue processing the - * request. + * @throws Exception */ - O runQuery(I input) throws InterruptedException, DataFetcherException; + O runQuery(I input) throws Exception; } diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcherException.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcherException.java deleted file mode 100644 index b582aa078d..0000000000 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DataFetcherException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 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.datasourcesummary.uiutils; - -/** - * An Exception that is thrown when there is an issue processing data in a - * DataProcessor. - */ -public class DataFetcherException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Main constructor. - * - * @param string The error message. - */ - public DataFetcherException(String string) { - super(string); - } - - /** - * Main constructor. - * - * @param string The error message. - * @param thrwbl The inner exception. - */ - public DataFetcherException(String string, Throwable thrwbl) { - super(string, thrwbl); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java index c74c5d65c9..1e4184d85b 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java @@ -90,13 +90,6 @@ public class JTablePanel extends JPanel { this.visible = visible; } - /** - * @return The child JLabel component. - */ - JLabel getLabel() { - return label; - } - /** * Sets the message to be displayed in the child jlabel. * @@ -391,15 +384,15 @@ public class JTablePanel extends JPanel { return; } - switch (result.getState()) { - case LOADED: + switch (result.getResultType()) { + case SUCCESS: if (result.getData() == null || result.getData().isEmpty()) { showMessage(noResultsMessage); } else { showResults(result.getData()); } break; - case LOAD_ERROR: + case ERROR: // if there is an error, log accordingly, set result list to // empty and display error message logger.log(Level.WARNING, "An exception was caused while results were loaded.", result.getException());