From 538bd3c2afb241cd5688b66a378bb57d8048da05 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Tue, 17 Apr 2018 14:32:32 -0600 Subject: [PATCH] comments and access modifiers # Conflicts: # Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java # Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java # Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java --- .../commonfilesearch/AllDataSources.java | 2 +- .../commonfilesearch/CommonFilesMetaData.java | 22 ++++++---- .../CommonFilesMetaDataBuilder.java | 41 ++++++++++++++----- .../commonfilesearch/CommonFilesPanel.java | 4 +- .../FileInstanceMetaData.java | 25 +++++++---- .../autopsy/commonfilesearch/Md5MetaData.java | 16 +++++--- .../commonfilesearch/SingleDataSource.java | 10 ++++- .../sleuthkit/autopsy/datamodel/Md5Node.java | 30 ++++++-------- .../netbeans/core/startup/Bundle.properties | 2 +- .../core/windows/view/ui/Bundle.properties | 2 +- 10 files changed, 97 insertions(+), 57 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java index 7cbb44533a..89bc1e6199 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java @@ -24,7 +24,7 @@ import java.util.Map; /** * Provides logic for selecting common files from all data sources. */ -class AllDataSources extends CommonFilesMetaDataBuilder { +final class AllDataSources extends CommonFilesMetaDataBuilder { private static final String WHERE_CLAUSE = "md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL)%s GROUP BY md5 HAVING COUNT(*) > 1) order by md5"; diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaData.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaData.java index 26af5e81dc..32ce695b03 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaData.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaData.java @@ -26,27 +26,35 @@ import java.util.Map; * Utility and wrapper model around data required for Common Files Search results. * Subclass this to implement different selections of files from the case. */ -public class CommonFilesMetaData { +final class CommonFilesMetaData { private final Map metadata; private final Map dataSourceIdToNameMap; + /** + * Create meta dat object which can be handed off to the node factories + * @param metadata map of md5 to parent-level node meta data + * @param dataSourcesMap map of obj_id to data source name + */ CommonFilesMetaData(Map metadata, Map dataSourcesMap) { this.metadata = metadata; this.dataSourceIdToNameMap = dataSourcesMap; } - public Md5MetaData getMetaDataForMd5(String md5){ + /** + * Find the meta data for the given md5. + * + * This is a convenience method - you can also iterate over getMetaData(). + * @param md5 key + * @return + */ + Md5MetaData getMetaDataForMd5(String md5){ return this.metadata.get(md5); } - public Map getMataData(){ + Map getMataData(){ return Collections.unmodifiableMap(this.metadata); } - - public Map getDataSourceIdToNameMap() { - return Collections.unmodifiableMap(this.dataSourceIdToNameMap); - } int size() { int count = 0; diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java index 31cf59ce5b..2f217f09e0 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java @@ -41,8 +41,9 @@ import org.sleuthkit.datamodel.TskCoreException; /** * - * Generates a List when collateFiles() is called, which - * organizes AbstractFiles by md5 to prepare to display in viewer. + * Generates a List when + * findCommonFiles() is called, which + * organizes files by md5 to prepare to display in viewer. * * This entire thing runs on a background thread where exceptions are handled. */ @@ -102,6 +103,14 @@ abstract class CommonFilesMetaDataBuilder { filterByDoc = filterByDocMimeType; } + /** + * Use this as a prefix when building the SQL select statement. + * + *
    + *
  • You only have to specify the WHERE clause if you use this.
  • + *
  • If you do not use this string, you must use at least the columns selected below, in that order.
  • + *
+ */ protected static String SELECT_PREFIX = "SELECT obj_id, md5, data_source_obj_id from tsk_files where"; /** @@ -115,7 +124,16 @@ abstract class CommonFilesMetaDataBuilder { */ protected abstract String buildSqlSelectStatement(); - public Map findCommonFiles() throws TskCoreException, NoCurrentCaseException, SQLException { + /** + * Generate a meta data object which encapsulates everything need to + * add the tree table tab to the top component. + * @return a data object with all of the matched files in a hierarchical + * format + * @throws TskCoreException + * @throws NoCurrentCaseException + * @throws SQLException + */ + public CommonFilesMetaData findCommonFiles() throws TskCoreException, NoCurrentCaseException, SQLException { Map commonFiles = new HashMap<>(); @@ -131,17 +149,18 @@ abstract class CommonFilesMetaDataBuilder { String dataSource = this.dataSourceIdToNameMap.get(dataSourceId); if(commonFiles.containsKey(md5)){ - commonFiles.get(md5).getMetaData().add(new FileInstanceMetaData(objectId, dataSource, dataSourceId)); + final Md5MetaData md5MetaData = commonFiles.get(md5); + md5MetaData.addFileInstanceMetaData(new FileInstanceMetaData(objectId, dataSource)); } else { - List fileInstances = new ArrayList<>(); - fileInstances.add(new FileInstanceMetaData(objectId, dataSource, dataSourceId)); - Md5MetaData md5s = new Md5MetaData(md5, fileInstances); - commonFiles.put(md5, md5s); + final List fileInstances = new ArrayList<>(); + fileInstances.add(new FileInstanceMetaData(objectId, dataSource)); + Md5MetaData md5MetaData = new Md5MetaData(md5, fileInstances); + commonFiles.put(md5, md5MetaData); } - } - } + } + } - return commonFiles; + return new CommonFilesMetaData(commonFiles, this.dataSourceIdToNameMap); } String determineMimeTypeFilter() { diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java index a4b549afa8..943c2e1c07 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java @@ -263,8 +263,8 @@ public final class CommonFilesPanel extends javax.swing.JPanel { setTitleForSingleSource(dataSourceId); } - - CommonFilesMetaData metaData = new CommonFilesMetaData(builder.findCommonFiles(), CommonFilesPanel.this.dataSourceMap); + + CommonFilesMetaData metaData = builder.findCommonFiles(); return metaData; } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/FileInstanceMetaData.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/FileInstanceMetaData.java index 57067fa4e8..f990394479 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/FileInstanceMetaData.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/FileInstanceMetaData.java @@ -20,29 +20,36 @@ package org.sleuthkit.autopsy.commonfilesearch; /** - * Encalsulates data required to instantiate a FileInstanceNode. + * Encapsulates data required to instantiate a FileInstanceNode. */ -public class FileInstanceMetaData { +final public class FileInstanceMetaData { private Long objectId; private String dataSourceName; - private Long dataSourceId; - public FileInstanceMetaData (Long objectId, String dataSourceName, Long dataSourceId){ + /** + * Create meta data required to find an abstract file and build a FileInstanceNode. + * @param objectId id of abstract file to find + * @param dataSourceName name of datasource where the object is found + */ + FileInstanceMetaData (Long objectId, String dataSourceName){ this.objectId = objectId; this.dataSourceName = dataSourceName; - this.dataSourceId = dataSourceId; } + /** + * obj_id for the file represented by this object + * @return + */ public Long getObjectId(){ return this.objectId; } + /** + * Name of datasource where this instance was found. + * @return + */ public String getDataSourceName(){ return this.dataSourceName; - } - - public Long getDataSourceId(){ - return this.dataSourceId; } } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/Md5MetaData.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/Md5MetaData.java index 9f415ea07b..cd1f1fba46 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/Md5MetaData.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/Md5MetaData.java @@ -19,19 +19,21 @@ */ package org.sleuthkit.autopsy.commonfilesearch; +import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; /** - * Encaspsulates data required to instantiate an Md5Node. + * Encapsulates data required to instantiate an Md5Node. */ -public class Md5MetaData { +final public class Md5MetaData { private String md5; private List fileInstances; - public Md5MetaData(String md5, List fileInstances){ + Md5MetaData(String md5, List fileInstances){ this.md5 = md5; this.fileInstances = fileInstances; } @@ -40,8 +42,12 @@ public class Md5MetaData { return this.md5; } - public List getMetaData(){ - return this.fileInstances; + void addFileInstanceMetaData(FileInstanceMetaData metadata){ + this.fileInstances.add(metadata); + } + + public Collection getMetaData(){ + return Collections.unmodifiableCollection(this.fileInstances); } public int size(){ diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java index 10799e4c5b..9e2afac529 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java @@ -26,12 +26,18 @@ import java.util.Set; /** * Provides logic for selecting common files from a single data source. */ -class SingleDataSource extends CommonFilesMetaDataBuilder { +final class SingleDataSource extends CommonFilesMetaDataBuilder { private static final String WHERE_CLAUSE = "%s md5 in (select md5 from tsk_files where md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL) and data_source_obj_id=%s%s) GROUP BY md5 HAVING COUNT(*) > 1) order by md5"; private final Long selectedDataSourceId; - public SingleDataSource(Long dataSourceId, Map dataSourceIdMap, boolean filterByMediaMimeType, boolean filterByDocMimeType) { + /** + * Implements the algorithm for getting common files that appear at least + * once in the given data source. + * @param dataSourceId data source id for which common files must appear at least once + * @param dataSourceIdMap map of obj_id to data source name + */ +public SingleDataSource(Long dataSourceId, Map dataSourceIdMap, boolean filterByMediaMimeType, boolean filterByDocMimeType) { super(dataSourceIdMap, filterByMediaMimeType, filterByDocMimeType); this.selectedDataSourceId = dataSourceId; } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java b/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java index cacef742e6..79f87542ec 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java @@ -22,6 +22,7 @@ package org.sleuthkit.autopsy.datamodel; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; import org.openide.nodes.ChildFactory; import org.openide.nodes.Children; import org.openide.nodes.Node; @@ -31,8 +32,10 @@ import org.openide.util.NbBundle; import org.openide.util.lookup.Lookups; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.commonfilesearch.CommonFilesPanel; import org.sleuthkit.autopsy.commonfilesearch.FileInstanceMetaData; import org.sleuthkit.autopsy.commonfilesearch.Md5MetaData; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; @@ -40,10 +43,13 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Represents a common files match - two or more files which appear to be the * same file and appear as children of this node. This node will simply contain - * the MD5 of the matched files, + * the MD5 of the matched files, the data sources those files were found within, + * and a count of the instances represented by the md5. */ public class Md5Node extends DisplayableItemNode { + private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class.getName()); + private final String md5Hash; private final int commonFileCount; private final String dataSources; @@ -108,7 +114,7 @@ public class Md5Node extends DisplayableItemNode { @Override public T accept(DisplayableItemNodeVisitor visitor) { - return visitor.visit(this); //TODO need to work on this + return visitor.visit(this); } @Override @@ -141,31 +147,19 @@ public class Md5Node extends DisplayableItemNode { return new FileInstanceNode(abstractFile, file.getDataSourceName()); } catch (NoCurrentCaseException ex) { - Exceptions.printStackTrace(ex); - //TODO log this + LOGGER.log(Level.SEVERE, String.format("Unable to create node for file with obj_id: %s.", new Object[]{file.getObjectId()}), ex); } catch (TskCoreException ex) { - Exceptions.printStackTrace(ex); - //TODO log this + LOGGER.log(Level.SEVERE, String.format("Unable to create node for file with obj_id: %s.", new Object[]{file.getObjectId()}), ex); } - //TODO smells bad... + //TODO smells bad...do something? return null; } @Override - protected boolean createKeys(List list) { - - //TODO load children from db here - //TODO consider doing db work here??? - + protected boolean createKeys(List list) { list.addAll(this.descendants.getMetaData()); return true; } - -// @Override -// protected Node createWaitNode() { -// //TODO could skip this...maybe??? -// return new CommonFileChildNodeLoading(Children.LEAF); -// } } @NbBundle.Messages({ diff --git a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties index b1adb5d40b..25a8bb023f 100644 --- a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties +++ b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties @@ -1,5 +1,5 @@ #Updated by build script -#Mon, 19 Mar 2018 11:17:11 -0700 +#Tue, 17 Apr 2018 09:14:51 -0600 LBL_splash_window_title=Starting Autopsy SPLASH_HEIGHT=314 SPLASH_WIDTH=538 diff --git a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties index 6cb9d4bdea..0ddc19dcc0 100644 --- a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties +++ b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties @@ -1,4 +1,4 @@ #Updated by build script -#Fri, 09 Mar 2018 13:03:41 -0700 +#Tue, 17 Apr 2018 09:14:51 -0600 CTL_MainWindow_Title=Autopsy 4.6.0 CTL_MainWindow_Title_No_Project=Autopsy 4.6.0