From 0c82f1637c40d0e49f40e787fabb72cbeddcd766 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 14 Mar 2018 13:40:02 -0600 Subject: [PATCH] adjusted the sql query to select all the data needed to display common files, passed new data down to nodes --- .../commonfilesearch/CommonFilesChildren.java | 20 +++++++-- .../commonfilesearch/CommonFilesPanel.java | 6 ++- .../CommonFilesSearchNode.java | 8 ++-- .../autopsy/datamodel/CommonFileNode.java | 42 +++++++++++++++---- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesChildren.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesChildren.java index d3af492fd6..fd340ef72d 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesChildren.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesChildren.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.commonfilesearch; +import java.util.HashMap; import java.util.List; import org.sleuthkit.datamodel.AbstractFile; import org.openide.nodes.Children; @@ -29,17 +30,28 @@ import org.sleuthkit.autopsy.datamodel.CommonFileNode; */ final class CommonFilesChildren extends Children.Keys { - CommonFilesChildren(boolean lazy, List fileList) { + private final java.util.Map instanceCountMap; + private final java.util.Map dataSourceMap; + + CommonFilesChildren(boolean lazy, List fileList, java.util.Map instanceCountMap, java.util.Map dataSourceMap) { super(lazy); this.setKeys(fileList); + + this.instanceCountMap = instanceCountMap; + this.dataSourceMap = dataSourceMap; } @Override protected Node[] createNodes(AbstractFile t) { + + final String md5Hash = t.getMd5Hash(); + + int instanceCount = this.instanceCountMap.get(md5Hash); + String dataSources = this.dataSourceMap.get(md5Hash); + Node[] node = new Node[1]; - - //TODO replace FileNode with our own subclass of its base type or similar (use CommonFileNode once its finished) - node[0] = new CommonFileNode(t); + node[0] = new CommonFileNode(t, instanceCount, dataSources); + return node; } } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java index df7f1b37d3..7bc2d75b97 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java @@ -90,7 +90,7 @@ public final class CommonFilesPanel extends javax.swing.JPanel { //TODO this is sort of a misues of the findAllFilesWhere function and seems brittle... //...consider doing something else //TODO verify that this works with postgres - return tskDb.findAllFilesWhere("1 == 1 AND (known != 1 OR known IS NULL) GROUP BY md5 HAVING COUNT(*) > 1;"); + return tskDb.findAllFilesWhere("md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL) GROUP BY md5 HAVING COUNT(*) > 1) order by md5"); } @Override @@ -100,7 +100,9 @@ public final class CommonFilesPanel extends javax.swing.JPanel { List contentList = get(); - CommonFilesSearchNode contentFilesNode = new CommonFilesSearchNode(contentList); + CommonFilesMetaData metadata = CommonFilesMetaData.DeDupeFiles(contentList); + + CommonFilesSearchNode contentFilesNode = new CommonFilesSearchNode(metadata.dedupedFiles, metadata.instanceCountMap, metadata.dataSourceMap); TopComponent component = DataResultTopComponent.createInstance( title, diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchNode.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchNode.java index 9f67afce58..bac59f6de9 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchNode.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchNode.java @@ -18,21 +18,23 @@ */ package org.sleuthkit.autopsy.commonfilesearch; +import java.util.ArrayList; import java.util.List; import org.openide.nodes.AbstractNode; import org.openide.util.NbBundle; import org.sleuthkit.datamodel.AbstractFile; /** - * Encapsulates data used to display common files search results in the top right pane. + * Encapsulates data used to display common files search results in the top + * right pane. */ //TODO rename to CommonFilesSearchNode final class CommonFilesSearchNode extends AbstractNode { private CommonFilesChildren children; - CommonFilesSearchNode(List keys) { - super(new CommonFilesChildren(true, keys)); + CommonFilesSearchNode(List keys, java.util.Map instanceCountMap, java.util.Map dataSourceMap) { + super(new CommonFilesChildren(true, keys, instanceCountMap, dataSourceMap)); this.children = (CommonFilesChildren) this.getChildren(); } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/CommonFileNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/CommonFileNode.java index 20529b43e2..c46288e02f 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/CommonFileNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/CommonFileNode.java @@ -34,9 +34,27 @@ public class CommonFileNode extends AbstractNode { private final AbstractFile content; - public CommonFileNode(AbstractFile fsContent) { + private final int commonFileCount; + + private final String dataSources; + + public CommonFileNode(AbstractFile fsContent, int commonFileCount, String dataSources) { super(Children.LEAF); this.content = fsContent; + this.commonFileCount = commonFileCount; + this.dataSources = dataSources; + } + + int getCommonFileCount(){ + return this.commonFileCount; + } + + AbstractFile getContent(){ + return this.content; + } + + String getDataSources(){ + return this.dataSources; } @Override @@ -49,7 +67,7 @@ public class CommonFileNode extends AbstractNode { } Map map = new LinkedHashMap<>(); - fillPropertyMap(map, content); + fillPropertyMap(map, this); final String NO_DESCR = Bundle.AbstractFsContentNode_noDesc_text(); for (CommonFilePropertyType propType : CommonFilePropertyType.values()) { @@ -63,25 +81,31 @@ public class CommonFileNode extends AbstractNode { return s; } - /** + /** * Fill map with AbstractFile properties * * @param map map with preserved ordering, where property names/values * are put - * @param content The content to get properties for. + * @param node The item to get properties for. */ - static public void fillPropertyMap(Map map, AbstractFile content) { - map.put(CommonFilePropertyType.Name.toString(), content.getName()); - map.put(CommonFilePropertyType.Md5Hash.toString(), StringUtils.defaultString(content.getMd5Hash())); + static public void fillPropertyMap(Map map, CommonFileNode node) { + map.put(CommonFilePropertyType.Name.toString(), node.getContent().getName()); + map.put(CommonFilePropertyType.InstanceCount.toString(), node.getCommonFileCount()); + map.put(CommonFilePropertyType.Md5Hash.toString(), StringUtils.defaultString(node.getContent().getMd5Hash())); + map.put(CommonFilePropertyType.DataSources.toString(), node.getDataSources()); } @NbBundle.Messages({ "CommonFilePropertyType.nameColLbl=Name", - "CommonFilePropertyType.md5HashColLbl=MD5 Hash"}) + "CommonFilePropertyType.instanceColLbl1=Instance Count", + "CommonFilePropertyType.md5HashColLbl=MD5 Hash", + "CommonFilePropertyType.dataSourcesColLbl=Data Sources"}) public enum CommonFilePropertyType { Name(Bundle.CommonFilePropertyType_nameColLbl()), - Md5Hash(Bundle.CommonFilePropertyType_md5HashColLbl()); + InstanceCount(Bundle.CommonFilePropertyType_instanceColLbl1()), + Md5Hash(Bundle.CommonFilePropertyType_md5HashColLbl()), + DataSources(Bundle.CommonFilePropertyType_dataSourcesColLbl()); final private String displayString;