19 package org.sleuthkit.autopsy.commonfilesearch;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.Collections;
24 import java.util.HashMap;
26 import java.util.logging.Level;
46 final class InterCaseSearchResultsProcessor {
51 private final Type correlationType;
53 private static final Logger LOGGER = Logger.getLogger(CommonAttributePanel.class.getName());
58 private final String interCaseWhereClause;
63 private final String singleInterCaseWhereClause;
72 InterCaseSearchResultsProcessor(CorrelationAttributeInstance.Type theType) {
73 this.correlationType = theType;
74 interCaseWhereClause = getInterCaseWhereClause();
75 singleInterCaseWhereClause = getSingleInterCaseWhereClause();
78 private String getInterCaseWhereClause() {
79 String tableName = EamDbUtil.correlationTypeToInstanceTableName(correlationType);
80 StringBuilder sqlString =
new StringBuilder(250);
81 sqlString.append(
"value IN (SELECT value FROM ")
83 .append(
" WHERE value IN (SELECT value FROM ")
85 .append(
" WHERE case_id=%s AND (known_status !=%s OR known_status IS NULL) GROUP BY value)")
86 .append(
" GROUP BY value HAVING COUNT(DISTINCT case_id) > 1) ORDER BY value");
87 return sqlString.toString();
90 private String getSingleInterCaseWhereClause() {
91 String tableName = EamDbUtil.correlationTypeToInstanceTableName(correlationType);
92 StringBuilder sqlString =
new StringBuilder(250);
93 sqlString.append(
"value IN (SELECT value FROM ")
95 .append(
" WHERE value IN (SELECT value FROM ")
97 .append(
" WHERE case_id=%s AND (known_status !=%s OR known_status IS NULL) GROUP BY value)")
98 .append(
" AND (case_id=%s OR case_id=%s) GROUP BY value HAVING COUNT(DISTINCT case_id) > 1) ORDER BY value");
99 return sqlString.toString();
109 CorrelationAttributeInstance findSingleCorrelationAttribute(
int attrbuteId) {
112 InterCaseCommonAttributeRowCallback instancetableCallback =
new InterCaseCommonAttributeRowCallback();
113 EamDb dbManager = EamDb.getInstance();
114 dbManager.processInstanceTableWhere(correlationType, String.format(
"id = %s", attrbuteId), instancetableCallback);
116 return instancetableCallback.getCorrelationAttribute();
118 }
catch (EamDbException ex) {
119 LOGGER.log(Level.SEVERE,
"Error accessing EamDb processing InstanceTable row.", ex);
135 Map<String, Map<String, CommonAttributeValueList>> findInterCaseValuesByCase(Case currentCase) {
137 InterCaseByCaseCallback instancetableCallback =
new InterCaseByCaseCallback();
138 EamDb dbManager = EamDb.getInstance();
140 int caseId = dbManager.getCase(currentCase).getID();
142 dbManager.processInstanceTableWhere(correlationType, String.format(interCaseWhereClause, caseId,
143 TskData.FileKnown.KNOWN.getFileKnownValue()),
144 instancetableCallback);
146 return instancetableCallback.getInstanceCollatedCommonFiles();
148 }
catch (EamDbException ex) {
149 LOGGER.log(Level.SEVERE,
"Error accessing EamDb processing CaseInstancesTable.", ex);
151 return new HashMap<>();
160 Map<Integer, CommonAttributeValueList> findInterCaseValuesByCount(Case currentCase) {
162 InterCaseByCountCallback instancetableCallback =
new InterCaseByCountCallback();
163 EamDb dbManager = EamDb.getInstance();
165 int caseId = dbManager.getCase(currentCase).getID();
167 dbManager.processInstanceTableWhere(correlationType, String.format(interCaseWhereClause, caseId,
168 TskData.FileKnown.KNOWN.getFileKnownValue()),
169 instancetableCallback);
171 return instancetableCallback.getInstanceCollatedCommonFiles();
173 }
catch (EamDbException ex) {
174 LOGGER.log(Level.SEVERE,
"Error accessing EamDb processing CaseInstancesTable.", ex);
176 return new HashMap<>();
187 Map<Integer, CommonAttributeValueList> findSingleInterCaseValuesByCount(Case currentCase, CorrelationCase singleCase) {
189 InterCaseByCountCallback instancetableCallback =
new InterCaseByCountCallback();
190 EamDb dbManager = EamDb.getInstance();
191 int caseId = dbManager.getCase(currentCase).getID();
192 int targetCaseId = singleCase.getID();
193 dbManager.processInstanceTableWhere(correlationType, String.format(singleInterCaseWhereClause, caseId,
194 TskData.FileKnown.KNOWN.getFileKnownValue(), caseId, targetCaseId), instancetableCallback);
195 return instancetableCallback.getInstanceCollatedCommonFiles();
196 }
catch (EamDbException ex) {
197 LOGGER.log(Level.SEVERE,
"Error accessing EamDb processing CaseInstancesTable.", ex);
199 return new HashMap<>();
215 Map<String, Map<String, CommonAttributeValueList>> findSingleInterCaseValuesByCase(Case currentCase, CorrelationCase singleCase) {
217 InterCaseByCaseCallback instancetableCallback =
new InterCaseByCaseCallback();
218 EamDb dbManager = EamDb.getInstance();
219 int caseId = dbManager.getCase(currentCase).getID();
220 int targetCaseId = singleCase.getID();
221 dbManager.processInstanceTableWhere(correlationType, String.format(singleInterCaseWhereClause, caseId,
222 TskData.FileKnown.KNOWN.getFileKnownValue(), caseId, targetCaseId), instancetableCallback);
223 return instancetableCallback.getInstanceCollatedCommonFiles();
224 }
catch (EamDbException ex) {
225 LOGGER.log(Level.SEVERE,
"Error accessing EamDb processing CaseInstancesTable.", ex);
227 return new HashMap<>();
236 final Map<Integer, CommonAttributeValueList> instanceCollatedCommonFiles =
new HashMap<>();
244 while (resultSet.next()) {
248 if (previousRowMd5.isEmpty()) {
249 previousRowMd5 = corValue;
251 if (corValue == null || HashUtility.isNoDataMd5(corValue)) {
259 if (commonAttributeValue != null) {
261 if (instanceCollatedCommonFiles.containsKey(size)) {
262 instanceCollatedCommonFiles.get(size).addMetadataToList(commonAttributeValue);
265 value.addMetadataToList(commonAttributeValue);
266 instanceCollatedCommonFiles.put(size, value);
269 }
catch (SQLException ex) {
270 LOGGER.log(Level.WARNING,
"Error getting artifact instances from database.", ex);
284 if (commonAttributeValue == null) {
287 if (!corValue.equals(previousRowMd5)) {
289 if (instanceCollatedCommonFiles.containsKey(size)) {
290 instanceCollatedCommonFiles.get(size).addMetadataToList(commonAttributeValue);
293 value.addMetadataToList(commonAttributeValue);
294 instanceCollatedCommonFiles.put(size, value);
298 previousRowMd5 = corValue;
305 searchResult.setCurrentAttributeInst(corrAttr);
306 commonAttributeValue.addInstance(searchResult);
309 Map<Integer, CommonAttributeValueList> getInstanceCollatedCommonFiles() {
310 return Collections.unmodifiableMap(instanceCollatedCommonFiles);
320 final Map<String, Map<String, CommonAttributeValueList>> caseCollatedDataSourceCollections =
new HashMap<>();
325 while (resultSet.next()) {
328 if (corValue == null || HashUtility.isNoDataMd5(corValue)) {
336 if (!caseCollatedDataSourceCollections.containsKey(caseName)) {
337 caseCollatedDataSourceCollections.put(caseName,
new HashMap<String, CommonAttributeValueList>());
339 Map<String, CommonAttributeValueList> dataSourceToFile = caseCollatedDataSourceCollections.get(caseName);
340 if (!dataSourceToFile.containsKey(dataSourceNameKey)) {
346 searchResult.setCurrentAttributeInst(corrAttr);
348 commonAttributeValue.addInstance(searchResult);
349 valueList.addMetadataToList(commonAttributeValue);
350 dataSourceToFile.put(dataSourceNameKey, valueList);
351 caseCollatedDataSourceCollections.put(caseName, dataSourceToFile);
354 LOGGER.log(Level.WARNING,
"Error getting artifact instances from database.", ex);
358 Map<String, Map<String, CommonAttributeValueList>> getInstanceCollatedCommonFiles() {
359 return Collections.unmodifiableMap(caseCollatedDataSourceCollections);
376 while (resultSet.next()) {
386 LOGGER.log(Level.INFO,
"Unable to get CorrelationAttributeInstance.", ex);
391 LOGGER.log(Level.WARNING,
"Error getting single correlation artifact instance from database.", ex);
396 return correlationAttributeInstance;
CommonAttributeValue commonAttributeValue
void process(ResultSet resultSet)
static String getFilePath(ResultSet resultSet)
static int getId(ResultSet resultSet)
CorrelationDataSource getDataSourceById(CorrelationCase correlationCase, int dataSourceId)
CorrelationCase getCaseById(int caseId)
void countAndAddCommonAttributes(String corValue, int resultId)
static EamDb getInstance()
void process(ResultSet resultSet)
CorrelationAttributeInstance getCorrelationAttributeInstance(CorrelationAttributeInstance.Type type, CorrelationCase correlationCase, CorrelationDataSource correlationDataSource, String value, String filePath)
static int getDataSourceId(ResultSet resultSet)
Long getDataSourceObjectID()
static int getCaseId(ResultSet resultSet)
static String getValue(ResultSet resultSet)
void process(ResultSet resultSet)