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

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.