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;
121 Map<String, CommonAttributeValueList> currentCaseDataSourceMap = metadata.get(currentCaseName);
122 Map<String, Map<String, CommonAttributeValueList>> filteredCaseNameToDataSourcesTree =
new HashMap<>();
123 if (currentCaseDataSourceMap == null) {
124 return filteredCaseNameToDataSourcesTree;
128 .filter(filterType -> filterType.getId() == resultTypeId)
132 Map<String, CommonAttributeValue> valuesToKeepCurrentCase =
getValuesToKeepFromCurrentCase(currentCaseDataSourceMap, attributeType, percentageThreshold, uniqueCaseDataSourceTuples);
133 for (Entry<String, Map<String, CommonAttributeValueList>> mapOfDataSources : Collections.unmodifiableMap(metadata).entrySet()) {
134 if (!mapOfDataSources.getKey().equals(currentCaseName)) {
136 Map<String, CommonAttributeValueList> newTreeForCase =
createTreeForCase(valuesToKeepCurrentCase, mapOfDataSources.getValue());
137 if (!newTreeForCase.isEmpty()) {
138 filteredCaseNameToDataSourcesTree.put(mapOfDataSources.getKey(), newTreeForCase);
142 return filteredCaseNameToDataSourcesTree;
144 LOGGER.log(Level.INFO,
"Unable to perform filtering returning unfiltered result set", ex);
169 Map<String, CommonAttributeValue> valuesToKeep =
new HashMap<>();
170 Set<String> valuesToRemove =
new HashSet<>();
171 for (Entry<String, CommonAttributeValueList> mapOfValueLists : Collections.unmodifiableMap(dataSourceToValueList).entrySet()) {
173 if (valuesToRemove.contains(value.getValue())) {
175 }
else if (
filterValue(attributeType, value, maximumPercentageThreshold, uniqueCaseDataSourceTuples)) {
176 valuesToRemove.add(value.getValue());
178 valuesToKeep.put(value.getValue(), value);
198 private Map<String, CommonAttributeValueList>
createTreeForCase(Map<String, CommonAttributeValue> valuesToKeepCurrentCase, Map<String, CommonAttributeValueList> dataSourceToValueList)
throws CentralRepoException {
199 Map<String, CommonAttributeValueList> treeForCase =
new HashMap<>();
200 for (Entry<String, CommonAttributeValueList> mapOfValueLists : Collections.unmodifiableMap(dataSourceToValueList).entrySet()) {
202 if (valuesToKeepCurrentCase.containsKey(value.getValue())) {
203 if (!treeForCase.containsKey(mapOfValueLists.getKey())) {
206 treeForCase.get(mapOfValueLists.getKey()).addMetadataToList(valuesToKeepCurrentCase.get(value.getValue()));
233 if (maximumPercentageThreshold != 0) {
236 attributeType, value.getValue()).doubleValue();
237 Double commonalityPercentage = uniqueTypeValueTuples / uniqueCaseDataSourceTuples * 100;
238 int frequencyPercentage = commonalityPercentage.intValue();
239 if (frequencyPercentage > maximumPercentageThreshold) {
243 LOGGER.log(Level.WARNING,
"Unable to determine frequency percentage attribute - frequency filter may not be accurate for these results.", ex);
Long getCountUniqueDataSources()
boolean filterValue(CorrelationAttributeInstance.Type attributeType, CommonAttributeValue value, int maximumPercentageThreshold, Double uniqueCaseDataSourceTuples)
Map< String, CommonAttributeValue > getValuesToKeepFromCurrentCase(Map< String, CommonAttributeValueList > dataSourceToValueList, CorrelationAttributeInstance.Type attributeType, int maximumPercentageThreshold, Double uniqueCaseDataSourceTuples)
final Map< String, Map< String, CommonAttributeValueList > > caseNameToDataSources
List< CorrelationAttributeInstance.Type > getDefinedCorrelationTypes()
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 CentralRepository getInstance()
Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value)
static final Logger LOGGER
Map< String, CommonAttributeValueList > createTreeForCase(Map< String, CommonAttributeValue > valuesToKeepCurrentCase, Map< String, CommonAttributeValueList > dataSourceToValueList)
static final int FILES_TYPE_ID