20 package org.sleuthkit.autopsy.commonfilesearch;
 
   22 import java.util.Collections;
 
   23 import java.util.HashMap;
 
   24 import java.util.HashSet;
 
   26 import java.util.Map.Entry;
 
   28 import java.util.logging.Level;
 
   62         this.caseNameToDataSources = 
filterMetadata(metadata, percentageThreshold, resultType.getId(), mimeTypesToFilterOn);
 
   87     Map<String, CommonAttributeValueList> getAttributeValuesForCaseName(String caseName) {
 
   88         return this.caseNameToDataSources.get(caseName);
 
   97     public Map<String, Map<String, CommonAttributeValueList>> 
getMetadata() {
 
   98         return Collections.unmodifiableMap(this.caseNameToDataSources);
 
  117     private Map<String, Map<String, CommonAttributeValueList>> 
filterMetadata(Map<String, Map<String, CommonAttributeValueList>> metadata, 
int percentageThreshold, 
int resultTypeId, Set<String> mimeTypesToFilterOn) {
 
  119             final String currentCaseName;
 
  123                 throw new EamDbException(
"Unable to get current case while performing filtering", ex);
 
  125             Map<String, CommonAttributeValueList> currentCaseDataSourceMap = metadata.get(currentCaseName);
 
  126             if (currentCaseDataSourceMap == null) {
 
  127                 throw new EamDbException(
"No data for current case found in results, indicating there are no results and nothing will be filtered");
 
  132                     .filter(filterType -> filterType.getId() == resultTypeId)
 
  136             Map<String, Map<String, CommonAttributeValueList>> filteredCaseNameToDataSourcesTree = 
new HashMap<>();
 
  137             Map<String, CommonAttributeValue> valuesToKeepCurrentCase = 
getValuesToKeepFromCurrentCase(currentCaseDataSourceMap, attributeType, percentageThreshold, uniqueCaseDataSourceTuples, mimeTypesToFilterOn);
 
  138             for (Entry<String, Map<String, CommonAttributeValueList>> mapOfDataSources : Collections.unmodifiableMap(metadata).entrySet()) {
 
  139                 if (!mapOfDataSources.getKey().equals(currentCaseName)) {
 
  141                     Map<String, CommonAttributeValueList> newTreeForCase = 
createTreeForCase(valuesToKeepCurrentCase, mapOfDataSources.getValue());
 
  142                     filteredCaseNameToDataSourcesTree.put(mapOfDataSources.getKey(), newTreeForCase);
 
  145             return filteredCaseNameToDataSourcesTree;
 
  147             LOGGER.log(Level.INFO, 
"Unable to perform filtering returning unfiltered result set", ex);
 
  173         Map<String, CommonAttributeValue> valuesToKeep = 
new HashMap<>();
 
  174         Set<String> valuesToRemove = 
new HashSet<>();
 
  175         for (Entry<String, CommonAttributeValueList> mapOfValueLists : Collections.unmodifiableMap(dataSourceToValueList).entrySet()) {
 
  177                 if (valuesToRemove.contains(value.getValue())) {
 
  179                 } 
else if (
filterValue(attributeType, value, maximumPercentageThreshold, uniqueCaseDataSourceTuples, mimeTypesToFilterOn)) {
 
  180                     valuesToRemove.add(value.getValue());
 
  182                     valuesToKeep.put(value.getValue(), value);
 
  202     private Map<String, CommonAttributeValueList> 
createTreeForCase(Map<String, CommonAttributeValue> valuesToKeepCurrentCase, Map<String, CommonAttributeValueList> dataSourceToValueList) 
throws EamDbException {
 
  203         Map<String, CommonAttributeValueList> treeForCase = 
new HashMap<>();
 
  204         for (Entry<String, CommonAttributeValueList> mapOfValueLists : Collections.unmodifiableMap(dataSourceToValueList).entrySet()) {
 
  206                 if (valuesToKeepCurrentCase.containsKey(value.getValue())) {
 
  207                     if (!treeForCase.containsKey(mapOfValueLists.getKey())) {
 
  210                     treeForCase.get(mapOfValueLists.getKey()).addMetadataToList(valuesToKeepCurrentCase.get(value.getValue()));
 
  240         if (!mimeTypesToInclude.isEmpty()) { 
 
  242                 AbstractFile abstractFile = commonAttr.getAbstractFile();
 
  243                 if (abstractFile != null) {
 
  244                     String mimeType = abstractFile.getMIMEType();
 
  245                     if (mimeType != null && !mimeTypesToInclude.contains(mimeType)) {
 
  251         if (maximumPercentageThreshold != 0) {  
 
  254                         attributeType, value.getValue()).doubleValue();
 
  255                 Double commonalityPercentage = uniqueTypeValueTuples / uniqueCaseDataSourceTuples * 100;
 
  256                 int frequencyPercentage = commonalityPercentage.intValue();
 
  257                 if (frequencyPercentage > maximumPercentageThreshold) {
 
  261                 LOGGER.log(Level.WARNING, 
"Unable to determine frequency percentage attribute - frequency filter may not be accurate for these results.", ex);
 
Map< String, CommonAttributeValueList > createTreeForCase(Map< String, CommonAttributeValue > valuesToKeepCurrentCase, Map< String, CommonAttributeValueList > dataSourceToValueList)
 
Map< String, Map< String, CommonAttributeValueList > > filterMetadata(Map< String, Map< String, CommonAttributeValueList >> metadata, int percentageThreshold, int resultTypeId, Set< String > mimeTypesToFilterOn)
 
boolean filterValue(CorrelationAttributeInstance.Type attributeType, CommonAttributeValue value, int maximumPercentageThreshold, Double uniqueCaseDataSourceTuples, Set< String > mimeTypesToInclude)
 
static List< CorrelationAttributeInstance.Type > getDefaultCorrelationTypes()
 
Long getCountUniqueDataSources()
 
Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value)
 
static final Logger LOGGER
 
Map< String, Map< String, CommonAttributeValueList > > getMetadata()
 
static EamDb getInstance()
 
final Map< String, Map< String, CommonAttributeValueList > > caseNameToDataSources
 
synchronized static Logger getLogger(String name)
 
static Case getCurrentCaseThrows()
 
static final int FILES_TYPE_ID
 
Map< String, CommonAttributeValue > getValuesToKeepFromCurrentCase(Map< String, CommonAttributeValueList > dataSourceToValueList, CorrelationAttributeInstance.Type attributeType, int maximumPercentageThreshold, Double uniqueCaseDataSourceTuples, Set< String > mimeTypesToFilterOn)