From 9fb65e6ff275d6d36fde1de955f1bc3c62c26d2e Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 9 Apr 2018 09:23:36 -0600 Subject: [PATCH] pulled the two subclasses into their own files --- .../commonfilesearch/AllDataSources.java | 39 +++++++++++++++++ .../CommonFilesMetaDataBuilder.java | 35 +--------------- .../commonfilesearch/SingleDataSource.java | 42 +++++++++++++++++++ 3 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java create mode 100644 Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java new file mode 100644 index 0000000000..ebf3c1bafc --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSources.java @@ -0,0 +1,39 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 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.commonfilesearch; + +import java.util.Map; + +/** + * Provides logic for selecting common files from all data sources. + */ +class AllDataSources extends CommonFilesMetaDataBuilder { + + private static final String WHERE_CLAUSE = "md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL) GROUP BY md5 HAVING COUNT(*) > 1) order by md5"; + + public AllDataSources(Map dataSourceIdMap) { + super(dataSourceIdMap); + } + + @Override + protected String buildSqlWhereClause() { + return AllDataSources.WHERE_CLAUSE; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java index d53e9f403f..5d663a6f9d 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetaDataBuilder.java @@ -43,7 +43,6 @@ import org.sleuthkit.datamodel.TskCoreException; abstract class CommonFilesMetaDataBuilder { private final Map dataSourceIdToNameMap; - //TODO subclass this class to specify where clause and/or additional algorithms. CommonFilesMetaDataBuilder(Map dataSourceIdMap) { dataSourceIdToNameMap = dataSourceIdMap; @@ -119,36 +118,4 @@ abstract class CommonFilesMetaDataBuilder { List files = sleuthkitCase.findAllFilesWhere(whereClause); return files; } -} - -class SingleDataSource extends CommonFilesMetaDataBuilder { - - private static final String allDataSourcesWhereClause = "md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL) GROUP BY md5 HAVING COUNT(*) > 1) order by md5"; - - private final Long selectedDataSourceId; - - public SingleDataSource(Long dataSourceId, Map dataSourceIdMap) { - super(dataSourceIdMap); - this.selectedDataSourceId = dataSourceId; - } - - @Override - protected String buildSqlWhereClause() { - Object[] args = new String[]{Long.toString(this.selectedDataSourceId), Long.toString(this.selectedDataSourceId)}; - return String.format(SingleDataSource.allDataSourcesWhereClause, args); - } -} - -class AllDataSources extends CommonFilesMetaDataBuilder { - - private static final String singleDataSourceWhereClause = "md5 in (select md5 from tsk_files where data_source_obj_id=%s and (known != 1 OR known IS NULL) GROUP BY md5 HAVING COUNT(*) > 1) AND data_source_obj_id=%s order by md5"; - - public AllDataSources(Map dataSourceIdMap) { - super(dataSourceIdMap); - } - - @Override - protected String buildSqlWhereClause() { - return AllDataSources.singleDataSourceWhereClause; - } -} +} \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java new file mode 100644 index 0000000000..d25f8aec73 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java @@ -0,0 +1,42 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 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.commonfilesearch; + +import java.util.Map; + +/** + * Provides logic for selecting common files from a single data source. + */ +class SingleDataSource extends CommonFilesMetaDataBuilder { + + private static final String WHERE_CLAUSE = "md5 in (select md5 from tsk_files where data_source_obj_id=%s and (known != 1 OR known IS NULL) GROUP BY md5 HAVING COUNT(*) > 1) AND data_source_obj_id=%s order by md5"; + private final Long selectedDataSourceId; + + public SingleDataSource(Long dataSourceId, Map dataSourceIdMap) { + super(dataSourceIdMap); + this.selectedDataSourceId = dataSourceId; + } + + @Override + protected String buildSqlWhereClause() { + Object[] args = new String[]{Long.toString(this.selectedDataSourceId), Long.toString(this.selectedDataSourceId)}; + return String.format(SingleDataSource.WHERE_CLAUSE, args); + } +}