19package org.sleuthkit.autopsy.datamodel;
21import com.google.common.util.concurrent.ThreadFactoryBuilder;
22import java.sql.ResultSet;
23import java.sql.SQLException;
25import java.util.concurrent.ExecutorService;
26import java.util.concurrent.Executors;
27import java.util.logging.Level;
28import javax.swing.SwingUtilities;
29import org.apache.commons.lang3.tuple.Pair;
30import org.openide.nodes.Children;
31import org.openide.nodes.Sheet;
32import org.openide.util.lookup.Lookups;
33import org.openide.util.Lookup;
34import org.openide.util.NbBundle;
35import org.openide.util.NbBundle.Messages;
36import org.sleuthkit.autopsy.casemodule.Case;
37import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
38import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance;
39import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable;
40import org.sleuthkit.autopsy.coreutils.Logger;
41import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
42import org.sleuthkit.datamodel.Content;
43import org.sleuthkit.datamodel.Score;
44import org.sleuthkit.datamodel.SleuthkitCase;
45import org.sleuthkit.datamodel.Tag;
46import org.sleuthkit.datamodel.TskCoreException;
47import org.sleuthkit.datamodel.TskData;
48import org.sleuthkit.datamodel.TskException;
56public abstract class AbstractContentNode<T
extends Content> extends ContentNode {
68 static final ExecutorService backgroundTasksPool;
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();
93 backgroundTasksPool = Executors.newFixedThreadPool(
MAX_POOL_SIZE,
94 new ThreadFactoryBuilder().setNameFormat(
"content-node-background-task-%d").build());
112 AbstractContentNode(T
content, Lookup lookup) {
113 super(Children.create(
new ContentChildren(
content),
true), lookup);
116 super.setName(
"content_" + Long.toString(
content.getId()));
135 return super.getName();
160 if (!c.hasChildren()) {
163 }
catch (TskCoreException ex) {
165 logger.log(Level.SEVERE,
"Error checking if the node has children, for content: " + c, ex);
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";
179 ResultSet resultSet = dbQuery.getResultSet();
180 if (resultSet.next()) {
181 return (0 < resultSet.getInt(
"count"));
184 logger.log(Level.SEVERE,
"Error checking if the node has children, for content: " + c, ex);
197 boolean hasChildren =
false;
201 hasChildren =
content.hasChildren();
202 }
catch (TskCoreException ex) {
203 logger.log(Level.SEVERE,
"Error checking if the node has children, for content: " +
content, ex);
217 List<Long> childrenIds =
null;
221 childrenIds =
content.getChildrenIds();
222 }
catch (TskCoreException ex) {
223 logger.log(Level.SEVERE,
"Error getting children ids, for content: " +
content, ex);
237 List<Content> children =
null;
241 children =
content.getChildren();
242 }
catch (TskCoreException ex) {
243 logger.log(Level.SEVERE,
"Error getting children, for content: " +
content, ex);
259 int childrenCount = -1;
263 childrenCount =
content.getChildrenCount();
264 }
catch (TskCoreException ex) {
265 logger.log(Level.SEVERE,
"Error checking node content children count, for content: " +
content, ex);
269 return childrenCount;
284 public int read(
byte[] buf,
long offset,
long len)
throws TskException {
285 return content.read(buf, offset, len);
302 SwingUtilities.invokeLater(() -> {
308 Sheet visibleSheet = this.getSheet();
309 Sheet.Set visibleSheetSet = visibleSheet.get(Sheet.PROPERTIES);
310 Property<?>[] visibleProps = visibleSheetSet.getProperties();
312 for (
int i = 0; i < visibleProps.length; i++) {
313 if (visibleProps[i].
getName().equals(newProp.getName())) {
314 visibleProps[i] = newProp;
318 visibleSheetSet.put(visibleProps);
319 visibleSheet.put(visibleSheetSet);
321 this.setSheet(visibleSheet);
338 "# {0} - significanceDisplayName",
339 "AbstractContentNode_getScorePropertyAndDescription_description=Has an {0} analysis result score"
342 Score score = Score.SCORE_UNKNOWN;
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);
349 String significanceDisplay = score.getSignificance().getDisplayName();
350 String description = Bundle.AbstractContentNode_getScorePropertyAndDescription_description(significanceDisplay);
351 return Pair.of(score, description);
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
synchronized static Logger getLogger(String name)
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, List< CorrelationAttributeInstance > attributes)
int read(byte[] buf, long offset, long len)
static final Integer MAX_POOL_SIZE
abstract List< Tag > getAllTagsFromDatabase()
static boolean contentHasVisibleContentChildren(Content c)
static final String NO_DESCR
boolean hasVisibleContentChildren()
static final Logger logger
static final String VALUE_LOADING
synchronized void updateSheet(NodeProperty<?>... newProps)
List< Long > getContentChildrenIds()
List< Content > getContentChildren()
boolean hasContentChildren()
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance attribute, String defaultDescription)
int getContentChildrenCount()
Pair< Score, String > getScorePropertyAndDescription()
void setName(String name)