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

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