pulled the two subclasses into their own files

This commit is contained in:
Brian Sweeney 2018-04-09 09:23:36 -06:00
parent bcfa75c5f9
commit 9fb65e6ff2
3 changed files with 82 additions and 34 deletions

View File

@ -0,0 +1,39 @@
/*
*
* Autopsy Forensic Browser
*
* Copyright 2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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<Long, String> dataSourceIdMap) {
super(dataSourceIdMap);
}
@Override
protected String buildSqlWhereClause() {
return AllDataSources.WHERE_CLAUSE;
}
}

View File

@ -43,7 +43,6 @@ import org.sleuthkit.datamodel.TskCoreException;
abstract class CommonFilesMetaDataBuilder {
private final Map<Long, String> dataSourceIdToNameMap;
//TODO subclass this class to specify where clause and/or additional algorithms.
CommonFilesMetaDataBuilder(Map<Long, String> dataSourceIdMap) {
dataSourceIdToNameMap = dataSourceIdMap;
@ -119,36 +118,4 @@ abstract class CommonFilesMetaDataBuilder {
List<AbstractFile> 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<Long, String> 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<Long, String> dataSourceIdMap) {
super(dataSourceIdMap);
}
@Override
protected String buildSqlWhereClause() {
return AllDataSources.singleDataSourceWhereClause;
}
}
}

View File

@ -0,0 +1,42 @@
/*
*
* Autopsy Forensic Browser
*
* Copyright 2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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<Long, String> 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);
}
}