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;
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 Collections.unmodifiableList(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<String> itemName;
110 NodeResults(List<ResultDisplayAttributes> analysisResults, Optional<AnalysisResult> selectedResult,
111 Optional<Score> aggregateScore, Optional<String> itemName) {
112 this.analysisResults = analysisResults;
113 this.selectedResult = selectedResult;
114 this.aggregateScore = aggregateScore;
115 this.itemName = itemName;
123 List<ResultDisplayAttributes> getAnalysisResults() {
124 return Collections.unmodifiableList(analysisResults);
132 Optional<AnalysisResult> getSelectedResult() {
133 return selectedResult;
141 Optional<Score> getAggregateScore() {
142 return aggregateScore;
150 Optional<String> getItemName() {
164 return (originalAttrStr == null) ?
"" : originalAttrStr.trim();
175 "AnalysisResultsViewModel_displayAttributes_score=Score",
176 "AnalysisResultsViewModel_displayAttributes_type=Type",
177 "AnalysisResultsViewModel_displayAttributes_configuration=Configuration",
178 "AnalysisResultsViewModel_displayAttributes_conclusion=Conclusion"
184 type =
normalizeAttr(analysisResult.getType().getDisplayName());
185 }
catch (TskCoreException ex) {
186 logger.log(Level.SEVERE,
"Unable to get type for analysis result with id: " + analysisResult.getArtifactID(), ex);
190 Stream<Pair<String, String>> baseAnalysisAttrs = Stream.of(
191 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_score(),
192 normalizeAttr(analysisResult.getScore().getSignificance().getDisplayName())),
193 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_type(),
195 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_configuration(),
197 Pair.of(Bundle.AnalysisResultsViewModel_displayAttributes_conclusion(),
202 Stream<Pair<String, String>> blackboardAttributes = Stream.empty();
205 blackboardAttributes = analysisResult.getAttributes().stream()
206 .filter(attr -> attr != null && attr.getAttributeType() != null && attr.getAttributeType().getDisplayName() != null)
207 .map(attr -> Pair.of(attr.getAttributeType().getDisplayName(),
normalizeAttr(attr.getDisplayString())))
208 .sorted((a, b) -> a.getKey().compareToIgnoreCase(b.getKey()));
209 }
catch (TskCoreException ex) {
210 logger.log(Level.SEVERE,
"Unable to get attributes for analysis result with id: " + analysisResult.getArtifactID(), ex);
214 List<Pair<String, String>> allDisplayAttributes = Stream.concat(baseAnalysisAttrs, blackboardAttributes)
215 .collect(Collectors.toList());
217 return new ResultDisplayAttributes(analysisResult, allDisplayAttributes);
221 return analysisResults.stream()
222 .filter(ar -> ar != null && ar.getScore() != null)
224 .sorted((a, b) -> -a.getScore().compareTo(b.getScore()))
226 .collect(Collectors.toList());
238 private String
getName(Content selectedContent)
throws TskCoreException {
239 if (selectedContent == null) {
241 }
else if (selectedContent instanceof BlackboardArtifact) {
242 return ((BlackboardArtifact) selectedContent).getShortDescription();
244 return selectedContent.getName();
256 NodeResults getAnalysisResults(Node node) {
258 return new NodeResults(Collections.emptyList(), Optional.empty(), Optional.empty(), Optional.empty());
261 String contentName = null;
262 AnalysisResult selectedAnalysisResult = null;
263 Score aggregateScore = null;
264 List<AnalysisResult> analysisResults = Collections.emptyList();
265 long selectedObjectId = 0;
267 AnalysisResultItem analysisResultItem = node.getLookup().lookup(AnalysisResultItem.class);
268 Content analyzedContent;
269 if (Objects.nonNull(analysisResultItem)) {
276 selectedAnalysisResult = analysisResultItem.getTskContent();
277 selectedObjectId = selectedAnalysisResult.getId();
278 analyzedContent = selectedAnalysisResult.getParent();
285 TskContentItem<?> contentItem = node.getLookup().lookup(TskContentItem.class);
286 analyzedContent = contentItem.getTskContent();
287 selectedObjectId = analyzedContent.getId();
289 aggregateScore = analyzedContent.getAggregateScore();
290 analysisResults = analyzedContent.getAllAnalysisResults();
291 contentName =
getName(analyzedContent);
293 }
catch (TskCoreException ex) {
294 logger.log(Level.SEVERE, String.format(
"Error getting analysis result data for selected Content (object ID=%d)", selectedObjectId), ex);
301 return new NodeResults(displayAttributes,
302 Optional.ofNullable(selectedAnalysisResult),
303 Optional.ofNullable(aggregateScore),
304 Optional.ofNullable(contentName));
String normalizeAttr(String originalAttrStr)
String getName(Content selectedContent)
ResultDisplayAttributes getDisplayAttributes(AnalysisResult analysisResult)
List< ResultDisplayAttributes > getOrderedDisplayAttributes(Collection< AnalysisResult > analysisResults)
static final Logger logger