20 package org.sleuthkit.autopsy.commonpropertiessearch;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.HashSet;
34 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
45 @SuppressWarnings(
"PMD.AbstractNaming")
48 private static final String FILTER_BY_MIME_TYPES_WHERE_CLAUSE =
" and mime_type in (%s)";
62 super(filterByMediaMimeType, filterByDocMimeType, percentageThreshold);
63 this.dataSourceIdToNameMap = dataSourceIdMap;
66 Map<Long, String> getDataSourceIdToNameMap() {
67 return Collections.unmodifiableMap(this.dataSourceIdToNameMap);
79 static final String SELECT_PREFIX =
"SELECT obj_id, md5, data_source_obj_id from tsk_files where";
91 protected abstract String buildSqlSelectStatement();
106 Map<String, CommonAttributeValue> commonFiles =
new HashMap<>();
111 SleuthkitCase sleuthkitCase = currentCase.getSleuthkitCase();
113 String selectStatement = this.buildSqlSelectStatement();
116 CaseDbQuery query = sleuthkitCase.executeQuery(selectStatement);
117 ResultSet resultSet = query.getResultSet()) {
119 while (resultSet.next()) {
120 Long objectId = resultSet.getLong(1);
121 String md5 = resultSet.getString(2);
122 Long dataSourceId = resultSet.getLong(3);
123 String dataSource = this.getDataSourceIdToNameMap().get(dataSourceId);
125 if (md5 == null || HashUtility.isNoDataMd5(md5)) {
129 if (commonFiles.containsKey(md5)) {
135 commonFiles.put(md5, commonAttributeValue);
140 Map<Integer, CommonAttributeValueList> instanceCollatedCommonFiles = collateMatchesByNumberOfInstances(commonFiles);
147 throw new EamDbException(
"Not Supported at the moment");
160 String determineMimeTypeFilter() {
162 Set<String> mimeTypesToFilterOn =
new HashSet<>();
163 String mimeTypeString =
"";
164 if (isFilterByMedia()) {
165 mimeTypesToFilterOn.addAll(MEDIA_PICS_VIDEO_MIME_TYPES);
167 if (isFilterByDoc()) {
168 mimeTypesToFilterOn.addAll(TEXT_FILES_MIME_TYPES);
170 StringBuilder mimeTypeFilter =
new StringBuilder(mimeTypesToFilterOn.size());
171 if (!mimeTypesToFilterOn.isEmpty()) {
172 for (String mimeType : mimeTypesToFilterOn) {
173 mimeTypeFilter.append(SINGLE_QUOTE).append(mimeType).append(SINGLE_QUTOE_COMMA);
175 mimeTypeString = mimeTypeFilter.toString().substring(0, mimeTypeFilter.length() - 1);
176 mimeTypeString = String.format(FILTER_BY_MIME_TYPES_WHERE_CLAUSE,
new Object[]{mimeTypeString});
178 return mimeTypeString;
180 static final String SINGLE_QUTOE_COMMA =
"',";
181 static final String SINGLE_QUOTE =
"'";
final Map< Long, String > dataSourceIdToNameMap
CommonAttributeCountSearchResults findMatchesByCount()
CommonAttributeCaseSearchResults findMatchesByCase()
static Case getCurrentCaseThrows()