19 package org.sleuthkit.autopsy.contentviewers.analysisresults;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.Optional;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.stream.Collectors;
30 import java.util.stream.Stream;
31 import org.apache.commons.lang3.tuple.Pair;
32 import org.openide.nodes.Node;
33 import org.openide.util.NbBundle;
51 static class ResultDisplayAttributes {
53 private final AnalysisResult analysisResult;
54 private final List<Pair<String, String>> attributesToDisplay;
64 ResultDisplayAttributes(AnalysisResult analysisResult, List<Pair<String, String>> attributesToDisplay) {
65 this.analysisResult = analysisResult;
66 this.attributesToDisplay = attributesToDisplay;
74 List<Pair<String, String>> getAttributesToDisplay() {
75 return attributesToDisplay;
83 AnalysisResult getAnalysisResult() {
84 return analysisResult;
92 static class NodeResults {
94 private final List<ResultDisplayAttributes> analysisResults;
95 private final Optional<AnalysisResult> selectedResult;
96 private final Optional<Score> aggregateScore;
97 private final Optional<Content> content;
108 NodeResults(List<ResultDisplayAttributes> analysisResults, Optional<AnalysisResult> selectedResult, Optional<Score> aggregateScore, Optional<Content> content) {
109 this.analysisResults = analysisResults;
110 this.selectedResult = selectedResult;
111 this.aggregateScore = aggregateScore;
112 this.content = content;
120 List<ResultDisplayAttributes> getAnalysisResults() {
121 return analysisResults;
129 Optional<AnalysisResult> getSelectedResult() {
130 return selectedResult;
138 Optional<Score> getAggregateScore() {
139 return aggregateScore;
149 Optional<Content> getContent() {
163 return (originalAttrStr == null) ?
"" : originalAttrStr.trim();
174 "AnalysisResultsViewModel_displayAttributes_score=Score",
175 "AnalysisResultsViewModel_displayAttributes_type=Type",
176 "AnalysisResultsViewModel_displayAttributes_configuration=Configuration",
177 "AnalysisResultsViewModel_displayAttributes_conclusion=Conclusion"
183 type =
normalizeAttr(analysisResult.getType().getDisplayName());
184 }
catch (TskCoreException ex) {
185 logger.log(Level.SEVERE,
"Unable to get type for analysis result with id: " + analysisResult.getArtifactID(), ex);
189 Stream<Pair<String, String>> baseAnalysisAttrs = Stream.of(
190 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_score(),
191 normalizeAttr(analysisResult.getScore().getSignificance().getDisplayName())),
192 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_type(),
194 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_configuration(),
196 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_conclusion(),
201 Stream<Pair<String, String>> blackboardAttributes = Stream.empty();
204 blackboardAttributes = analysisResult.getAttributes().stream()
205 .filter(attr -> attr != null && attr.getAttributeType() != null && attr.getAttributeType().getDisplayName() != null)
206 .map(attr -> Pair.of(attr.getAttributeType().getDisplayName(),
normalizeAttr(attr.getDisplayString())))
207 .sorted((a, b) -> a.getKey().compareToIgnoreCase(b.getKey()));
208 }
catch (TskCoreException ex) {
209 logger.log(Level.SEVERE,
"Unable to get attributes for analysis result with id: " + analysisResult.getArtifactID(), ex);
213 List<Pair<String, String>> allDisplayAttributes = Stream.concat(baseAnalysisAttrs, blackboardAttributes)
214 .collect(Collectors.toList());
216 return new ResultDisplayAttributes(analysisResult, allDisplayAttributes);
220 return analysisResults.stream()
221 .filter(ar -> ar != null && ar.getScore() != null)
223 .sorted((a, b) -> -a.getScore().compareTo(b.getScore()))
225 .collect(Collectors.toList());
236 NodeResults getAnalysisResults(Node node) {
238 return new NodeResults(Collections.emptyList(), Optional.empty(), Optional.empty(), Optional.empty());
241 Optional<Score> aggregateScore = Optional.empty();
242 Optional<Content> nodeContent = Optional.empty();
244 Map<Long, AnalysisResult> allAnalysisResults =
new HashMap<>();
245 Optional<AnalysisResult> selectedResult = Optional.empty();
248 for (Content content : node.getLookup().lookupAll(Content.class)) {
249 if (content == null || content instanceof BlackboardArtifact) {
254 nodeContent = Optional.of(content);
257 aggregateScore = Optional.ofNullable(content.getAggregateScore());
260 content.getAllAnalysisResults().stream()
261 .forEach((ar) -> allAnalysisResults.put(ar.getArtifactID(), ar));
264 }
catch (TskCoreException ex) {
265 logger.log(Level.SEVERE,
"Unable to get analysis results for content with obj id " + content.getId(), ex);
270 Collection<? extends AnalysisResult> analysisResults = node.getLookup().lookupAll(AnalysisResult.class);
271 if (analysisResults.size() > 0) {
274 List<AnalysisResult> filteredResults = analysisResults.stream()
275 .collect(Collectors.toList());
278 filteredResults.forEach((ar) -> allAnalysisResults.put(ar.getArtifactID(), ar));
281 selectedResult = filteredResults.stream()
282 .max((a, b) -> a.getScore().compareTo(b.getScore()));
285 if (!aggregateScore.isPresent()) {
286 aggregateScore = selectedResult.flatMap(selectedRes -> Optional.ofNullable(selectedRes.getScore()));
293 return new NodeResults(displayAttributes, selectedResult, aggregateScore, nodeContent);
String normalizeAttr(String originalAttrStr)
ResultDisplayAttributes getDisplayAttributes(AnalysisResult analysisResult)
List< ResultDisplayAttributes > getOrderedDisplayAttributes(Collection< AnalysisResult > analysisResults)
static final Logger logger