From dee30d6099ebb262bc6bf7dfb1078cac26e3a9a8 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 13 Oct 2021 16:12:38 -0400 Subject: [PATCH 1/4] First cut --- .../mainui/datamodel/Bundle.properties-MERGED | 1 + .../datamodel/FileTypeMimeSearchParam.java | 92 +++++++++++++++++++ .../autopsy/mainui/datamodel/ViewsDAO.java | 55 +++++++++-- 3 files changed, 142 insertions(+), 6 deletions(-) create mode 100755 Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/Bundle.properties-MERGED index 2a45b536bd..192d522fe0 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/Bundle.properties-MERGED @@ -16,6 +16,7 @@ FileExtRootFilter_documents_displayName=Documents FileExtRootFilter_executable_displayName=Executable FileExtRootFilter_image_displayName=Images FileExtRootFilter_video_displayName=Video +FileTypesByMimeType.name.text=By MIME Type ThreePanelDataArtifactDAO.dataArtifact.columnKeys.comment.description=Comment ThreePanelDataArtifactDAO.dataArtifact.columnKeys.comment.displayName=C ThreePanelDataArtifactDAO.dataArtifact.columnKeys.comment.name=Comment diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java new file mode 100755 index 0000000000..6ef8881984 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java @@ -0,0 +1,92 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 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.mainui.datamodel; + +import java.util.Objects; + +/** + * Key for accessing data about file MIME type from the DAO. + */ +public class FileTypeMimeSearchParam extends BaseSearchParam { + + private final String mimeType; + private final Long dataSourceId; + private final boolean knownShown; + + // TODO: This should ideally take in some kind of ENUM once we redo the tree. + // this assumes that filters implicitly or explicitly implement hashCode and equals to work + public FileTypeMimeSearchParam(String mimeType, Long dataSourceId, boolean showKnown) { + this.mimeType = mimeType; + this.dataSourceId = dataSourceId; + this.knownShown = showKnown; + } + + public FileTypeMimeSearchParam(String mimeType, Long dataSourceId, boolean knownShown, long startItem, Long maxResultsCount) { + super(startItem, maxResultsCount); + this.mimeType = mimeType; + this.dataSourceId = dataSourceId; + this.knownShown = knownShown; + } + + public String getFilter() { + return mimeType; + } + + public Long getDataSourceId() { + return dataSourceId; + } + + public boolean isKnownShown() { + return knownShown; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 23 * hash + Objects.hashCode(this.mimeType); + hash = 23 * hash + Objects.hashCode(this.dataSourceId); + hash = 23 * hash + (this.knownShown ? 1 : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final FileTypeMimeSearchParam other = (FileTypeMimeSearchParam) obj; + if (this.knownShown != other.knownShown) { + return false; + } + if (!(this.mimeType.equals(other.mimeType))) { + return false; + } + if (!Objects.equals(this.dataSourceId, other.dataSourceId)) { + return false; + } + return true; + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java index 6feea44708..727529e15c 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java @@ -28,9 +28,11 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; +import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import static org.sleuthkit.autopsy.core.UserPreferences.hideSlackFilesInViewsTree; import org.sleuthkit.autopsy.coreutils.TimeZoneUtils; import org.sleuthkit.autopsy.datamodel.FileTypeExtensions; import org.sleuthkit.autopsy.mainui.datamodel.FileRowDTO.ExtensionMediaType; @@ -151,6 +153,7 @@ public class ViewsDAO { } private final Cache fileTypeByExtensionCache = CacheBuilder.newBuilder().maximumSize(1000).build(); + private final Cache fileTypeByMimeCache = CacheBuilder.newBuilder().maximumSize(1000).build(); public SearchResultsDTO getFilesByExtension(FileTypeExtensionsSearchParam key) throws ExecutionException, IllegalArgumentException { if (key.getFilter() == null) { @@ -159,8 +162,19 @@ public class ViewsDAO { throw new IllegalArgumentException("Data source id must be greater than 0 or null"); } - return fileTypeByExtensionCache.get(key, () -> fetchFileViewFiles(key.getFilter(), key.getDataSourceId(), key.isKnownShown())); + return fileTypeByExtensionCache.get(key, () -> fetchExtensionSearchResultsDTOs(key.getFilter(), key.getDataSourceId(), key.isKnownShown())); } + + public SearchResultsDTO getFilesByMime(FileTypeMimeSearchParam key) throws ExecutionException, IllegalArgumentException { + if (key.getFilter() == null) { + throw new IllegalArgumentException("Must have non-null filter"); + } else if (key.getDataSourceId() != null && key.getDataSourceId() <= 0) { + throw new IllegalArgumentException("Data source id must be greater than 0 or null"); + } + + return fileTypeByMimeCache.get(key, () -> fetchMimeSearchResultsDTOs(key.getFilter(), key.getDataSourceId(), key.isKnownShown())); + } + // private ViewFileTableSearchResultsDTO fetchFilesForTable(ViewFileCacheKey cacheKey) throws NoCurrentCaseException, TskCoreException { // @@ -179,7 +193,7 @@ public class ViewsDAO { private Map fetchFileViewCounts(List filters, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { Map counts = new HashMap<>(); for (FileExtSearchFilter filter : filters) { - String whereClause = getFileWhereStatement(filter, dataSourceId, showKnown); + String whereClause = getFileExtensionWhereStatement(filter, dataSourceId, showKnown); long count = getCase().countFilesWhere(whereClause); counts.put(filter.getId(), count); } @@ -187,7 +201,7 @@ public class ViewsDAO { return counts; } - private String getFileWhereStatement(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) { + private String getFileExtensionWhereStatement(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) { String whereClause = "(dir_type = " + TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue() + ")" + (showKnown ? " " @@ -201,9 +215,38 @@ public class ViewsDAO { .collect(Collectors.joining(", ")) + "))"; return whereClause; } + + private String getFileMimeWhereStatement(String mimeType, Long dataSourceId, boolean showKnown) { - private SearchResultsDTO fetchFileViewFiles(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { - String whereStatement = getFileWhereStatement(filter, dataSourceId, showKnown); + String whereClause = "(dir_type = " + TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue() + ")" + + " AND (type IN (" + + TskData.TSK_DB_FILES_TYPE_ENUM.FS.ordinal() + "," + + TskData.TSK_DB_FILES_TYPE_ENUM.CARVED.ordinal() + "," + + TskData.TSK_DB_FILES_TYPE_ENUM.DERIVED.ordinal() + "," + + TskData.TSK_DB_FILES_TYPE_ENUM.LAYOUT_FILE.ordinal() + "," + + TskData.TSK_DB_FILES_TYPE_ENUM.LOCAL.ordinal() + + (hideSlackFilesInViewsTree() ? "" : ("," + TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.ordinal())) + + "))" + + ((dataSourceId > 0) ? " AND data_source_obj_id = " + dataSourceId : " ") + + (showKnown ? (" AND (known IS NULL OR known != " + TskData.FileKnown.KNOWN.getFileKnownValue() + ")") : "") + + " AND mime_type = '" + mimeType + "'"; + + return whereClause; + } + + private SearchResultsDTO fetchExtensionSearchResultsDTOs(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { + String whereStatement = getFileExtensionWhereStatement(filter, dataSourceId, showKnown); + return fetchFileViewFiles(whereStatement, filter.getDisplayName()); + } + + @NbBundle.Messages({"FileTypesByMimeType.name.text=By MIME Type"}) + private SearchResultsDTO fetchMimeSearchResultsDTOs(String mimeType, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { + String whereStatement = getFileMimeWhereStatement(mimeType, dataSourceId, showKnown); + final String MIME_TYPE_DISPLAY_NAME = Bundle.FileTypesByMimeType_name_text(); + return fetchFileViewFiles(whereStatement, MIME_TYPE_DISPLAY_NAME); + } + + private SearchResultsDTO fetchFileViewFiles(String whereStatement, String displayName) throws NoCurrentCaseException, TskCoreException { List files = getCase().findAllFilesWhere(whereStatement); List fileRows = new ArrayList<>(); @@ -259,7 +302,7 @@ public class ViewsDAO { cellValues)); } - return new BaseSearchResultsDTO(FILE_VIEW_EXT_TYPE_ID, filter.getDisplayName(), FILE_COLUMNS, fileRows); + return new BaseSearchResultsDTO(FILE_VIEW_EXT_TYPE_ID, displayName, FILE_COLUMNS, fileRows); } } From f90cb55b677a9beeac4d2eb44e67cae3ac2600c8 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 13 Oct 2021 16:15:50 -0400 Subject: [PATCH 2/4] Minor --- .../autopsy/mainui/datamodel/FileTypeMimeSearchParam.java | 2 +- Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java index 6ef8881984..338094dc12 100755 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java @@ -44,7 +44,7 @@ public class FileTypeMimeSearchParam extends BaseSearchParam { this.knownShown = knownShown; } - public String getFilter() { + public String getMimeType() { return mimeType; } diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java index 727529e15c..a83e37c573 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java @@ -166,13 +166,13 @@ public class ViewsDAO { } public SearchResultsDTO getFilesByMime(FileTypeMimeSearchParam key) throws ExecutionException, IllegalArgumentException { - if (key.getFilter() == null) { + if (key.getMimeType() == null) { throw new IllegalArgumentException("Must have non-null filter"); } else if (key.getDataSourceId() != null && key.getDataSourceId() <= 0) { throw new IllegalArgumentException("Data source id must be greater than 0 or null"); } - return fileTypeByMimeCache.get(key, () -> fetchMimeSearchResultsDTOs(key.getFilter(), key.getDataSourceId(), key.isKnownShown())); + return fileTypeByMimeCache.get(key, () -> fetchMimeSearchResultsDTOs(key.getMimeType(), key.getDataSourceId(), key.isKnownShown())); } From e8f0ba93a6a9d366f06626290315149c7f72d425 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 13 Oct 2021 16:51:24 -0400 Subject: [PATCH 3/4] Code review feedback, renamed some classes --- .../DataResultTopComponent.java | 4 +-- .../datamodel/FileTypesByExtension.java | 7 ++-- .../DirectoryTreeTopComponent.java | 4 +-- ...SearchParam.java => BaseSearchParams.java} | 6 ++-- .../datamodel/DataArtifactSearchParam.java | 2 +- ...va => FileTypeExtensionsSearchParams.java} | 19 +++-------- ...ram.java => FileTypeMimeSearchParams.java} | 21 +++--------- .../{SearchParam.java => SearchParams.java} | 2 +- .../autopsy/mainui/datamodel/ViewsDAO.java | 33 ++++++++++--------- 9 files changed, 37 insertions(+), 61 deletions(-) rename Core/src/org/sleuthkit/autopsy/mainui/datamodel/{BaseSearchParam.java => BaseSearchParams.java} (88%) rename Core/src/org/sleuthkit/autopsy/mainui/datamodel/{FileTypeExtensionsSearchParam.java => FileTypeExtensionsSearchParams.java} (74%) rename Core/src/org/sleuthkit/autopsy/mainui/datamodel/{FileTypeMimeSearchParam.java => FileTypeMimeSearchParams.java} (69%) rename Core/src/org/sleuthkit/autopsy/mainui/datamodel/{SearchParam.java => SearchParams.java} (96%) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java index 4c3a10e239..ac51c6e29b 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java @@ -43,7 +43,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.mainui.datamodel.DataArtifactSearchParam; import org.sleuthkit.autopsy.mainui.nodes.DataArtifactNode; import org.sleuthkit.autopsy.mainui.nodes.FileNode; -import org.sleuthkit.autopsy.mainui.datamodel.FileTypeExtensionsSearchParam; +import org.sleuthkit.autopsy.mainui.datamodel.FileTypeExtensionsSearchParams; import org.sleuthkit.autopsy.mainui.nodes.SearchResultRootNode; import org.sleuthkit.autopsy.mainui.datamodel.MainDAO; import org.sleuthkit.autopsy.mainui.datamodel.SearchResultsDTO; @@ -386,7 +386,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe } - public void displayFileExtensions(FileTypeExtensionsSearchParam fileExtensionsKey) { + public void displayFileExtensions(FileTypeExtensionsSearchParams fileExtensionsKey) { try { displaySearchResults(threePanelDAO.getViewsDAO().getFilesByExtension(fileExtensionsKey)); } catch (ExecutionException | IllegalArgumentException ex) { diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/FileTypesByExtension.java b/Core/src/org/sleuthkit/autopsy/datamodel/FileTypesByExtension.java index fcd770b887..5a946589df 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/FileTypesByExtension.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/FileTypesByExtension.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.datamodel; -import org.sleuthkit.autopsy.mainui.datamodel.FileTypeExtensionsSearchParam; +import org.sleuthkit.autopsy.mainui.datamodel.FileTypeExtensionsSearchParams; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Arrays; @@ -350,10 +350,9 @@ public final class FileTypesByExtension implements AutopsyVisitableItem { FileExtensionNode(FileExtSearchFilter filter, SleuthkitCase skCase, FileTypesByExtObservable o) { super(typesRoot, Children.LEAF, Lookups.fixed(filter.getDisplayName(), - new FileTypeExtensionsSearchParam( + new FileTypeExtensionsSearchParams( filter, - filteringDataSourceObjId() > 0 ? filteringDataSourceObjId() : null, - !UserPreferences.hideKnownFilesInViewsTree()))); + filteringDataSourceObjId() > 0 ? filteringDataSourceObjId() : null))); this.filter = filter; super.setName(filter.getDisplayName()); diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java index 2505abd2fd..a6d095036f 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java @@ -84,7 +84,7 @@ import org.sleuthkit.autopsy.datamodel.KeywordHits; import org.sleuthkit.autopsy.datamodel.AutopsyTreeChildFactory; import org.sleuthkit.autopsy.mainui.datamodel.DataArtifactSearchParam; import org.sleuthkit.autopsy.datamodel.DataArtifacts; -import org.sleuthkit.autopsy.mainui.datamodel.FileTypeExtensionsSearchParam; +import org.sleuthkit.autopsy.mainui.datamodel.FileTypeExtensionsSearchParams; import org.sleuthkit.autopsy.datamodel.OsAccounts; import org.sleuthkit.autopsy.datamodel.PersonNode; import org.sleuthkit.autopsy.datamodel.Tags; @@ -872,7 +872,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat Node drfn = new DataResultFilterNode(originNode, DirectoryTreeTopComponent.this.em); // Create a TableFilterNode with knowledge of the node's type to allow for column order settings DataArtifactSearchParam dataArtifactKey = originNode.getLookup().lookup(DataArtifactSearchParam.class); - FileTypeExtensionsSearchParam fileExtensionsKey = originNode.getLookup().lookup(FileTypeExtensionsSearchParam.class); + FileTypeExtensionsSearchParams fileExtensionsKey = originNode.getLookup().lookup(FileTypeExtensionsSearchParams.class); if (dataArtifactKey != null) { dataResult.displayDataArtifact(dataArtifactKey); } else if (fileExtensionsKey != null) { diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/BaseSearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/BaseSearchParams.java similarity index 88% rename from Core/src/org/sleuthkit/autopsy/mainui/datamodel/BaseSearchParam.java rename to Core/src/org/sleuthkit/autopsy/mainui/datamodel/BaseSearchParams.java index 6283c1ed9a..c1913e37b5 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/BaseSearchParam.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/BaseSearchParams.java @@ -21,18 +21,18 @@ package org.sleuthkit.autopsy.mainui.datamodel; /** * Base implementation of search parameters to provide to a DAO. */ -public class BaseSearchParam implements SearchParam { +public class BaseSearchParams implements SearchParams { private final long startItem; private final Long maxResultsCount; /** * Constructor that gets all results. */ - public BaseSearchParam() { + public BaseSearchParams() { this(0, null); } - public BaseSearchParam(long startItem, Long maxResultsCount) { + public BaseSearchParams(long startItem, Long maxResultsCount) { this.startItem = startItem; this.maxResultsCount = maxResultsCount; } diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/DataArtifactSearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/DataArtifactSearchParam.java index 291cbed1ab..8157c07ca1 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/DataArtifactSearchParam.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/DataArtifactSearchParam.java @@ -24,7 +24,7 @@ import org.sleuthkit.datamodel.BlackboardArtifact; /** * Key for data artifact in order to retrieve data from DAO. */ -public class DataArtifactSearchParam extends BaseSearchParam { +public class DataArtifactSearchParam extends BaseSearchParams { private final BlackboardArtifact.Type artifactType; private final Long dataSourceId; diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeExtensionsSearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeExtensionsSearchParams.java similarity index 74% rename from Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeExtensionsSearchParam.java rename to Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeExtensionsSearchParams.java index bfb39ff0e4..f565f9c36c 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeExtensionsSearchParam.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeExtensionsSearchParams.java @@ -23,25 +23,22 @@ import java.util.Objects; /** * Key for accessing data about file type extensions from the DAO. */ -public class FileTypeExtensionsSearchParam extends BaseSearchParam { +public class FileTypeExtensionsSearchParams extends BaseSearchParams { private final FileExtSearchFilter filter; private final Long dataSourceId; - private final boolean knownShown; // TODO: This should ideally take in some kind of ENUM once we redo the tree. // this assumes that filters implicitly or explicitly implement hashCode and equals to work - public FileTypeExtensionsSearchParam(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) { + public FileTypeExtensionsSearchParams(FileExtSearchFilter filter, Long dataSourceId) { this.filter = filter; this.dataSourceId = dataSourceId; - this.knownShown = showKnown; } - public FileTypeExtensionsSearchParam(FileExtSearchFilter filter, Long dataSourceId, boolean knownShown, long startItem, Long maxResultsCount) { + public FileTypeExtensionsSearchParams(FileExtSearchFilter filter, Long dataSourceId, long startItem, Long maxResultsCount) { super(startItem, maxResultsCount); this.filter = filter; this.dataSourceId = dataSourceId; - this.knownShown = knownShown; } public FileExtSearchFilter getFilter() { @@ -52,16 +49,11 @@ public class FileTypeExtensionsSearchParam extends BaseSearchParam { return dataSourceId; } - public boolean isKnownShown() { - return knownShown; - } - @Override public int hashCode() { int hash = 7; hash = 23 * hash + Objects.hashCode(this.filter); hash = 23 * hash + Objects.hashCode(this.dataSourceId); - hash = 23 * hash + (this.knownShown ? 1 : 0); return hash; } @@ -76,10 +68,7 @@ public class FileTypeExtensionsSearchParam extends BaseSearchParam { if (getClass() != obj.getClass()) { return false; } - final FileTypeExtensionsSearchParam other = (FileTypeExtensionsSearchParam) obj; - if (this.knownShown != other.knownShown) { - return false; - } + final FileTypeExtensionsSearchParams other = (FileTypeExtensionsSearchParams) obj; if (!Objects.equals(this.filter, other.filter)) { return false; } diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java similarity index 69% rename from Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java rename to Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java index 338094dc12..cd9afdba2e 100755 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParam.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java @@ -23,25 +23,20 @@ import java.util.Objects; /** * Key for accessing data about file MIME type from the DAO. */ -public class FileTypeMimeSearchParam extends BaseSearchParam { +public class FileTypeMimeSearchParams extends BaseSearchParams { private final String mimeType; private final Long dataSourceId; - private final boolean knownShown; - // TODO: This should ideally take in some kind of ENUM once we redo the tree. - // this assumes that filters implicitly or explicitly implement hashCode and equals to work - public FileTypeMimeSearchParam(String mimeType, Long dataSourceId, boolean showKnown) { + public FileTypeMimeSearchParams(String mimeType, Long dataSourceId, boolean showKnown) { this.mimeType = mimeType; this.dataSourceId = dataSourceId; - this.knownShown = showKnown; } - public FileTypeMimeSearchParam(String mimeType, Long dataSourceId, boolean knownShown, long startItem, Long maxResultsCount) { + public FileTypeMimeSearchParams(String mimeType, Long dataSourceId, boolean knownShown, long startItem, Long maxResultsCount) { super(startItem, maxResultsCount); this.mimeType = mimeType; this.dataSourceId = dataSourceId; - this.knownShown = knownShown; } public String getMimeType() { @@ -52,16 +47,11 @@ public class FileTypeMimeSearchParam extends BaseSearchParam { return dataSourceId; } - public boolean isKnownShown() { - return knownShown; - } - @Override public int hashCode() { int hash = 7; hash = 23 * hash + Objects.hashCode(this.mimeType); hash = 23 * hash + Objects.hashCode(this.dataSourceId); - hash = 23 * hash + (this.knownShown ? 1 : 0); return hash; } @@ -76,10 +66,7 @@ public class FileTypeMimeSearchParam extends BaseSearchParam { if (getClass() != obj.getClass()) { return false; } - final FileTypeMimeSearchParam other = (FileTypeMimeSearchParam) obj; - if (this.knownShown != other.knownShown) { - return false; - } + final FileTypeMimeSearchParams other = (FileTypeMimeSearchParams) obj; if (!(this.mimeType.equals(other.mimeType))) { return false; } diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/SearchParam.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/SearchParams.java similarity index 96% rename from Core/src/org/sleuthkit/autopsy/mainui/datamodel/SearchParam.java rename to Core/src/org/sleuthkit/autopsy/mainui/datamodel/SearchParams.java index b64103554b..5d5c946546 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/SearchParam.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/SearchParams.java @@ -21,7 +21,7 @@ package org.sleuthkit.autopsy.mainui.datamodel; /** * Describes parameters to provide to the DAO for fetching data. */ -public interface SearchParam { +public interface SearchParams { long getStartItem(); diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java index a83e37c573..74b193bc51 100644 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/ViewsDAO.java @@ -32,6 +32,7 @@ import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import static org.sleuthkit.autopsy.core.UserPreferences.hideKnownFilesInViewsTree; import static org.sleuthkit.autopsy.core.UserPreferences.hideSlackFilesInViewsTree; import org.sleuthkit.autopsy.coreutils.TimeZoneUtils; import org.sleuthkit.autopsy.datamodel.FileTypeExtensions; @@ -152,27 +153,27 @@ public class ViewsDAO { return Case.getCurrentCaseThrows().getSleuthkitCase(); } - private final Cache fileTypeByExtensionCache = CacheBuilder.newBuilder().maximumSize(1000).build(); - private final Cache fileTypeByMimeCache = CacheBuilder.newBuilder().maximumSize(1000).build(); + private final Cache fileTypeByExtensionCache = CacheBuilder.newBuilder().maximumSize(1000).build(); + private final Cache fileTypeByMimeCache = CacheBuilder.newBuilder().maximumSize(1000).build(); - public SearchResultsDTO getFilesByExtension(FileTypeExtensionsSearchParam key) throws ExecutionException, IllegalArgumentException { + public SearchResultsDTO getFilesByExtension(FileTypeExtensionsSearchParams key) throws ExecutionException, IllegalArgumentException { if (key.getFilter() == null) { throw new IllegalArgumentException("Must have non-null filter"); } else if (key.getDataSourceId() != null && key.getDataSourceId() <= 0) { throw new IllegalArgumentException("Data source id must be greater than 0 or null"); } - return fileTypeByExtensionCache.get(key, () -> fetchExtensionSearchResultsDTOs(key.getFilter(), key.getDataSourceId(), key.isKnownShown())); + return fileTypeByExtensionCache.get(key, () -> fetchExtensionSearchResultsDTOs(key.getFilter(), key.getDataSourceId())); } - public SearchResultsDTO getFilesByMime(FileTypeMimeSearchParam key) throws ExecutionException, IllegalArgumentException { + public SearchResultsDTO getFilesByMime(FileTypeMimeSearchParams key) throws ExecutionException, IllegalArgumentException { if (key.getMimeType() == null) { throw new IllegalArgumentException("Must have non-null filter"); } else if (key.getDataSourceId() != null && key.getDataSourceId() <= 0) { throw new IllegalArgumentException("Data source id must be greater than 0 or null"); } - return fileTypeByMimeCache.get(key, () -> fetchMimeSearchResultsDTOs(key.getMimeType(), key.getDataSourceId(), key.isKnownShown())); + return fileTypeByMimeCache.get(key, () -> fetchMimeSearchResultsDTOs(key.getMimeType(), key.getDataSourceId())); } @@ -190,10 +191,10 @@ public class ViewsDAO { // ViewFileCacheKey cacheKey = new ViewFileCacheKey(artType, dataSourceId); // return dataArtifactCache.get(cacheKey, () -> fetchFilesForTable(cacheKey)); // } - private Map fetchFileViewCounts(List filters, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { + private Map fetchFileViewCounts(List filters, Long dataSourceId) throws NoCurrentCaseException, TskCoreException { Map counts = new HashMap<>(); for (FileExtSearchFilter filter : filters) { - String whereClause = getFileExtensionWhereStatement(filter, dataSourceId, showKnown); + String whereClause = getFileExtensionWhereStatement(filter, dataSourceId); long count = getCase().countFilesWhere(whereClause); counts.put(filter.getId(), count); } @@ -201,9 +202,9 @@ public class ViewsDAO { return counts; } - private String getFileExtensionWhereStatement(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) { + private String getFileExtensionWhereStatement(FileExtSearchFilter filter, Long dataSourceId) { String whereClause = "(dir_type = " + TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue() + ")" - + (showKnown + + (hideKnownFilesInViewsTree() ? " " : " AND (known IS NULL OR known != " + TskData.FileKnown.KNOWN.getFileKnownValue() + ")") + (dataSourceId != null && dataSourceId > 0 @@ -216,7 +217,7 @@ public class ViewsDAO { return whereClause; } - private String getFileMimeWhereStatement(String mimeType, Long dataSourceId, boolean showKnown) { + private String getFileMimeWhereStatement(String mimeType, Long dataSourceId) { String whereClause = "(dir_type = " + TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue() + ")" + " AND (type IN (" @@ -228,20 +229,20 @@ public class ViewsDAO { + (hideSlackFilesInViewsTree() ? "" : ("," + TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.ordinal())) + "))" + ((dataSourceId > 0) ? " AND data_source_obj_id = " + dataSourceId : " ") - + (showKnown ? (" AND (known IS NULL OR known != " + TskData.FileKnown.KNOWN.getFileKnownValue() + ")") : "") + + (hideKnownFilesInViewsTree() ? (" AND (known IS NULL OR known != " + TskData.FileKnown.KNOWN.getFileKnownValue() + ")") : "") + " AND mime_type = '" + mimeType + "'"; return whereClause; } - private SearchResultsDTO fetchExtensionSearchResultsDTOs(FileExtSearchFilter filter, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { - String whereStatement = getFileExtensionWhereStatement(filter, dataSourceId, showKnown); + private SearchResultsDTO fetchExtensionSearchResultsDTOs(FileExtSearchFilter filter, Long dataSourceId) throws NoCurrentCaseException, TskCoreException { + String whereStatement = getFileExtensionWhereStatement(filter, dataSourceId); return fetchFileViewFiles(whereStatement, filter.getDisplayName()); } @NbBundle.Messages({"FileTypesByMimeType.name.text=By MIME Type"}) - private SearchResultsDTO fetchMimeSearchResultsDTOs(String mimeType, Long dataSourceId, boolean showKnown) throws NoCurrentCaseException, TskCoreException { - String whereStatement = getFileMimeWhereStatement(mimeType, dataSourceId, showKnown); + private SearchResultsDTO fetchMimeSearchResultsDTOs(String mimeType, Long dataSourceId) throws NoCurrentCaseException, TskCoreException { + String whereStatement = getFileMimeWhereStatement(mimeType, dataSourceId); final String MIME_TYPE_DISPLAY_NAME = Bundle.FileTypesByMimeType_name_text(); return fetchFileViewFiles(whereStatement, MIME_TYPE_DISPLAY_NAME); } From 3eda8ffc4a5b01df7d2e56fb7867fd1bd0bf5f7c Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Wed, 13 Oct 2021 17:14:43 -0400 Subject: [PATCH 4/4] Update FileTypeMimeSearchParams.java --- .../autopsy/mainui/datamodel/FileTypeMimeSearchParams.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java index cd9afdba2e..99240ca8f4 100755 --- a/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java +++ b/Core/src/org/sleuthkit/autopsy/mainui/datamodel/FileTypeMimeSearchParams.java @@ -28,6 +28,7 @@ public class FileTypeMimeSearchParams extends BaseSearchParams { private final String mimeType; private final Long dataSourceId; + // @@@ TODO: Remove shownKnown from constructors and have DAO figure it out. public FileTypeMimeSearchParams(String mimeType, Long dataSourceId, boolean showKnown) { this.mimeType = mimeType; this.dataSourceId = dataSourceId;