20 package org.sleuthkit.autopsy.commonpropertiessearch;
 
   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;
 
   59         this.caseNameToDataSources = 
filterMetadata(metadata, percentageThreshold, resultType.getId());
 
   84     Map<String, CommonAttributeValueList> getAttributeValuesForCaseName(String caseName) {
 
   85         return this.caseNameToDataSources.get(caseName);
 
   94     public Map<String, Map<String, CommonAttributeValueList>> 
getMetadata() {
 
   95         return Collections.unmodifiableMap(this.caseNameToDataSources);
 
  113     private Map<String, Map<String, CommonAttributeValueList>> 
filterMetadata(Map<String, Map<String, CommonAttributeValueList>> metadata, 
int percentageThreshold, 
int resultTypeId) {
 
  115             final String currentCaseName;
 
  119                 throw new EamDbException(
"Unable to get current case while performing filtering", ex);
 
  121             Map<String, CommonAttributeValueList> currentCaseDataSourceMap = metadata.get(currentCaseName);
 
  122             Map<String, Map<String, CommonAttributeValueList>> filteredCaseNameToDataSourcesTree = 
new HashMap<>();
 
  123             if (currentCaseDataSourceMap == null) { 
 
  124                 return filteredCaseNameToDataSourcesTree;
 
  129                     .filter(filterType -> filterType.getId() == resultTypeId)
 
  133             Map<String, CommonAttributeValue> valuesToKeepCurrentCase = 
getValuesToKeepFromCurrentCase(currentCaseDataSourceMap, attributeType, percentageThreshold, uniqueCaseDataSourceTuples);
 
  134             for (Entry<String, Map<String, CommonAttributeValueList>> mapOfDataSources : Collections.unmodifiableMap(metadata).entrySet()) {
 
  135                 if (!mapOfDataSources.getKey().equals(currentCaseName)) {
 
  137                     Map<String, CommonAttributeValueList> newTreeForCase = 
createTreeForCase(valuesToKeepCurrentCase, mapOfDataSources.getValue());
 
  138                     if (!newTreeForCase.isEmpty()) {
 
  139                         filteredCaseNameToDataSourcesTree.put(mapOfDataSources.getKey(), newTreeForCase);
 
  143             return filteredCaseNameToDataSourcesTree;
 
  145             LOGGER.log(Level.INFO, 
"Unable to perform filtering returning unfiltered result set", ex);
 
  170         Map<String, CommonAttributeValue> valuesToKeep = 
new HashMap<>();
 
  171         Set<String> valuesToRemove = 
new HashSet<>();
 
  172         for (Entry<String, CommonAttributeValueList> mapOfValueLists : Collections.unmodifiableMap(dataSourceToValueList).entrySet()) {
 
  174                 if (valuesToRemove.contains(value.getValue())) {
 
  176                 } 
else if (
filterValue(attributeType, value, maximumPercentageThreshold, uniqueCaseDataSourceTuples)) {
 
  177                     valuesToRemove.add(value.getValue());
 
  179                     valuesToKeep.put(value.getValue(), value);
 
  199     private Map<String, CommonAttributeValueList> 
createTreeForCase(Map<String, CommonAttributeValue> valuesToKeepCurrentCase, Map<String, CommonAttributeValueList> dataSourceToValueList) 
throws EamDbException {
 
  200         Map<String, CommonAttributeValueList> treeForCase = 
new HashMap<>();
 
  201         for (Entry<String, CommonAttributeValueList> mapOfValueLists : Collections.unmodifiableMap(dataSourceToValueList).entrySet()) {
 
  203                 if (valuesToKeepCurrentCase.containsKey(value.getValue())) {
 
  204                     if (!treeForCase.containsKey(mapOfValueLists.getKey())) {
 
  207                     treeForCase.get(mapOfValueLists.getKey()).addMetadataToList(valuesToKeepCurrentCase.get(value.getValue()));
 
  234         if (maximumPercentageThreshold != 0) {  
 
  237                         attributeType, value.getValue()).doubleValue();
 
  238                 Double commonalityPercentage = uniqueTypeValueTuples / uniqueCaseDataSourceTuples * 100;
 
  239                 int frequencyPercentage = commonalityPercentage.intValue();
 
  240                 if (frequencyPercentage > maximumPercentageThreshold) {
 
  244                 LOGGER.log(Level.WARNING, 
"Unable to determine frequency percentage attribute - frequency filter may not be accurate for these results.", ex);
 
static List< CorrelationAttributeInstance.Type > getDefaultCorrelationTypes()
boolean filterValue(CorrelationAttributeInstance.Type attributeType, CommonAttributeValue value, int maximumPercentageThreshold, Double uniqueCaseDataSourceTuples)
Long getCountUniqueDataSources()
Map< String, CommonAttributeValue > getValuesToKeepFromCurrentCase(Map< String, CommonAttributeValueList > dataSourceToValueList, CorrelationAttributeInstance.Type attributeType, int maximumPercentageThreshold, Double uniqueCaseDataSourceTuples)
final Map< String, Map< String, CommonAttributeValueList > > caseNameToDataSources
Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value)
static EamDb getInstance()
Map< String, Map< String, CommonAttributeValueList > > filterMetadata(Map< String, Map< String, CommonAttributeValueList >> metadata, int percentageThreshold, int resultTypeId)
synchronized static Logger getLogger(String name)
Map< String, Map< String, CommonAttributeValueList > > getMetadata()
static Case getCurrentCaseThrows()
static final Logger LOGGER
Map< String, CommonAttributeValueList > createTreeForCase(Map< String, CommonAttributeValue > valuesToKeepCurrentCase, Map< String, CommonAttributeValueList > dataSourceToValueList)
static final int FILES_TYPE_ID