Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractContentNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-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.datamodel;
20 
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.List;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import java.util.logging.Level;
28 import javax.swing.SwingUtilities;
29 import org.apache.commons.lang3.tuple.Pair;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.lookup.Lookups;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35 import org.openide.util.NbBundle.Messages;
41 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.Score;
44 import org.sleuthkit.datamodel.SleuthkitCase;
45 import org.sleuthkit.datamodel.Tag;
46 import org.sleuthkit.datamodel.TskCoreException;
47 import org.sleuthkit.datamodel.TskData;
48 import org.sleuthkit.datamodel.TskException;
49 
56 public abstract class AbstractContentNode<T extends Content> extends ContentNode {
57 
61  protected final T content;
62  private static final Logger logger = Logger.getLogger(AbstractContentNode.class.getName());
63 
68  static final ExecutorService backgroundTasksPool;
69  private static final Integer MAX_POOL_SIZE = 10;
70 
74  @NbBundle.Messages({"AbstractContentNode.nodescription=no description",
75  "AbstractContentNode.valueLoading=value loading"})
76  protected static final String NO_DESCR = Bundle.AbstractContentNode_nodescription();
77  protected static final String VALUE_LOADING = Bundle.AbstractContentNode_valueLoading();
78 
85  enum NodeSpecificEvents {
86  TRANSLATION_AVAILABLE,
87  SCO_AVAILABLE
88  }
89 
90  static {
91  //Initialize this pool only once! This will be used by every instance of AAFN
92  //to do their heavy duty SCO column and translation updates.
93  backgroundTasksPool = Executors.newFixedThreadPool(MAX_POOL_SIZE,
94  new ThreadFactoryBuilder().setNameFormat("content-node-background-task-%d").build());
95  }
96 
102  AbstractContentNode(T content) {
103  this(content, Lookups.fixed(content, new TskContentItem<>(content)));
104  }
105 
112  AbstractContentNode(T content, Lookup lookup) {
113  super(Children.create(new ContentChildren(content), true), lookup);
114  this.content = content;
115  //super.setName(ContentUtils.getSystemName(content));
116  super.setName("content_" + Long.toString(content.getId())); //NON-NLS
117  }
118 
124  public T getContent() {
125  return content;
126  }
127 
128  @Override
129  public void setName(String name) {
130  super.setName(name);
131  }
132 
133  @Override
134  public String getName() {
135  return super.getName();
136  }
137 
144  public boolean hasVisibleContentChildren() {
145  return contentHasVisibleContentChildren(content);
146  }
147 
156  public static boolean contentHasVisibleContentChildren(Content c) {
157  if (c != null) {
158 
159  try {
160  if (!c.hasChildren()) {
161  return false;
162  }
163  } catch (TskCoreException ex) {
164 
165  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
166  return false;
167  }
168 
169  String query = "SELECT COUNT(obj_id) AS count FROM "
170  + " ( SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId() + " AND type = "
171  + TskData.ObjectType.ARTIFACT.getObjectType()
172  + " INTERSECT SELECT artifact_obj_id FROM blackboard_artifacts WHERE obj_id = " + c.getId()
173  + " AND (artifact_type_id = " + ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
174  + " OR artifact_type_id = " + ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() + ") "
175  + " UNION SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId()
176  + " AND type = " + TskData.ObjectType.ABSTRACTFILE.getObjectType() + ") AS OBJECT_IDS"; //NON-NLS;
177 
178  try (SleuthkitCase.CaseDbQuery dbQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query)) {
179  ResultSet resultSet = dbQuery.getResultSet();
180  if (resultSet.next()) {
181  return (0 < resultSet.getInt("count"));
182  }
183  } catch (TskCoreException | SQLException | NoCurrentCaseException ex) {
184  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
185  }
186  }
187  return false;
188  }
189 
196  public boolean hasContentChildren() {
197  boolean hasChildren = false;
198 
199  if (content != null) {
200  try {
201  hasChildren = content.hasChildren();
202  } catch (TskCoreException ex) {
203  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + content, ex); //NON-NLS
204  }
205  }
206 
207  return hasChildren;
208  }
209 
216  public List<Long> getContentChildrenIds() {
217  List<Long> childrenIds = null;
218 
219  if (content != null) {
220  try {
221  childrenIds = content.getChildrenIds();
222  } catch (TskCoreException ex) {
223  logger.log(Level.SEVERE, "Error getting children ids, for content: " + content, ex); //NON-NLS
224  }
225  }
226 
227  return childrenIds;
228 
229  }
230 
236  public List<Content> getContentChildren() {
237  List<Content> children = null;
238 
239  if (content != null) {
240  try {
241  children = content.getChildren();
242  } catch (TskCoreException ex) {
243  logger.log(Level.SEVERE, "Error getting children, for content: " + content, ex); //NON-NLS
244  }
245  }
246 
247  return children;
248 
249  }
250 
258  public int getContentChildrenCount() {
259  int childrenCount = -1;
260 
261  if (content != null) {
262  try {
263  childrenCount = content.getChildrenCount();
264  } catch (TskCoreException ex) {
265  logger.log(Level.SEVERE, "Error checking node content children count, for content: " + content, ex); //NON-NLS
266  }
267  }
268 
269  return childrenCount;
270  }
271 
284  public int read(byte[] buf, long offset, long len) throws TskException {
285  return content.read(buf, offset, len);
286  }
287 
301  protected synchronized void updateSheet(NodeProperty<?>... newProps) {
302  SwingUtilities.invokeLater(() -> {
303  /*
304  * Refresh ONLY those properties in the sheet currently. Subclasses
305  * may have only added a subset of our properties or their own
306  * properties.
307  */
308  Sheet visibleSheet = this.getSheet();
309  Sheet.Set visibleSheetSet = visibleSheet.get(Sheet.PROPERTIES);
310  Property<?>[] visibleProps = visibleSheetSet.getProperties();
311  for (NodeProperty<?> newProp : newProps) {
312  for (int i = 0; i < visibleProps.length; i++) {
313  if (visibleProps[i].getName().equals(newProp.getName())) {
314  visibleProps[i] = newProp;
315  }
316  }
317  }
318  visibleSheetSet.put(visibleProps);
319  visibleSheet.put(visibleSheetSet);
320  //setSheet() will notify Netbeans to update this node in the UI.
321  this.setSheet(visibleSheet);
322  });
323  }
324 
330  abstract protected List<Tag> getAllTagsFromDatabase();
331 
337  @Messages({
338  "# {0} - significanceDisplayName",
339  "AbstractContentNode_getScorePropertyAndDescription_description=Has an {0} analysis result score"
340  })
341  protected Pair<Score, String> getScorePropertyAndDescription() {
342  Score score = Score.SCORE_UNKNOWN;
343  try {
344  score = this.content.getAggregateScore();
345  } catch (TskCoreException ex) {
346  logger.log(Level.WARNING, "Unable to get aggregate score for content with id: " + this.content.getId(), ex);
347  }
348 
349  String significanceDisplay = score.getSignificance().getDisplayName();
350  String description = Bundle.AbstractContentNode_getScorePropertyAndDescription_description(significanceDisplay);
351  return Pair.of(score, description);
352  }
353 
364  protected DataResultViewerTable.HasCommentStatus getCommentProperty(List<Tag> tags, List<CorrelationAttributeInstance> attributes) {
366  }
367 
380  protected Pair<Long, String> getCountPropertyAndDescription(CorrelationAttributeInstance attribute, String defaultDescription) {
381  return Pair.of(-1L, NO_DESCR);
382  }
383 }
synchronized void updateSheet(NodeProperty<?>...newProps)
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance attribute, String defaultDescription)
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, List< CorrelationAttributeInstance > attributes)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.