19 package org.sleuthkit.datamodel;
 
   21 import com.google.common.collect.ImmutableSet;
 
   22 import java.sql.ResultSet;
 
   23 import java.sql.SQLException;
 
   24 import java.sql.Statement;
 
   25 import java.util.ArrayList;
 
   26 import java.util.Arrays;
 
   27 import java.util.Collection;
 
   28 import java.util.Collections;
 
   29 import java.util.HashSet;
 
   30 import java.util.List;
 
   31 import java.util.Objects;
 
   33 import java.util.stream.Collectors;
 
   50                 this.caseDb = Objects.requireNonNull(casedb, 
"Cannot create Blackboard for null SleuthkitCase");
 
  167                 final String queryString = 
"SELECT DISTINCT arts.artifact_type_id AS artifact_type_id, " 
  168                                 + 
"types.type_name AS type_name, types.display_name AS display_name " 
  169                                 + 
"FROM blackboard_artifact_types AS types " 
  170                                 + 
"INNER JOIN blackboard_artifacts AS arts " 
  171                                 + 
"ON arts.artifact_type_id = types.artifact_type_id " 
  172                                 + 
"WHERE arts.data_source_obj_id = " + dataSourceObjId;
 
  176                                 Statement statement = connection.createStatement();
 
  177                                 ResultSet resultSet = connection.executeQuery(statement, queryString);) {
 
  180                         while (resultSet.next()) {
 
  182                                                 resultSet.getString(
"type_name"), resultSet.getString(
"display_name")));
 
  184                         return uniqueArtifactTypes;
 
  185                 } 
catch (SQLException ex) {
 
  186                         throw new TskCoreException(
"Error getting artifact types is use for data source." + ex.getMessage(), ex);
 
  205                 return getArtifactsCountHelper(artifactTypeID,
 
  206                                 "blackboard_artifacts.data_source_obj_id = '" + dataSourceObjId + 
"';");
 
  222                 return caseDb.getArtifactsHelper(
"blackboard_artifacts.data_source_obj_id = " + dataSourceObjId
 
  223                                 + 
" AND blackboard_artifact_types.artifact_type_id = " + artifactTypeID + 
";");
 
  238         private long getArtifactsCountHelper(
int artifactTypeID, String whereClause) 
throws TskCoreException {
 
  239                 String queryString = 
"SELECT COUNT(*) AS count FROM blackboard_artifacts " 
  240                                 + 
"WHERE blackboard_artifacts.artifact_type_id = " + artifactTypeID
 
  242                                 + 
" AND " + whereClause;
 
  246                                 Statement statement = connection.createStatement();
 
  247                                 ResultSet resultSet = connection.executeQuery(statement, queryString);) {
 
  250                         if (resultSet.next()) {
 
  251                                 count = resultSet.getLong(
"count");
 
  254                 } 
catch (SQLException ex) {
 
  255                         throw new TskCoreException(
"Error getting artifact types is use for data source." + ex.getMessage(), ex);
 
  277                 ArrayList<BlackboardArtifact> artifactsList;
 
  282                 artifactsList = content.getArtifacts(artifactType);
 
  283                 if (artifactsList.isEmpty()) {
 
  291                         if (attributesMatch(artifact.getAttributes(), attributesList)) {
 
  317         private boolean attributesMatch(Collection<BlackboardAttribute> fileAttributesList, Collection<BlackboardAttribute> expectedAttributesList) {
 
  319                         boolean match = 
false;
 
  323                                 if (attributeType.getTypeID() != expectedAttribute.getAttributeType().getTypeID()) {
 
  327                                 Object fileAttributeValue;
 
  328                                 Object expectedAttributeValue;
 
  329                                 switch (attributeType.getValueType()) {
 
  331                                                 fileAttributeValue = fileAttribute.getValueBytes();
 
  332                                                 expectedAttributeValue = expectedAttribute.getValueBytes();
 
  335                                                 fileAttributeValue = fileAttribute.getValueDouble();
 
  336                                                 expectedAttributeValue = expectedAttribute.getValueDouble();
 
  339                                                 fileAttributeValue = fileAttribute.getValueInt();
 
  340                                                 expectedAttributeValue = expectedAttribute.getValueInt();
 
  344                                                 fileAttributeValue = fileAttribute.getValueLong();
 
  345                                                 expectedAttributeValue = expectedAttribute.getValueLong();
 
  349                                                 fileAttributeValue = fileAttribute.getValueString();
 
  350                                                 expectedAttributeValue = expectedAttribute.getValueString();
 
  353                                                 fileAttributeValue = fileAttribute.getDisplayString();
 
  354                                                 expectedAttributeValue = expectedAttribute.getDisplayString();
 
  362                                 if (fileAttributeValue instanceof byte[]) {
 
  363                                         if (Arrays.equals((byte[]) fileAttributeValue, (byte[]) expectedAttributeValue)) {
 
  367                                 } 
else if (fileAttributeValue.equals(expectedAttributeValue)) {
 
  393                 private static final long serialVersionUID = 1L;
 
  412                         super(message, cause);
 
  423                 private final String moduleName;
 
  425                 private final ImmutableSet<BlackboardArtifact> artifacts;
 
  428                         Set<Integer> typeIDS = artifacts.stream()
 
  430                                         .collect(Collectors.toSet());
 
  432                         for (Integer typeID : typeIDS) {
 
  439                         artifactTypes = ImmutableSet.copyOf(types);
 
  440                         this.artifacts = ImmutableSet.copyOf(artifacts);
 
  441                         this.moduleName = moduleName;
 
  450                         Set<BlackboardArtifact> tempSet = artifacts.stream()
 
  451                                         .filter(artifact -> artifact.getArtifactTypeID() == artifactType.getTypeID())
 
  452                                         .collect(Collectors.toSet());
 
  453                         return ImmutableSet.copyOf(tempSet);
 
  461                         return artifactTypes;
 
void postArtifact(BlackboardArtifact artifact, String moduleName)
 
void postArtifacts(Collection< BlackboardArtifact > artifacts, String moduleName)
 
Collection< BlackboardArtifact > getArtifacts()
 
Collection< BlackboardArtifact > getArtifacts(BlackboardArtifact.Type artifactType)
 
BlackboardAttribute.Type addArtifactAttributeType(String attrTypeString, TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String displayName)
 
BlackboardAttribute.Type getOrAddAttributeType(String typeName, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String displayName)
 
List< BlackboardArtifact > getArtifacts(int artifactTypeID, long dataSourceObjId)
 
TimelineManager getTimelineManager()
 
void releaseSingleUserCaseReadLock()
 
BlackboardAttribute.Type getAttributeType(String attrTypeName)
 
BlackboardArtifact.Type getArtifactType(String artTypeName)
 
boolean artifactExists(Content content, BlackboardArtifact.ARTIFACT_TYPE artifactType, Collection< BlackboardAttribute > attributesList)
 
Collection< BlackboardArtifact.Type > getArtifactTypes()
 
BlackboardArtifact.Type getOrAddArtifactType(String typeName, String displayName)
 
void acquireSingleUserCaseReadLock()
 
long getArtifactsCount(int artifactTypeID, long dataSourceObjId)
 
List< BlackboardArtifact.Type > getArtifactTypesInUse(long dataSourceObjId)
 
BlackboardArtifact.Type addBlackboardArtifactType(String artifactTypeName, String displayName)