19 package org.sleuthkit.autopsy.contentviewers.analysisresults;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.Optional;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30 import org.apache.commons.lang3.tuple.Pair;
31 import org.openide.nodes.Node;
32 import org.openide.util.NbBundle;
50 static class ResultDisplayAttributes {
52 private final AnalysisResult analysisResult;
53 private final List<Pair<String, String>> attributesToDisplay;
63 ResultDisplayAttributes(AnalysisResult analysisResult, List<Pair<String, String>> attributesToDisplay) {
64 this.analysisResult = analysisResult;
65 this.attributesToDisplay = attributesToDisplay;
73 List<Pair<String, String>> getAttributesToDisplay() {
74 return Collections.unmodifiableList(attributesToDisplay);
82 AnalysisResult getAnalysisResult() {
83 return analysisResult;
91 static class NodeResults {
93 private final List<ResultDisplayAttributes> analysisResults;
94 private final Optional<AnalysisResult> selectedResult;
95 private final Optional<Score> aggregateScore;
96 private final Optional<Content> content;
107 NodeResults(List<ResultDisplayAttributes> analysisResults, Optional<AnalysisResult> selectedResult, Optional<Score> aggregateScore, Optional<Content> content) {
108 this.analysisResults = analysisResults;
109 this.selectedResult = selectedResult;
110 this.aggregateScore = aggregateScore;
111 this.content = content;
119 List<ResultDisplayAttributes> getAnalysisResults() {
120 return Collections.unmodifiableList(analysisResults);
128 Optional<AnalysisResult> getSelectedResult() {
129 return selectedResult;
137 Optional<Score> getAggregateScore() {
138 return aggregateScore;
148 Optional<Content> getContent() {
162 return (originalAttrStr == null) ?
"" : originalAttrStr.trim();
173 "AnalysisResultsViewModel_displayAttributes_score=Score",
174 "AnalysisResultsViewModel_displayAttributes_type=Type",
175 "AnalysisResultsViewModel_displayAttributes_configuration=Configuration",
176 "AnalysisResultsViewModel_displayAttributes_conclusion=Conclusion"
182 type =
normalizeAttr(analysisResult.getType().getDisplayName());
183 }
catch (TskCoreException ex) {
184 logger.log(Level.SEVERE,
"Unable to get type for analysis result with id: " + analysisResult.getArtifactID(), ex);
188 Stream<Pair<String, String>> baseAnalysisAttrs = Stream.of(
189 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_score(),
190 normalizeAttr(analysisResult.getScore().getSignificance().getDisplayName())),
191 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_type(),
193 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_configuration(),
195 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_conclusion(),
200 Stream<Pair<String, String>> blackboardAttributes = Stream.empty();
203 blackboardAttributes = analysisResult.getAttributes().stream()
204 .filter(attr -> attr != null && attr.getAttributeType() != null && attr.getAttributeType().getDisplayName() != null)
205 .map(attr -> Pair.of(attr.getAttributeType().getDisplayName(),
normalizeAttr(attr.getDisplayString())))
206 .sorted((a, b) -> a.getKey().compareToIgnoreCase(b.getKey()));
207 }
catch (TskCoreException ex) {
208 logger.log(Level.SEVERE,
"Unable to get attributes for analysis result with id: " + analysisResult.getArtifactID(), ex);
212 List<Pair<String, String>> allDisplayAttributes = Stream.concat(baseAnalysisAttrs, blackboardAttributes)
213 .collect(Collectors.toList());
215 return new ResultDisplayAttributes(analysisResult, allDisplayAttributes);
219 return analysisResults.stream()
220 .filter(ar -> ar != null && ar.getScore() != null)
222 .sorted((a, b) -> -a.getScore().compareTo(b.getScore()))
224 .collect(Collectors.toList());
235 NodeResults getAnalysisResults(Node node) {
237 return new NodeResults(Collections.emptyList(), Optional.empty(), Optional.empty(), Optional.empty());
240 Content analyzedContent = null;
241 AnalysisResult selectedAnalysisResult = null;
242 Score aggregateScore = null;
243 List<AnalysisResult> analysisResults = Collections.emptyList();
244 long selectedObjectId = 0;
246 AnalysisResultItem analysisResultItem = node.getLookup().lookup(AnalysisResultItem.class);
247 if (Objects.nonNull(analysisResultItem)) {
254 selectedAnalysisResult = analysisResultItem.getTskContent();
255 selectedObjectId = selectedAnalysisResult.getId();
256 analyzedContent = selectedAnalysisResult.getParent();
263 TskContentItem<?> contentItem = node.getLookup().lookup(TskContentItem.class);
264 analyzedContent = contentItem.getTskContent();
265 selectedObjectId = analyzedContent.getId();
267 aggregateScore = analyzedContent.getAggregateScore();
268 analysisResults = analyzedContent.getAllAnalysisResults();
269 }
catch (TskCoreException ex) {
270 logger.log(Level.SEVERE, String.format(
"Error getting analysis result data for selected Content (object ID=%d)", selectedObjectId), ex);
277 return new NodeResults(displayAttributes, Optional.ofNullable(selectedAnalysisResult), Optional.ofNullable(aggregateScore), Optional.ofNullable(analyzedContent));
String normalizeAttr(String originalAttrStr)
ResultDisplayAttributes getDisplayAttributes(AnalysisResult analysisResult)
List< ResultDisplayAttributes > getOrderedDisplayAttributes(Collection< AnalysisResult > analysisResults)
static final Logger logger