6639 refactor to allow for artifact type filters

This commit is contained in:
William Schaefer 2020-07-30 09:59:13 -04:00
parent 7514dec615
commit 092430b102
29 changed files with 353 additions and 134 deletions

View File

@ -90,12 +90,12 @@ abstract class AbstractDiscoveryFilterPanel extends javax.swing.JPanel {
} }
/** /**
* Get the FileFilter which is represented by this Panel. * Get the AbstractFilter which is represented by this Panel.
* *
* @return The FileFilter for the selected settings, null if the settings * @return The AbstractFilter for the selected settings, null if the settings
* are not in use. * are not in use.
*/ */
abstract FileSearchFiltering.FileFilter getFilter(); abstract AbstractFilter getFilter();
/** /**
* Remove listeners from the checkbox and the list if they exist. * Remove listeners from the checkbox and the list if they exist.

View File

@ -0,0 +1,62 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.sleuthkit.autopsy.discovery;
import java.util.ArrayList;
import java.util.List;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
import org.sleuthkit.datamodel.SleuthkitCase;
/**
* Base class for the filters.
*/
abstract class AbstractFilter {
/**
* Returns part of a query on the tsk_files table that can be AND-ed with
* other pieces
*
* @return the SQL query or an empty string if there is no SQL query for
* this filter.
*/
abstract String getWhereClause();
/**
* Indicates whether this filter needs to use the secondary, non-SQL method
* applyAlternateFilter().
*
* @return false by default
*/
boolean useAlternateFilter() {
return false;
}
/**
* Run a secondary filter that does not operate on tsk_files.
*
* @param currentResults The current list of matching files; empty if no
* filters have yet been run.
* @param caseDb The case database
* @param centralRepoDb The central repo database. Can be null if the
* filter does not require it.
*
* @return The list of files that match this filter (and any that came
* before it)
*
* @throws FileSearchException
*/
List<ResultFile> applyAlternateFilter(List<ResultFile> currentResults, SleuthkitCase caseDb,
CentralRepository centralRepoDb) throws FileSearchException {
return new ArrayList<>();
}
/**
* Get a description of the selected filter.
*
* @return A description of the filter
*/
abstract String getDesc();
}

View File

@ -61,6 +61,8 @@ abstract class AbstractFiltersPanel extends JPanel implements ActionListener, Li
secondColumnPanel.setLayout(new GridBagLayout()); secondColumnPanel.setLayout(new GridBagLayout());
} }
abstract SearchData.ResultType getResultType();
/** /**
* Get the type of results this filters panel is for. * Get the type of results this filters panel is for.
* *
@ -242,12 +244,18 @@ abstract class AbstractFiltersPanel extends JPanel implements ActionListener, Li
* *
* @return The list of filters selected by the user. * @return The list of filters selected by the user.
*/ */
synchronized List<FileSearchFiltering.FileFilter> getFilters() { synchronized List<AbstractFilter> getFilters() {
List<FileSearchFiltering.FileFilter> filtersToUse = new ArrayList<>();
filtersToUse.add(new FileSearchFiltering.FileTypeFilter(getFileType())); List<AbstractFilter> filtersToUse = new ArrayList<>();
if (getResultType().equals(SearchData.ResultType.FILE)) {
filtersToUse.add(new SearchFiltering.FileTypeFilter(getFileType()));
} else if (getResultType().equals(SearchData.ResultType.ARTIFACT)){
}
for (AbstractDiscoveryFilterPanel filterPanel : filters) { for (AbstractDiscoveryFilterPanel filterPanel : filters) {
if (filterPanel.getCheckbox().isSelected()) { if (filterPanel.getCheckbox().isSelected()) {
FileSearchFiltering.FileFilter filter = filterPanel.getFilter(); AbstractFilter filter = filterPanel.getFilter();
if (filter != null) { if (filter != null) {
filtersToUse.add(filter); filtersToUse.add(filter);
} }

View File

@ -0,0 +1,82 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.sleuthkit.autopsy.discovery;
import org.openide.util.NbBundle;
import org.sleuthkit.datamodel.BlackboardArtifact;
/**
* Utility enums for searches made for artifacts with Discovery.
*/
public class ArtifactSearchData extends SearchData {
@Override
ResultType getResultType(){
return ResultType.ARTIFACT;
}
/**
* Enum representing the file type. We don't simply use
* FileTypeUtils.FileTypeCategory because: - Some file types categories
* overlap - It is convenient to have the "OTHER" option for files that
* don't match the given types
*/
@NbBundle.Messages({
"ArtifactSearchData.ArtifactType.Domain.displayName=Domain",
"ArtifactSearchData.ArtifactType.Other.displayName=Other"})
enum ArtifactType {
DOMAIN(0, Bundle.ArtifactSearchData_ArtifactType_Domain_displayName(), BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK),
OTHER(1, Bundle.ArtifactSearchData_ArtifactType_Other_displayName(), null);
private final int ranking; // For ordering in the UI
private final String displayName;
private final BlackboardArtifact.ARTIFACT_TYPE artifactType;
ArtifactType(int value, String displayName, BlackboardArtifact.ARTIFACT_TYPE type) {
this.ranking = value;
this.displayName = displayName;
this.artifactType = type;
}
/**
* Get the MIME types matching this category.
*
* @return Collection of MIME type strings
*/
BlackboardArtifact.ARTIFACT_TYPE getMediaTypes() {
return artifactType;
}
@Override
public String toString() {
return displayName;
}
/**
* Get the rank for sorting.
*
* @return the rank (lower should be displayed first)
*/
int getRanking() {
return ranking;
}
static ArtifactType fromBlackboardArtifact(final BlackboardArtifact.ARTIFACT_TYPE type) {
switch (type) {
case TSK_WEB_BOOKMARK:
return DOMAIN;
default:
return OTHER;
}
}
}
}

View File

@ -1,3 +1,5 @@
ArtifactSearchData.ArtifactType.Domain.displayName=Domain
ArtifactSearchData.ArtifactType.Other.displayName=Other
CTL_OpenDiscoveryAction=Discovery CTL_OpenDiscoveryAction=Discovery
# {0} - dataSourceName # {0} - dataSourceName
DataSourceModuleWrapper.exifModule.text=Exif Parser module was not run on data source: {0}\n DataSourceModuleWrapper.exifModule.text=Exif Parser module was not run on data source: {0}\n

View File

@ -194,10 +194,10 @@ final class DataSourceFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (dataSourceCheckbox.isSelected()) { if (dataSourceCheckbox.isSelected()) {
List<DataSource> dataSources = dataSourceList.getSelectedValuesList().stream().map(t -> t.getDataSource()).collect(Collectors.toList()); List<DataSource> dataSources = dataSourceList.getSelectedValuesList().stream().map(t -> t.getDataSource()).collect(Collectors.toList());
return new FileSearchFiltering.DataSourceFilter(dataSources); return new SearchFiltering.DataSourceFilter(dataSources);
} }
return null; return null;
} }

View File

@ -503,7 +503,7 @@ final class DiscoveryDialog extends javax.swing.JDialog {
tc.open(); tc.open();
} }
tc.resetTopComponent(); tc.resetTopComponent();
List<FileSearchFiltering.FileFilter> filters; List<AbstractFilter> filters;
if (videosButton.isSelected()) { if (videosButton.isSelected()) {
filters = videoFilterPanel.getFilters(); filters = videoFilterPanel.getFilters();
} else if (documentsButton.isSelected()) { } else if (documentsButton.isSelected()) {

View File

@ -116,7 +116,7 @@ final class DiscoveryEventUtils {
static final class SearchCompleteEvent { static final class SearchCompleteEvent {
private final Map<GroupKey, Integer> groupMap; private final Map<GroupKey, Integer> groupMap;
private final List<FileSearchFiltering.FileFilter> searchFilters; private final List<AbstractFilter> searchFilters;
private final FileSearch.AttributeType groupingAttribute; private final FileSearch.AttributeType groupingAttribute;
private final FileGroup.GroupSortingAlgorithm groupSort; private final FileGroup.GroupSortingAlgorithm groupSort;
private final FileSorter.SortingMethod fileSortMethod; private final FileSorter.SortingMethod fileSortMethod;
@ -132,7 +132,7 @@ final class DiscoveryEventUtils {
* @param groupSort The sorting algorithm used for groups. * @param groupSort The sorting algorithm used for groups.
* @param fileSortMethod The sorting method used for files. * @param fileSortMethod The sorting method used for files.
*/ */
SearchCompleteEvent(Map<GroupKey, Integer> groupMap, List<FileSearchFiltering.FileFilter> searchfilters, SearchCompleteEvent(Map<GroupKey, Integer> groupMap, List<AbstractFilter> searchfilters,
FileSearch.AttributeType groupingAttribute, FileGroup.GroupSortingAlgorithm groupSort, FileSearch.AttributeType groupingAttribute, FileGroup.GroupSortingAlgorithm groupSort,
FileSorter.SortingMethod fileSortMethod) { FileSorter.SortingMethod fileSortMethod) {
this.groupMap = groupMap; this.groupMap = groupMap;
@ -156,7 +156,7 @@ final class DiscoveryEventUtils {
* *
* @return The search filters which were used by the search. * @return The search filters which were used by the search.
*/ */
List<FileSearchFiltering.FileFilter> getFilters() { List<AbstractFilter> getFilters() {
return Collections.unmodifiableList(searchFilters); return Collections.unmodifiableList(searchFilters);
} }
@ -275,7 +275,7 @@ final class DiscoveryEventUtils {
private final FileType resultType; private final FileType resultType;
private final GroupKey groupKey; private final GroupKey groupKey;
private final int groupSize; private final int groupSize;
private final List<FileSearchFiltering.FileFilter> searchfilters; private final List<AbstractFilter> searchfilters;
private final FileSearch.AttributeType groupingAttribute; private final FileSearch.AttributeType groupingAttribute;
private final FileGroup.GroupSortingAlgorithm groupSort; private final FileGroup.GroupSortingAlgorithm groupSort;
private final FileSorter.SortingMethod fileSortMethod; private final FileSorter.SortingMethod fileSortMethod;
@ -294,7 +294,7 @@ final class DiscoveryEventUtils {
* selected. * selected.
* @param resultType The type of files which exist in the group. * @param resultType The type of files which exist in the group.
*/ */
GroupSelectedEvent(List<FileSearchFiltering.FileFilter> searchfilters, GroupSelectedEvent(List<AbstractFilter> searchfilters,
FileSearch.AttributeType groupingAttribute, FileGroup.GroupSortingAlgorithm groupSort, FileSearch.AttributeType groupingAttribute, FileGroup.GroupSortingAlgorithm groupSort,
FileSorter.SortingMethod fileSortMethod, GroupKey groupKey, int groupSize, FileType resultType) { FileSorter.SortingMethod fileSortMethod, GroupKey groupKey, int groupSize, FileType resultType) {
this.searchfilters = searchfilters; this.searchfilters = searchfilters;
@ -358,7 +358,7 @@ final class DiscoveryEventUtils {
* *
* @return The search filters which were used by the search. * @return The search filters which were used by the search.
*/ */
List<FileSearchFiltering.FileFilter> getFilters() { List<AbstractFilter> getFilters() {
return Collections.unmodifiableList(searchfilters); return Collections.unmodifiableList(searchfilters);
} }

View File

@ -36,7 +36,6 @@ import org.openide.windows.RetainLocation;
import org.openide.windows.TopComponent; import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined;
import org.sleuthkit.autopsy.discovery.FileSearchFiltering.FileFilter;
/** /**
* Create a dialog for displaying the Discovery results. * Create a dialog for displaying the Discovery results.
@ -299,7 +298,7 @@ public final class DiscoveryTopComponent extends TopComponent {
void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) { void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) {
newSearchButton.setText(Bundle.DiscoveryTopComponent_newSearch_text()); newSearchButton.setText(Bundle.DiscoveryTopComponent_newSearch_text());
progressMessageTextArea.setForeground(Color.black); progressMessageTextArea.setForeground(Color.black);
progressMessageTextArea.setText(Bundle.DiscoveryTopComponent_searchComplete_text(searchCompleteEvent.getFilters().stream().map(FileFilter::getDesc).collect(Collectors.joining("; ")))); progressMessageTextArea.setText(Bundle.DiscoveryTopComponent_searchComplete_text(searchCompleteEvent.getFilters().stream().map(AbstractFilter::getDesc).collect(Collectors.joining("; "))));
progressMessageTextArea.setCaretPosition(0); progressMessageTextArea.setCaretPosition(0);
} }

View File

@ -98,4 +98,9 @@ final class DocumentFilterPanel extends AbstractFiltersPanel {
private javax.swing.JSplitPane documentsFiltersSplitPane; private javax.swing.JSplitPane documentsFiltersSplitPane;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@Override
SearchData.ResultType getResultType() {
return SearchData.ResultType.FILE;
}
} }

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View File

@ -0,0 +1,58 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.sleuthkit.autopsy.discovery;
/**
*
* @author wschaefer
*/
public class DomainFilterPanel extends AbstractFiltersPanel {
private static final long serialVersionUID = 1L;
private static final ArtifactSearchData.ArtifactType ARTIFACT_TYPE = ArtifactSearchData.ArtifactType.DOMAIN;
/**
* Creates new form DomainFilterPanel
*/
public DomainFilterPanel() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
FileSearchData.FileType getFileType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
SearchData.ResultType getResultType() {
return SearchData.ResultType.ARTIFACT;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@ -122,7 +122,7 @@ class FileSearch {
* @throws FileSearchException * @throws FileSearchException
*/ */
static SearchResults runFileSearchDebug(String userName, static SearchResults runFileSearchDebug(String userName,
List<FileSearchFiltering.FileFilter> filters, List<AbstractFilter> filters,
AttributeType groupAttributeType, AttributeType groupAttributeType,
FileGroup.GroupSortingAlgorithm groupSortingType, FileGroup.GroupSortingAlgorithm groupSortingType,
FileSorter.SortingMethod fileSortingMethod, FileSorter.SortingMethod fileSortingMethod,
@ -136,7 +136,7 @@ class FileSearch {
attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes()); attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes());
// Run the queries for each filter // Run the queries for each filter
List<ResultFile> resultFiles = FileSearchFiltering.runQueries(filters, caseDb, centralRepoDb); List<ResultFile> resultFiles = SearchFiltering.runQueries(filters, caseDb, centralRepoDb);
// Add the data to resultFiles for any attributes needed for sorting and grouping // Add the data to resultFiles for any attributes needed for sorting and grouping
addAttributes(attributesNeededForGroupingOrSorting, resultFiles, caseDb, centralRepoDb); addAttributes(attributesNeededForGroupingOrSorting, resultFiles, caseDb, centralRepoDb);
@ -174,7 +174,7 @@ class FileSearch {
* @throws FileSearchException * @throws FileSearchException
*/ */
static Map<GroupKey, Integer> getGroupSizes(String userName, static Map<GroupKey, Integer> getGroupSizes(String userName,
List<FileSearchFiltering.FileFilter> filters, List<AbstractFilter> filters,
AttributeType groupAttributeType, AttributeType groupAttributeType,
FileGroup.GroupSortingAlgorithm groupSortingType, FileGroup.GroupSortingAlgorithm groupSortingType,
FileSorter.SortingMethod fileSortingMethod, FileSorter.SortingMethod fileSortingMethod,
@ -211,7 +211,7 @@ class FileSearch {
* @throws FileSearchException * @throws FileSearchException
*/ */
static List<ResultFile> getFilesInGroup(String userName, static List<ResultFile> getFilesInGroup(String userName,
List<FileSearchFiltering.FileFilter> filters, List<AbstractFilter> filters,
AttributeType groupAttributeType, AttributeType groupAttributeType,
FileGroup.GroupSortingAlgorithm groupSortingType, FileGroup.GroupSortingAlgorithm groupSortingType,
FileSorter.SortingMethod fileSortingMethod, FileSorter.SortingMethod fileSortingMethod,
@ -483,7 +483,7 @@ class FileSearch {
* @throws FileSearchException * @throws FileSearchException
*/ */
private static Map<GroupKey, List<ResultFile>> runFileSearch(String userName, private static Map<GroupKey, List<ResultFile>> runFileSearch(String userName,
List<FileSearchFiltering.FileFilter> filters, List<AbstractFilter> filters,
AttributeType groupAttributeType, AttributeType groupAttributeType,
FileGroup.GroupSortingAlgorithm groupSortingType, FileGroup.GroupSortingAlgorithm groupSortingType,
FileSorter.SortingMethod fileSortingMethod, FileSorter.SortingMethod fileSortingMethod,
@ -498,7 +498,7 @@ class FileSearch {
attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes()); attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes());
// Run the queries for each filter // Run the queries for each filter
List<ResultFile> resultFiles = FileSearchFiltering.runQueries(filters, caseDb, centralRepoDb); List<ResultFile> resultFiles = SearchFiltering.runQueries(filters, caseDb, centralRepoDb);
// Add the data to resultFiles for any attributes needed for sorting and grouping // Add the data to resultFiles for any attributes needed for sorting and grouping
addAttributes(attributesNeededForGroupingOrSorting, resultFiles, caseDb, centralRepoDb); addAttributes(attributesNeededForGroupingOrSorting, resultFiles, caseDb, centralRepoDb);
@ -2077,13 +2077,13 @@ class FileSearch {
* @param groupSortingType The algorithm to sort the groups by. * @param groupSortingType The algorithm to sort the groups by.
* @param fileSortingMethod The method to sort the files by. * @param fileSortingMethod The method to sort the files by.
*/ */
SearchKey(String userName, List<FileSearchFiltering.FileFilter> filters, SearchKey(String userName, List<AbstractFilter> filters,
AttributeType groupAttributeType, AttributeType groupAttributeType,
FileGroup.GroupSortingAlgorithm groupSortingType, FileGroup.GroupSortingAlgorithm groupSortingType,
FileSorter.SortingMethod fileSortingMethod) { FileSorter.SortingMethod fileSortingMethod) {
StringBuilder searchStringBuilder = new StringBuilder(); StringBuilder searchStringBuilder = new StringBuilder();
searchStringBuilder.append(userName); searchStringBuilder.append(userName);
for (FileSearchFiltering.FileFilter filter : filters) { for (AbstractFilter filter : filters) {
searchStringBuilder.append(filter.toString()); searchStringBuilder.append(filter.toString());
} }
searchStringBuilder.append(groupAttributeType).append(groupSortingType).append(fileSortingMethod); searchStringBuilder.append(groupAttributeType).append(groupSortingType).append(fileSortingMethod);

View File

@ -28,12 +28,17 @@ import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.FileTypeUtils; import org.sleuthkit.autopsy.coreutils.FileTypeUtils;
/** /**
* Utility enums for FileSearch. * Utility enums for searches made for files with Discovery.
*/ */
final class FileSearchData { final class FileSearchData extends SearchData {
private final static long BYTES_PER_MB = 1000000; private final static long BYTES_PER_MB = 1000000;
@Override
ResultType getResultType() {
return ResultType.FILE;
}
/** /**
* Enum representing how often the file occurs in the Central Repository. * Enum representing how often the file occurs in the Central Repository.
*/ */
@ -384,14 +389,6 @@ final class FileSearchData {
return OTHER; return OTHER;
} }
/**
* Get the list of enums that are valid for filtering.
*
* @return enums that can be used to filter
*/
static List<FileType> getOptionsForFiltering() {
return Arrays.asList(IMAGE, VIDEO);
}
} }
/** /**

View File

@ -39,7 +39,7 @@ final class GroupListPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private FileType resultType = null; private FileType resultType = null;
private Map<GroupKey, Integer> groupMap = null; private Map<GroupKey, Integer> groupMap = null;
private List<FileSearchFiltering.FileFilter> searchfilters; private List<AbstractFilter> searchfilters;
private FileSearch.AttributeType groupingAttribute; private FileSearch.AttributeType groupingAttribute;
private FileGroup.GroupSortingAlgorithm groupSort; private FileGroup.GroupSortingAlgorithm groupSort;
private FileSorter.SortingMethod fileSortMethod; private FileSorter.SortingMethod fileSortMethod;

View File

@ -161,9 +161,9 @@ final class HashSetFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (hashSetCheckbox.isSelected()) { if (hashSetCheckbox.isSelected()) {
return new FileSearchFiltering.HashSetFilter(hashSetList.getSelectedValuesList()); return new SearchFiltering.HashSetFilter(hashSetList.getSelectedValuesList());
} }
return null; return null;
} }

View File

@ -103,4 +103,9 @@ final class ImageFilterPanel extends AbstractFiltersPanel {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JSplitPane imageFiltersSplitPane; private javax.swing.JSplitPane imageFiltersSplitPane;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@Override
SearchData.ResultType getResultType() {
return SearchData.ResultType.FILE;
}
} }

View File

@ -163,9 +163,9 @@ final class InterestingItemsFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (interestingItemsCheckbox.isSelected()) { if (interestingItemsCheckbox.isSelected()) {
return new FileSearchFiltering.InterestingFileSetFilter(interestingItemsList.getSelectedValuesList()); return new SearchFiltering.InterestingFileSetFilter(interestingItemsList.getSelectedValuesList());
} }
return null; return null;
} }

View File

@ -167,9 +167,9 @@ final class ObjectDetectedFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (objectsCheckbox.isSelected()) { if (objectsCheckbox.isSelected()) {
return new FileSearchFiltering.ObjectDetectionFilter(objectsList.getSelectedValuesList()); return new SearchFiltering.ObjectDetectionFilter(objectsList.getSelectedValuesList());
} }
return null; return null;
} }

View File

@ -34,7 +34,7 @@ final class PageWorker extends SwingWorker<Void, Void> {
private final static Logger logger = Logger.getLogger(PageWorker.class.getName()); private final static Logger logger = Logger.getLogger(PageWorker.class.getName());
private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS
private final List<FileSearchFiltering.FileFilter> searchfilters; private final List<AbstractFilter> searchfilters;
private final FileSearch.AttributeType groupingAttribute; private final FileSearch.AttributeType groupingAttribute;
private final FileGroup.GroupSortingAlgorithm groupSort; private final FileGroup.GroupSortingAlgorithm groupSort;
private final FileSorter.SortingMethod fileSortMethod; private final FileSorter.SortingMethod fileSortMethod;
@ -61,7 +61,7 @@ final class PageWorker extends SwingWorker<Void, Void> {
* @param resultType The type of files which exist in the group. * @param resultType The type of files which exist in the group.
* @param centralRepo The central repository to be used. * @param centralRepo The central repository to be used.
*/ */
PageWorker(List<FileSearchFiltering.FileFilter> searchfilters, FileSearch.AttributeType groupingAttribute, PageWorker(List<AbstractFilter> searchfilters, FileSearch.AttributeType groupingAttribute,
FileGroup.GroupSortingAlgorithm groupSort, FileSorter.SortingMethod fileSortMethod, GroupKey groupKey, FileGroup.GroupSortingAlgorithm groupSort, FileSorter.SortingMethod fileSortMethod, GroupKey groupKey,
int startingEntry, int pageSize, FileSearchData.FileType resultType, CentralRepository centralRepo) { int startingEntry, int pageSize, FileSearchData.FileType resultType, CentralRepository centralRepo) {
this.searchfilters = searchfilters; this.searchfilters = searchfilters;

View File

@ -24,7 +24,7 @@ import javax.swing.DefaultListModel;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import org.sleuthkit.autopsy.discovery.FileSearchFiltering.ParentSearchTerm; import org.sleuthkit.autopsy.discovery.SearchFiltering.ParentSearchTerm;
/** /**
* Panel to allow configuration of the Parent Folder filter. * Panel to allow configuration of the Parent Folder filter.
@ -32,7 +32,7 @@ import org.sleuthkit.autopsy.discovery.FileSearchFiltering.ParentSearchTerm;
final class ParentFolderFilterPanel extends AbstractDiscoveryFilterPanel { final class ParentFolderFilterPanel extends AbstractDiscoveryFilterPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private DefaultListModel<FileSearchFiltering.ParentSearchTerm> parentListModel; private DefaultListModel<SearchFiltering.ParentSearchTerm> parentListModel;
private static final String[] DEFAULT_IGNORED_PATHS = {"/Windows/", "/Program Files/"}; //NON-NLS private static final String[] DEFAULT_IGNORED_PATHS = {"/Windows/", "/Program Files/"}; //NON-NLS
/** /**
@ -49,7 +49,7 @@ final class ParentFolderFilterPanel extends AbstractDiscoveryFilterPanel {
private void setUpParentPathFilter() { private void setUpParentPathFilter() {
fullRadioButton.setSelected(true); fullRadioButton.setSelected(true);
includeRadioButton.setSelected(true); includeRadioButton.setSelected(true);
parentListModel = (DefaultListModel<FileSearchFiltering.ParentSearchTerm>) parentList.getModel(); parentListModel = (DefaultListModel<SearchFiltering.ParentSearchTerm>) parentList.getModel();
for (String ignorePath : DEFAULT_IGNORED_PATHS) { for (String ignorePath : DEFAULT_IGNORED_PATHS) {
parentListModel.add(parentListModel.size(), new ParentSearchTerm(ignorePath, false, false)); parentListModel.add(parentListModel.size(), new ParentSearchTerm(ignorePath, false, false));
} }
@ -291,8 +291,8 @@ final class ParentFolderFilterPanel extends AbstractDiscoveryFilterPanel {
* *
* @return The list of entered ParentSearchTerm objects * @return The list of entered ParentSearchTerm objects
*/ */
private List<FileSearchFiltering.ParentSearchTerm> getParentPaths() { private List<SearchFiltering.ParentSearchTerm> getParentPaths() {
List<FileSearchFiltering.ParentSearchTerm> results = new ArrayList<>(); List<SearchFiltering.ParentSearchTerm> results = new ArrayList<>();
for (int i = 0; i < parentListModel.getSize(); i++) { for (int i = 0; i < parentListModel.getSize(); i++) {
results.add(parentListModel.get(i)); results.add(parentListModel.get(i));
} }
@ -305,9 +305,9 @@ final class ParentFolderFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (parentCheckbox.isSelected()) { if (parentCheckbox.isSelected()) {
return new FileSearchFiltering.ParentFilter(getParentPaths()); return new SearchFiltering.ParentFilter(getParentPaths());
} }
return null; return null;
} }

View File

@ -154,9 +154,9 @@ final class PastOccurrencesFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (pastOccurrencesCheckbox.isSelected()) { if (pastOccurrencesCheckbox.isSelected()) {
return new FileSearchFiltering.FrequencyFilter(crFrequencyList.getSelectedValuesList()); return new SearchFiltering.FrequencyFilter(crFrequencyList.getSelectedValuesList());
} }
return null; return null;
} }

View File

@ -51,7 +51,7 @@ final class ResultsPanel extends javax.swing.JPanel {
private final VideoThumbnailViewer videoThumbnailViewer; private final VideoThumbnailViewer videoThumbnailViewer;
private final ImageThumbnailViewer imageThumbnailViewer; private final ImageThumbnailViewer imageThumbnailViewer;
private final DocumentPreviewViewer documentPreviewViewer; private final DocumentPreviewViewer documentPreviewViewer;
private List<FileSearchFiltering.FileFilter> searchFilters; private List<AbstractFilter> searchFilters;
private FileSearch.AttributeType groupingAttribute; private FileSearch.AttributeType groupingAttribute;
private FileGroup.GroupSortingAlgorithm groupSort; private FileGroup.GroupSortingAlgorithm groupSort;
private FileSorter.SortingMethod fileSortMethod; private FileSorter.SortingMethod fileSortMethod;

View File

@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.sleuthkit.autopsy.discovery;
abstract class SearchData {
enum ResultType {
FILE,
ARTIFACT;
}
abstract ResultType getResultType();
}

View File

@ -42,7 +42,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
/** /**
* Run various filters to return a subset of files from the current case. * Run various filters to return a subset of files from the current case.
*/ */
class FileSearchFiltering { class SearchFiltering {
/** /**
* Run the given filters to get a list of matching files. * Run the given filters to get a list of matching files.
@ -54,13 +54,13 @@ class FileSearchFiltering {
* *
* @return * @return
*/ */
static List<ResultFile> runQueries(List<FileFilter> filters, SleuthkitCase caseDb, CentralRepository centralRepoDb) throws FileSearchException { static List<ResultFile> runQueries(List<AbstractFilter> filters, SleuthkitCase caseDb, CentralRepository centralRepoDb) throws FileSearchException {
if (caseDb == null) { if (caseDb == null) {
throw new FileSearchException("Case DB parameter is null"); // NON-NLS throw new FileSearchException("Case DB parameter is null"); // NON-NLS
} }
// Combine all the SQL queries from the filters into one query // Combine all the SQL queries from the filters into one query
String combinedQuery = ""; String combinedQuery = "";
for (FileFilter filter : filters) { for (AbstractFilter filter : filters) {
if (!filter.getWhereClause().isEmpty()) { if (!filter.getWhereClause().isEmpty()) {
if (!combinedQuery.isEmpty()) { if (!combinedQuery.isEmpty()) {
combinedQuery += " AND "; // NON-NLS combinedQuery += " AND "; // NON-NLS
@ -94,7 +94,7 @@ class FileSearchFiltering {
* @throws TskCoreException * @throws TskCoreException
* @throws FileSearchException * @throws FileSearchException
*/ */
private static List<ResultFile> getResultList(List<FileFilter> filters, String combinedQuery, SleuthkitCase caseDb, CentralRepository centralRepoDb) throws TskCoreException, FileSearchException { private static List<ResultFile> getResultList(List<AbstractFilter> filters, String combinedQuery, SleuthkitCase caseDb, CentralRepository centralRepoDb) throws TskCoreException, FileSearchException {
// Get all matching abstract files // Get all matching abstract files
List<ResultFile> resultList = new ArrayList<>(); List<ResultFile> resultList = new ArrayList<>();
List<AbstractFile> sqlResults = caseDb.findAllFilesWhere(combinedQuery); List<AbstractFile> sqlResults = caseDb.findAllFilesWhere(combinedQuery);
@ -110,7 +110,7 @@ class FileSearchFiltering {
} }
// Now run any non-SQL filters. // Now run any non-SQL filters.
for (FileFilter filter : filters) { for (AbstractFilter filter : filters) {
if (filter.useAlternateFilter()) { if (filter.useAlternateFilter()) {
resultList = filter.applyAlternateFilter(resultList, caseDb, centralRepoDb); resultList = filter.applyAlternateFilter(resultList, caseDb, centralRepoDb);
} }
@ -122,61 +122,10 @@ class FileSearchFiltering {
return resultList; return resultList;
} }
/**
* Base class for the filters.
*/
static abstract class FileFilter {
/**
* Returns part of a query on the tsk_files table that can be AND-ed
* with other pieces
*
* @return the SQL query or an empty string if there is no SQL query for
* this filter.
*/
abstract String getWhereClause();
/**
* Indicates whether this filter needs to use the secondary, non-SQL
* method applyAlternateFilter().
*
* @return false by default
*/
boolean useAlternateFilter() {
return false;
}
/**
* Run a secondary filter that does not operate on tsk_files.
*
* @param currentResults The current list of matching files; empty if no
* filters have yet been run.
* @param caseDb The case database
* @param centralRepoDb The central repo database. Can be null if the
* filter does not require it.
*
* @return The list of files that match this filter (and any that came
* before it)
*
* @throws FileSearchException
*/
List<ResultFile> applyAlternateFilter(List<ResultFile> currentResults, SleuthkitCase caseDb,
CentralRepository centralRepoDb) throws FileSearchException {
return new ArrayList<>();
}
/**
* Get a description of the selected filter.
*
* @return A description of the filter
*/
abstract String getDesc();
}
/** /**
* A filter for specifying the file size * A filter for specifying the file size
*/ */
static class SizeFilter extends FileFilter { static class SizeFilter extends AbstractFilter {
private final List<FileSize> fileSizes; private final List<FileSize> fileSizes;
@ -316,7 +265,7 @@ class FileSearchFiltering {
/** /**
* A filter for specifying parent path (either full path or substring) * A filter for specifying parent path (either full path or substring)
*/ */
static class ParentFilter extends FileFilter { static class ParentFilter extends AbstractFilter {
private final List<ParentSearchTerm> parentSearchTerms; private final List<ParentSearchTerm> parentSearchTerms;
@ -393,7 +342,7 @@ class FileSearchFiltering {
/** /**
* A filter for specifying data sources * A filter for specifying data sources
*/ */
static class DataSourceFilter extends FileFilter { static class DataSourceFilter extends AbstractFilter {
private final List<DataSource> dataSources; private final List<DataSource> dataSources;
@ -444,7 +393,7 @@ class FileSearchFiltering {
* A filter for specifying keyword list names. A file must contain a keyword * A filter for specifying keyword list names. A file must contain a keyword
* from one of the given lists to pass. * from one of the given lists to pass.
*/ */
static class KeywordListFilter extends FileFilter { static class KeywordListFilter extends AbstractFilter {
private final List<String> listNames; private final List<String> listNames;
@ -480,7 +429,7 @@ class FileSearchFiltering {
/** /**
* A filter for specifying file types. * A filter for specifying file types.
*/ */
static class FileTypeFilter extends FileFilter { static class FileTypeFilter extends AbstractFilter {
private final List<FileType> categories; private final List<FileType> categories;
@ -539,7 +488,7 @@ class FileSearchFiltering {
/** /**
* A filter for specifying frequency in the central repository. * A filter for specifying frequency in the central repository.
*/ */
static class FrequencyFilter extends FileFilter { static class FrequencyFilter extends AbstractFilter {
private final List<Frequency> frequencies; private final List<Frequency> frequencies;
@ -609,7 +558,7 @@ class FileSearchFiltering {
* A filter for specifying hash set names. A file must match one of the * A filter for specifying hash set names. A file must match one of the
* given sets to pass. * given sets to pass.
*/ */
static class HashSetFilter extends FileFilter { static class HashSetFilter extends AbstractFilter {
private final List<String> setNames; private final List<String> setNames;
@ -647,7 +596,7 @@ class FileSearchFiltering {
* A filter for specifying interesting file set names. A file must match one * A filter for specifying interesting file set names. A file must match one
* of the given sets to pass. * of the given sets to pass.
*/ */
static class InterestingFileSetFilter extends FileFilter { static class InterestingFileSetFilter extends AbstractFilter {
private final List<String> setNames; private final List<String> setNames;
@ -685,7 +634,7 @@ class FileSearchFiltering {
* A filter for specifying object types detected. A file must match one of * A filter for specifying object types detected. A file must match one of
* the given types to pass. * the given types to pass.
*/ */
static class ObjectDetectionFilter extends FileFilter { static class ObjectDetectionFilter extends AbstractFilter {
private final List<String> typeNames; private final List<String> typeNames;
@ -723,7 +672,7 @@ class FileSearchFiltering {
* A filter for specifying the score. A file must have one of the given * A filter for specifying the score. A file must have one of the given
* scores to pass * scores to pass
*/ */
static class ScoreFilter extends FileFilter { static class ScoreFilter extends AbstractFilter {
private final List<Score> scores; private final List<Score> scores;
@ -800,7 +749,7 @@ class FileSearchFiltering {
* A filter for specifying tag names. A file must contain one of the given * A filter for specifying tag names. A file must contain one of the given
* tags to pass. * tags to pass.
*/ */
static class TagsFilter extends FileFilter { static class TagsFilter extends AbstractFilter {
private final List<TagName> tagNames; private final List<TagName> tagNames;
@ -849,7 +798,7 @@ class FileSearchFiltering {
* A filter for specifying that the file must have user content suspected * A filter for specifying that the file must have user content suspected
* data. * data.
*/ */
static class UserCreatedFilter extends FileFilter { static class UserCreatedFilter extends AbstractFilter {
/** /**
* Create the ExifFilter * Create the ExifFilter
@ -877,7 +826,7 @@ class FileSearchFiltering {
* A filter for specifying that the file must have been marked as notable in * A filter for specifying that the file must have been marked as notable in
* the CR. * the CR.
*/ */
static class NotableFilter extends FileFilter { static class NotableFilter extends AbstractFilter {
/** /**
* Create the NotableFilter * Create the NotableFilter
@ -945,7 +894,7 @@ class FileSearchFiltering {
/** /**
* A filter for specifying if known files should be included. * A filter for specifying if known files should be included.
*/ */
static class KnownFilter extends FileFilter { static class KnownFilter extends AbstractFilter {
@Override @Override
String getWhereClause() { String getWhereClause() {
@ -992,7 +941,7 @@ class FileSearchFiltering {
return result; return result;
} }
private FileSearchFiltering() { private SearchFiltering(){
// Class should not be instantiated // Class should not be instantiated
} }
} }

View File

@ -35,7 +35,7 @@ final class SearchWorker extends SwingWorker<Void, Void> {
private final static Logger logger = Logger.getLogger(SearchWorker.class.getName()); private final static Logger logger = Logger.getLogger(SearchWorker.class.getName());
private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS
private final List<FileSearchFiltering.FileFilter> filters; private final List<AbstractFilter> filters;
private final FileSearch.AttributeType groupingAttr; private final FileSearch.AttributeType groupingAttr;
private final FileSorter.SortingMethod fileSort; private final FileSorter.SortingMethod fileSort;
private final FileGroup.GroupSortingAlgorithm groupSortAlgorithm; private final FileGroup.GroupSortingAlgorithm groupSortAlgorithm;
@ -52,7 +52,7 @@ final class SearchWorker extends SwingWorker<Void, Void> {
* @param groupSort The Algorithm to sort groups by. * @param groupSort The Algorithm to sort groups by.
* @param fileSortMethod The SortingMethod to use for files. * @param fileSortMethod The SortingMethod to use for files.
*/ */
SearchWorker(CentralRepository centralRepo, List<FileSearchFiltering.FileFilter> searchfilters, FileSearch.AttributeType groupingAttribute, FileGroup.GroupSortingAlgorithm groupSort, FileSorter.SortingMethod fileSortMethod) { SearchWorker(CentralRepository centralRepo, List<AbstractFilter> searchfilters, FileSearch.AttributeType groupingAttribute, FileGroup.GroupSortingAlgorithm groupSort, FileSorter.SortingMethod fileSortMethod) {
centralRepoDb = centralRepo; centralRepoDb = centralRepo;
filters = searchfilters; filters = searchfilters;
groupingAttr = groupingAttribute; groupingAttr = groupingAttribute;

View File

@ -178,9 +178,9 @@ final class SizeFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (sizeCheckbox.isSelected()) { if (sizeCheckbox.isSelected()) {
return new FileSearchFiltering.SizeFilter(sizeList.getSelectedValuesList()); return new SearchFiltering.SizeFilter(sizeList.getSelectedValuesList());
} }
return null; return null;
} }

View File

@ -98,9 +98,9 @@ final class UserCreatedFilterPanel extends AbstractDiscoveryFilterPanel {
} }
@Override @Override
FileSearchFiltering.FileFilter getFilter() { AbstractFilter getFilter() {
if (userCreatedCheckbox.isSelected()) { if (userCreatedCheckbox.isSelected()) {
return new FileSearchFiltering.UserCreatedFilter(); return new SearchFiltering.UserCreatedFilter();
} }
return null; return null;
} }

View File

@ -105,4 +105,9 @@ final class VideoFilterPanel extends AbstractFiltersPanel {
private javax.swing.JSplitPane videoFiltersSplitPane; private javax.swing.JSplitPane videoFiltersSplitPane;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@Override
SearchData.ResultType getResultType() {
return SearchData.ResultType.FILE;
}
} }