Autopsy  4.13.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;
41 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.SleuthkitCase;
44 import org.sleuthkit.datamodel.Tag;
45 import org.sleuthkit.datamodel.TskCoreException;
46 import org.sleuthkit.datamodel.TskData;
47 import org.sleuthkit.datamodel.TskException;
48 
55 public abstract class AbstractContentNode<T extends Content> extends ContentNode {
56 
60  T content;
61  private static final Logger logger = Logger.getLogger(AbstractContentNode.class.getName());
62 
67  static final ExecutorService backgroundTasksPool;
68  private static final Integer MAX_POOL_SIZE = 10;
69 
73  @NbBundle.Messages({"AbstractContentNode.nodescription=no description",
74  "AbstractContentNode.valueLoading=value loading"})
75  protected static final String NO_DESCR = Bundle.AbstractContentNode_nodescription();
76  protected static final String VALUE_LOADING = Bundle.AbstractContentNode_valueLoading();
77 
84  enum NodeSpecificEvents {
85  TRANSLATION_AVAILABLE,
86  SCO_AVAILABLE
87  }
88 
89  static {
90  //Initialize this pool only once! This will be used by every instance of AAFN
91  //to do their heavy duty SCO column and translation updates.
92  backgroundTasksPool = Executors.newFixedThreadPool(MAX_POOL_SIZE,
93  new ThreadFactoryBuilder().setNameFormat("content-node-background-task-%d").build());
94  }
95 
101  AbstractContentNode(T content) {
102  this(content, Lookups.singleton(content));
103  }
104 
111  AbstractContentNode(T content, Lookup lookup) {
112  super(Children.create(new ContentChildren(content), false), lookup);
113  this.content = content;
114  //super.setName(ContentUtils.getSystemName(content));
115  super.setName("content_" + Long.toString(content.getId())); //NON-NLS
116  }
117 
123  public T getContent() {
124  return content;
125  }
126 
127  @Override
128  public void setName(String name) {
129  super.setName(name);
130  }
131 
132  @Override
133  public String getName() {
134  return super.getName();
135  }
136 
143  public boolean hasVisibleContentChildren() {
144  return contentHasVisibleContentChildren(content);
145  }
146 
155  public static boolean contentHasVisibleContentChildren(Content c) {
156  if (c != null) {
157 
158  try {
159  if (!c.hasChildren()) {
160  return false;
161  }
162  } catch (TskCoreException ex) {
163 
164  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
165  return false;
166  }
167 
168  String query = "SELECT COUNT(obj_id) AS count FROM "
169  + " ( SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId() + " AND type = "
170  + TskData.ObjectType.ARTIFACT.getObjectType()
171  + " INTERSECT SELECT artifact_obj_id FROM blackboard_artifacts WHERE obj_id = " + c.getId()
172  + " AND (artifact_type_id = " + ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
173  + " OR artifact_type_id = " + ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() + ") "
174  + " UNION SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId()
175  + " AND type = " + TskData.ObjectType.ABSTRACTFILE.getObjectType() + ") AS OBJECT_IDS"; //NON-NLS;
176 
177  try (SleuthkitCase.CaseDbQuery dbQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query)) {
178  ResultSet resultSet = dbQuery.getResultSet();
179  if (resultSet.next()) {
180  return (0 < resultSet.getInt("count"));
181  }
182  } catch (TskCoreException | SQLException | NoCurrentCaseException ex) {
183  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
184  }
185  }
186  return false;
187  }
188 
195  public boolean hasContentChildren() {
196  boolean hasChildren = false;
197 
198  if (content != null) {
199  try {
200  hasChildren = content.hasChildren();
201  } catch (TskCoreException ex) {
202  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + content, ex); //NON-NLS
203  }
204  }
205 
206  return hasChildren;
207  }
208 
215  public List<Long> getContentChildrenIds() {
216  List<Long> childrenIds = null;
217 
218  if (content != null) {
219  try {
220  childrenIds = content.getChildrenIds();
221  } catch (TskCoreException ex) {
222  logger.log(Level.SEVERE, "Error getting children ids, for content: " + content, ex); //NON-NLS
223  }
224  }
225 
226  return childrenIds;
227 
228  }
229 
235  public List<Content> getContentChildren() {
236  List<Content> children = null;
237 
238  if (content != null) {
239  try {
240  children = content.getChildren();
241  } catch (TskCoreException ex) {
242  logger.log(Level.SEVERE, "Error getting children, for content: " + content, ex); //NON-NLS
243  }
244  }
245 
246  return children;
247 
248  }
249 
257  public int getContentChildrenCount() {
258  int childrenCount = -1;
259 
260  if (content != null) {
261  try {
262  childrenCount = content.getChildrenCount();
263  } catch (TskCoreException ex) {
264  logger.log(Level.SEVERE, "Error checking node content children count, for content: " + content, ex); //NON-NLS
265  }
266  }
267 
268  return childrenCount;
269  }
270 
283  public int read(byte[] buf, long offset, long len) throws TskException {
284  return content.read(buf, offset, len);
285  }
286 
300  protected synchronized void updateSheet(NodeProperty<?>... newProps) {
301  //Refresh ONLY those properties in the sheet currently. Subclasses may have
302  //only added a subset of our properties or their own props.s
303  Sheet visibleSheet = this.getSheet();
304  Sheet.Set visibleSheetSet = visibleSheet.get(Sheet.PROPERTIES);
305  Property<?>[] visibleProps = visibleSheetSet.getProperties();
306  for (NodeProperty<?> newProp : newProps) {
307  for (int i = 0; i < visibleProps.length; i++) {
308  if (visibleProps[i].getName().equals(newProp.getName())) {
309  visibleProps[i] = newProp;
310  }
311  }
312  }
313  visibleSheetSet.put(visibleProps);
314  visibleSheet.put(visibleSheetSet);
315  //setSheet() will notify Netbeans to update this node in the UI.
316  this.setSheet(visibleSheet);
317  }
318 
324  abstract protected List<Tag> getAllTagsFromDatabase();
325 
334 
342  abstract protected Pair<DataResultViewerTable.Score, String> getScorePropertyAndDescription(List<Tag> tags);
343 
352  abstract protected DataResultViewerTable.HasCommentStatus getCommentProperty(List<Tag> tags, CorrelationAttributeInstance attribute);
353 
364  abstract protected Pair<Long, String> getCountPropertyAndDescription(Type attributeType, String attributeValue, String defaultDescription);
365 }
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)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
abstract Pair< DataResultViewerTable.Score, String > getScorePropertyAndDescription(List< Tag > tags)

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.