19package org.sleuthkit.datamodel;
21import com.google.common.annotations.Beta;
22import java.util.ArrayList;
23import java.util.Collection;
24import java.util.Collections;
25import java.util.HashSet;
27import java.util.Optional;
29import java.util.logging.Level;
30import java.util.logging.Logger;
31import org.sleuthkit.datamodel.Blackboard.BlackboardException;
32import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
33import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
34import org.sleuthkit.datamodel.SleuthkitCase.CaseDbConnection;
35import org.sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction;
36import org.sleuthkit.datamodel.SleuthkitCase.ObjectInfo;
47 private final long objId;
48 private final String name;
49 private volatile Content parent;
50 private volatile String uniquePath;
52 private volatile boolean hasChildren;
53 private volatile boolean checkedHasChildren;
54 private volatile int childrenCount;
63 checkedHasChildren =
false;
82 if (uniquePath ==
null) {
83 String tempUniquePath =
"";
84 if (!name.isEmpty()) {
85 tempUniquePath =
"/" +
getName();
89 if (myParent !=
null) {
94 uniquePath = tempUniquePath;
101 if (checkedHasChildren ==
true) {
106 checkedHasChildren =
true;
113 if (childrenCount != -1) {
114 return childrenCount;
119 hasChildren = childrenCount > 0;
120 checkedHasChildren =
true;
122 return childrenCount;
129 if (parent ==
null) {
131 if (!parentIdOpt.isPresent()) {
134 parent = db.getContentById(parentIdOpt.get());
140 void setParent(
Content parent) {
141 this.parent = parent;
155 ObjectInfo parentInfo = db.getParentInfo(
this);
156 if (parentInfo !=
null) {
192 List<Content> children =
new ArrayList<Content>();
213 List<Long> childrenIDs =
new ArrayList<Long>();
216 childrenIDs.addAll(
getSleuthkitCase().getBlackboardArtifactChildrenIds(
this));
225 if (myParent ==
null) {
240 return getPool() !=
null;
251 Volume getPoolVolume() throws TskCoreException {
253 if (myParent ==
null) {
261 if (myParent instanceof Volume) {
263 if (((Volume) myParent).isPoolContent()) {
264 return (Volume) myParent;
282 Pool getPool() throws TskCoreException {
284 if (myParent ==
null) {
292 if (myParent instanceof Pool) {
293 return (Pool) myParent;
314 if (getClass() != obj.getClass()) {
318 if (this.objId != other.objId) {
329 Logger.getLogger(
AbstractContent.class.getName()).log(Level.SEVERE,
null, ex);
337 int hash = 7 + (int) (this.objId ^ (this.objId >>> 32));
340 }
catch (TskCoreException ex) {
341 Logger.getLogger(
AbstractContent.class.getName()).log(Level.SEVERE,
null, ex);
354 switch (artifactType.getCategory()) {
357 case ANALYSIS_RESULT: {
362 throw new TskCoreException(String.format(
"Unknown category: %s for artifact type id: %d",
363 artifactType.getCategory().getName(), artifactTypeID));
373 AnalysisResultAdded resultAdded = db.getBlackboard().newAnalysisResult(artifactType, objId, dataSourceObjectId, score, conclusion, configuration, justification, attributesList, trans);
379 throw new TskCoreException(String.format(
"Error adding analysis result to content with objId = %d.", objId), ex);
386 long dataSourceObjectId = dataSourceId;
389 AnalysisResultAdded resultAdded = db.getBlackboard().newAnalysisResult(artifactType, objId, dataSourceObjectId, score, conclusion, configuration, justification, attributesList, trans);
395 throw new TskCoreException(String.format(
"Error adding analysis result to content with objId = %d.", objId), ex);
401 return db.getBlackboard().newDataArtifact(artifactType, objId, this.
getDataSource().
getId(), attributesList, osAccountId);
406 return db.getBlackboard().newDataArtifact(artifactType, objId, dataSourceId, attributesList, osAccountId);
415 @SuppressWarnings(
"deprecation")
423 return getArtifacts(db.getBlackboard().getArtifactType(artifactTypeName).getTypeID());
429 if (genInfoArtifact ==
null)
434 ArrayList<BlackboardArtifact> list =
new ArrayList<BlackboardArtifact>();
436 if (genInfoArtifact !=
null) {
437 list.add(genInfoArtifact);
441 return db.getBlackboardArtifacts(artifactTypeID, objId);
456 if (genInfoArtifact !=
null) {
457 return genInfoArtifact;
463 if (arts.isEmpty()) {
470 retArt = arts.get(0);
472 genInfoArtifact = retArt;
478 ArrayList<BlackboardAttribute> returnList =
new ArrayList<BlackboardAttribute>();
480 if (genInfoArtifact ==
null) {
482 if (genInfoArtifact ==
null) {
488 if (attribute.getAttributeType().getTypeID() == attr_type.getTypeID()) {
489 returnList.add(attribute);
498 return db.getMatchingArtifacts(
"WHERE obj_id = " + objId);
503 return db.getBlackboard().getAnalysisResults(objId);
508 return db.getBlackboard().getDataArtifactsBySource(objId);
513 return db.getScoringManager().getAggregateScore(objId);
518 return db.getBlackboard().getAnalysisResults(objId, artifactType.getTypeID());
523 return db.getBlackboardArtifactsCount(artifactTypeName, objId);
528 return db.getBlackboardArtifactsCount(artifactTypeID, objId);
533 return db.getBlackboardArtifactsCount(type, objId);
538 return db.getBlackboardArtifactsCount(objId);
543 Set<String> hashNames =
new HashSet<String>();
548 if (attribute !=
null) {
552 return Collections.unmodifiableSet(hashNames);
562 return "AbstractContent [\t" +
"objId " + String.format(
"%010d", objId) +
"\t"
563 +
"name " + name +
"\t" +
"parentId " +
parentId +
"\t"
564 +
"\t" +
"checkedHasChildren " + checkedHasChildren
565 +
"\t" +
"hasChildren " + hasChildren
566 +
"\t" +
"childrenCount " + childrenCount
567 +
"uniquePath " + uniquePath +
"]\t";
571 return "AbstractContent [\t" +
"objId " + String.format(
"%010d", objId)
572 +
"\t" +
"name " + name
573 +
"\t" +
"checkedHasChildren " + checkedHasChildren
574 +
"\t" +
"hasChildren " + hasChildren
575 +
"\t" +
"childrenCount " + childrenCount
579 return "AbstractContent [\t" +
"objId "
580 + String.format(
"%010d", objId) +
"\t" +
"name " + name
581 +
"\t" +
"checkedHasChildren " + checkedHasChildren
582 +
"\t" +
"hasChildren " + hasChildren
583 +
"\t" +
"childrenCount " + childrenCount
585 +
"\t" +
"parentId " +
parentId +
"]\t";
588 Logger.getLogger(
AbstractContent.class.getName()).log(Level.SEVERE,
"Could not find Parent", ex);
589 return "AbstractContent [\t" +
"objId " + String.format(
"%010d", objId) +
"\t"
590 +
"name " + name +
"\t" +
"parentId " +
parentId +
"\t"
591 +
"\t" +
"checkedHasChildren " + checkedHasChildren
592 +
"\t" +
"hasChildren " + hasChildren
593 +
"\t" +
"childrenCount " + childrenCount
594 +
"uniquePath " + uniquePath +
"]\t";
ArrayList< BlackboardArtifact > getAllArtifacts()
List< DataArtifact > getAllDataArtifacts()
long getArtifactsCount(String artifactTypeName)
static final long UNKNOWN_ID
Set< String > getHashSetNames()
AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactType, Score score, String conclusion, String configuration, String justification, Collection< BlackboardAttribute > attributesList, long dataSourceId)
AbstractContent(SleuthkitCase db, long obj_id, String name)
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList, Long osAccountId, long dataSourceId)
AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactType, Score score, String conclusion, String configuration, String justification, Collection< BlackboardAttribute > attributesList)
BlackboardArtifact getGenInfoArtifact(boolean create)
List< Content > getChildren()
long getAllArtifactsCount()
String toString(boolean preserveState)
long getArtifactsCount(ARTIFACT_TYPE type)
BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type)
Optional< Long > getParentId()
ArrayList< BlackboardArtifact > getArtifacts(String artifactTypeName)
BlackboardArtifact getGenInfoArtifact()
List< AnalysisResult > getAllAnalysisResults()
boolean equals(Object obj)
List< AnalysisResult > getAnalysisResults(BlackboardArtifact.Type artifactType)
List< Long > getChildrenIds()
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList, Long osAccountId)
Score getAggregateScore()
BlackboardArtifact newArtifact(int artifactTypeID)
ArrayList< BlackboardAttribute > getGenInfoAttributes(ATTRIBUTE_TYPE attr_type)
ArrayList< BlackboardArtifact > getArtifacts(int artifactTypeID)
SleuthkitCase getSleuthkitCase()
ArrayList< BlackboardArtifact > getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type)
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList)
long getArtifactsCount(int artifactTypeID)
AnalysisResult getAnalysisResult()
static final Score SCORE_UNKNOWN