Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AnalysisResultsContentViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers.analysisresults;
20 
21 import java.awt.Component;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import javax.swing.SwingWorker;
25 import org.openide.nodes.Node;
26 import org.openide.util.NbBundle;
27 import org.openide.util.lookup.ServiceProvider;
33 import org.sleuthkit.datamodel.AnalysisResult;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 @ServiceProvider(service = DataContentViewer.class, position = 7)
43  private static final Logger logger = Logger.getLogger(AnalysisResultsContentPanel.class.getName());
44 
45  // isPreferred value
46  private static final int PREFERRED_VALUE = 3;
47 
48  private final AnalysisResultsViewModel viewModel = new AnalysisResultsViewModel();
50 
51  private SwingWorker<?, ?> worker = null;
52 
53 
54 
55  @NbBundle.Messages({
56  "AnalysisResultsContentViewer_title=Analysis Results"
57  })
58  @Override
59  public String getTitle() {
60  return Bundle.AnalysisResultsContentViewer_title();
61  }
62 
63  @NbBundle.Messages({
64  "AnalysisResultsContentViewer_tooltip=Viewer for Analysis Results related to the selected node."
65  })
66  @Override
67  public String getToolTip() {
68  return Bundle.AnalysisResultsContentViewer_tooltip();
69  }
70 
71  @Override
72  public DataContentViewer createInstance() {
73  return new AnalysisResultsContentViewer();
74  }
75 
76  @Override
77  public Component getComponent() {
78  return panel;
79  }
80 
81  @Override
82  public void resetComponent() {
83  panel.reset();
84  }
85 
86  @Override
87  @NbBundle.Messages({
88  "AnalysisResultsContentViewer_setNode_loadingMessage=Loading...",
89  "AnalysisResultsContentViewer_setNode_errorMessage=There was an error loading results.",})
90  public synchronized void setNode(Node node) {
91  // reset the panel
92  panel.reset();
93 
94  // if there is a worker running, cancel it
95  if (worker != null) {
96  worker.cancel(true);
97  worker = null;
98  }
99 
100  // if no node, nothing to do
101  if (node == null) {
102  return;
103  }
104 
105  // show a loading message
106  panel.showMessage(Bundle.AnalysisResultsContentViewer_setNode_loadingMessage());
107 
108  // create the worker
109  worker = new DataFetchWorker<>(
110  // load a view model from the node
111  (selectedNode) -> viewModel.getAnalysisResults(selectedNode),
112  (nodeAnalysisResults) -> {
113  if (nodeAnalysisResults.getResultType() == DataFetchResult.ResultType.SUCCESS) {
114  // if successful, display the results
115  panel.displayResults(nodeAnalysisResults.getData());
116  } else {
117  // if there was an error, display an error message
118  panel.showMessage(Bundle.AnalysisResultsContentViewer_setNode_errorMessage());
119  }
120  },
121  node);
122 
123  // kick off the swing worker
124  worker.execute();
125  }
126 
127  @Override
128  public boolean isSupported(Node node) {
129  if (node == null) {
130  return false;
131  }
132 
133  // There needs to either be a file with an AnalysisResult or an AnalysisResult in the lookup.
134  for (Content content : node.getLookup().lookupAll(Content.class)) {
135  if (content instanceof AnalysisResult) {
136  return true;
137  }
138 
139  if (content == null || content instanceof BlackboardArtifact) {
140  continue;
141  }
142 
143  try {
144  if (Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard().hasAnalysisResults(content.getId())) {
145  return true;
146  }
147  } catch (NoCurrentCaseException | TskCoreException ex) {
148  logger.log(Level.SEVERE, "Unable to get analysis results for file with obj id " + content.getId(), ex);
149  }
150  }
151 
152  return false;
153  }
154 
155  @Override
156  public int isPreferred(Node node) {
157  return PREFERRED_VALUE;
158  }
159 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.