From 6e485e1167ce51f436e4f891539ada4bde855339 Mon Sep 17 00:00:00 2001 From: millmanorama <millmanorama@gmail.com> Date: Fri, 1 Dec 2017 10:43:45 +0100 Subject: [PATCH] introduce typeID to Relationship.Type and use it in filters and API --- .../datamodel/CaseDbSchemaVersionNumber.java | 2 +- .../sleuthkit/datamodel/CollectionUtils.java | 37 +++++++ .../datamodel/CommunicationsFilter.java | 20 +--- .../datamodel/CommunicationsManager.java | 54 ++++------ .../org/sleuthkit/datamodel/Relationship.java | 102 +++++++++++++----- .../sleuthkit/datamodel/SleuthkitCase.java | 2 +- .../datamodel/CommunicationsManagerTest.java | 86 +++++++-------- 7 files changed, 176 insertions(+), 127 deletions(-) create mode 100644 bindings/java/src/org/sleuthkit/datamodel/CollectionUtils.java diff --git a/bindings/java/src/org/sleuthkit/datamodel/CaseDbSchemaVersionNumber.java b/bindings/java/src/org/sleuthkit/datamodel/CaseDbSchemaVersionNumber.java index 5a08faa2a..8f739a3cf 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CaseDbSchemaVersionNumber.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CaseDbSchemaVersionNumber.java @@ -1,7 +1,7 @@ /* * Sleuth Kit Data Model * - * Copyright 2011-2017 Basis Technology Corp. + * Copyright 2017 Basis Technology Corp. * Contact: carrier <at> sleuthkit <dot> org * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/bindings/java/src/org/sleuthkit/datamodel/CollectionUtils.java b/bindings/java/src/org/sleuthkit/datamodel/CollectionUtils.java new file mode 100644 index 000000000..4d39663b1 --- /dev/null +++ b/bindings/java/src/org/sleuthkit/datamodel/CollectionUtils.java @@ -0,0 +1,37 @@ +/* + * Sleuth Kit Data Model + * + * Copyright 2017 Basis Technology Corp. + * Contact: carrier <at> sleuthkit <dot> org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.datamodel; + +import java.util.Arrays; +import java.util.HashSet; + +/** + * Static utilities for dealing with Collections. At some point this could be + * replaced with apache commons or guava... + */ +class CollectionUtils { + + @SuppressWarnings("unchecked") + static <T> HashSet<T> hashSetOf(T... values) { + return new HashSet<T>(Arrays.asList(values)); + } + + private CollectionUtils() { + } +} diff --git a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsFilter.java b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsFilter.java index ffe87c515..c76adfe23 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsFilter.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsFilter.java @@ -26,13 +26,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG; -import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT; -import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG; -import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE; -import static org.sleuthkit.datamodel.Relationship.Type.CALL_LOG; -import static org.sleuthkit.datamodel.Relationship.Type.CONTACT; -import static org.sleuthkit.datamodel.Relationship.Type.MESSAGE; /** * Defines an aggregate of filters to apply to a CommunicationsManager query. @@ -133,19 +126,12 @@ public String getSQL(CommunicationsManager commsManager) { return ""; } - List<Integer> artifactTypeIds = new ArrayList<Integer>(); + List<Integer> relationShipTypeIds = new ArrayList<Integer>(); for (Relationship.Type relType : relationshipTypes) { - if (relType.equals(CALL_LOG)) { - artifactTypeIds.add(TSK_CALLLOG.getTypeID()); - } else if (relType.equals(CONTACT)) { - artifactTypeIds.add(TSK_CONTACT.getTypeID()); - } else if (relType.equals(MESSAGE)) { - artifactTypeIds.add(TSK_EMAIL_MSG.getTypeID()); - artifactTypeIds.add(TSK_MESSAGE.getTypeID()); - } + relationShipTypeIds.add(relType.getTypeID()); } return " relationships.relationship_type IN ( " - + StringUtils.buildCSVString(artifactTypeIds) + " )"; + + StringUtils.buildCSVString(relationShipTypeIds) + " )"; } } diff --git a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java index cf2d21250..d9abdf830 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java @@ -64,7 +64,6 @@ public class CommunicationsManager { private static final String RELATIONSHIP_ARTIFACT_TYPE_IDS_CSV_STR = StringUtils.buildCSVString(RELATIONSHIP_ARTIFACT_TYPE_IDS); - CommunicationsManager(SleuthkitCase db) throws TskCoreException { this.db = db; @@ -347,7 +346,8 @@ public Account getAccount(Account.Type accountType, String accountUniqueID) thro * @param sender sender account * @param recipients list of recipients * @param relationshipArtifact relationship artifact - * @param dateTime date of communications/relationship, as epoch + * @param relationshipType The type of relationship to be created + * @param dateTime Date of communications/relationship, as epoch * seconds * * @@ -355,13 +355,17 @@ public Account getAccount(Account.Type accountType, String accountUniqueID) thro * @throws org.sleuthkit.datamodel.TskDataException If the all the accounts * and the relationship are * not from the same data - * source. + * source, or if the + * relationshipArtifact and + * relationshipType are not + * compatible. */ public void addRelationships(AccountFileInstance sender, List<AccountFileInstance> recipients, - BlackboardArtifact relationshipArtifact, long dateTime) throws TskCoreException, TskDataException { + BlackboardArtifact relationshipArtifact, Relationship.Type relationshipType, long dateTime) throws TskCoreException, TskDataException { - if (false == RELATIONSHIP_ARTIFACT_TYPE_IDS.contains(relationshipArtifact.getArtifactTypeID())) { - throw new TskCoreException("Unexpected Artifact type = " + relationshipArtifact.getArtifactTypeID()); + if (relationshipType.isCreatableFrom(relationshipArtifact) == false) { + throw new TskDataException("Can not make a " + relationshipType.getDisplayName() + + " relationship from a" + relationshipArtifact.getDisplayName()); } /* @@ -394,7 +398,8 @@ public void addRelationships(AccountFileInstance sender, List<AccountFileInstanc while (iter.hasNext()) { try { UnorderedAccountPair accountPair = iter.next(); - addAccountsRelationship(accountPair.getFirst(), accountPair.getSecond(), relationshipArtifact.getId(), dateTime, relationshipArtifact.getArtifactTypeID(), relationshipArtifact.getDataSourceObjectID()); + addAccountsRelationship(accountPair.getFirst(), accountPair.getSecond(), + relationshipArtifact, relationshipType, dateTime); } catch (TskCoreException ex) { LOGGER.log(Level.WARNING, "Could not get timezone for image", ex); //NON-NLS } @@ -625,19 +630,17 @@ private Account getAccount(long account_id) throws TskCoreException { /** * Adds a row in account relationships table * - * @param account1_id account_id for account1 - * @param account2_id account_id for account2 - * @param relationship_source_obj_id obj_id of the relationship source - * object - * @param dateTime datetime of communication/relationship - * @param relationship_type relationship type - * @param data_source_obj_id datasource object id from where - * relationship is extracted + * @param account1_id account_id for account1 + * @param account2_id account_id for account2 + * @param relationshipaArtifact relationship artifact + * @param relationshipType The type of relationship to be created + * @param dateTime datetime of communication/relationship as + * epoch seconds * * @throws TskCoreException exception thrown if a critical error occurs * within TSK core */ - private void addAccountsRelationship(long account1_id, long account2_id, long relationship_source_obj_id, long dateTime, int relationship_type, long data_source_obj_id) throws TskCoreException { + private void addAccountsRelationship(long account1_id, long account2_id, BlackboardArtifact relationshipaArtifact, Relationship.Type relationshipType, long dateTime) throws TskCoreException { CaseDbConnection connection = db.getConnection(); db.acquireSingleUserCaseWriteLock(); Statement s = null; @@ -648,7 +651,7 @@ private void addAccountsRelationship(long account1_id, long account2_id, long re s = connection.createStatement(); s.execute("INSERT INTO account_relationships (account1_id, account2_id, relationship_source_obj_id, date_time, relationship_type, data_source_obj_id ) " - + "VALUES ( " + account1_id + ", " + account2_id + ", " + relationship_source_obj_id + ", " + dateTime + ", " + relationship_type + ", " + data_source_obj_id + ")"); //NON-NLS + + "VALUES ( " + account1_id + ", " + account2_id + ", " + relationshipaArtifact.getId() + ", " + dateTime + ", " + relationshipType.getTypeID() + ", " + relationshipaArtifact.getDataSourceObjectID() + ")"); //NON-NLS connection.commitTransaction(); } catch (SQLException ex) { connection.rollbackTransaction(); @@ -832,7 +835,6 @@ public Set<BlackboardArtifact> getRelationshipSources(Set<AccountDeviceInstance> //log this? return Collections.emptySet(); } - System.out.println("RAMAN getCommunications() Num AccountDeviceInstancees = " + accountDeviceInstanceList.size()); Map<Long, Set<Long>> accountIdToDatasourceObjIdMap = new HashMap<Long, Set<Long>>(); for (AccountDeviceInstance accountDeviceInstance : accountDeviceInstanceList) { @@ -874,26 +876,20 @@ public Set<BlackboardArtifact> getRelationshipSources(Set<AccountDeviceInstance> try { s = connection.createStatement(); String queryStr - = "SELECT DISTINCT " - + " artifacts.artifact_id AS artifact_id," + = "SELECT DISTINCT artifacts.artifact_id AS artifact_id," + " artifacts.obj_id AS obj_id," + " artifacts.artifact_obj_id AS artifact_obj_id," + " artifacts.data_source_obj_id AS data_source_obj_id, " + " artifacts.artifact_type_id AS artifact_type_id, " + " artifacts.review_status_id AS review_status_id " + " FROM blackboard_artifacts as artifacts" - + " JOIN account_relationships AS relationships" - + " ON artifacts.artifact_obj_id = relationships.relationship_source_obj_id" + + " JOIN account_relationships AS relationships" + + " ON artifacts.artifact_obj_id = relationships.relationship_source_obj_id" // append sql to restrict search to specified account device instances + " WHERE (" + adiSQLClause + " )" // plus other filters + (filterSQL.isEmpty() ? "" : " AND (" + filterSQL + " )"); - System.out.println("RAMAN getCommunications() adiSQLClause = " + adiSQLClause); - System.out.println("RAMAN getCommunications() FilterSQL = " + filterSQL); - System.out.println("RAMAN getCommunications() QueryStr = " + queryStr); - - long startTime = System.nanoTime(); rs = connection.executeQuery(s, queryStr); //NON-NLS Set<BlackboardArtifact> artifacts = new HashSet<BlackboardArtifact>(); while (rs.next()) { @@ -905,10 +901,6 @@ public Set<BlackboardArtifact> getRelationshipSources(Set<AccountDeviceInstance> BlackboardArtifact.ReviewStatus.withID(rs.getInt("review_status_id")))); } - long endTime = System.nanoTime(); - System.out.println("RAMAN getCommunications() Time taken = " + (endTime - startTime) / 1000000L); - System.out.println(""); - return artifacts; } catch (SQLException ex) { throw new TskCoreException("Error getting relationships for account. " + ex.getMessage(), ex); diff --git a/bindings/java/src/org/sleuthkit/datamodel/Relationship.java b/bindings/java/src/org/sleuthkit/datamodel/Relationship.java index 08c65f33a..ca4be0b69 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Relationship.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Relationship.java @@ -20,12 +20,19 @@ import java.util.Arrays; import java.util.Collections; +import static java.util.Collections.singleton; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG; +import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT; +import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG; +import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE; +import static org.sleuthkit.datamodel.CollectionUtils.hashSetOf; /** * A relationship between Accounts, such as a communication ( email, sms, phone - * call (log) ) or presence in a contact book. + * call (call log) ) or presence in a contact book. */ public class Relationship { @@ -33,41 +40,42 @@ public static final class Type { private final String displayName; private final String typeName; + private final int typeID; - public static final Type MESSAGE = new Type("MESSAGE", "Message"); - public static final Type CALL_LOG = new Type("CALL_LOG", "Call Log"); - public static final Type CONTACT = new Type("CONTACT", "Contact"); + public static final Type MESSAGE = new Type("MESSAGE", "Message", 1); + public static final Type CALL_LOG = new Type("CALL_LOG", "Call Log", 2); + public static final Type CONTACT = new Type("CONTACT", "Contact", 3); - private static final Set<Type> PREDEFINED_RELATIONSHIP_TYPES - = Collections.unmodifiableSet(new HashSet<Relationship.Type>(Arrays.asList( - MESSAGE, CALL_LOG, CONTACT))); + private final static HashMap<Type, Set<Integer>> typesToArtifactTypeIDs = new HashMap<Type, Set<Integer>>(); + + static { + typesToArtifactTypeIDs.put(MESSAGE, hashSetOf( + TSK_EMAIL_MSG.getTypeID(), + TSK_MESSAGE.getTypeID())); + typesToArtifactTypeIDs.put(CALL_LOG, singleton( + TSK_CALLLOG.getTypeID())); + typesToArtifactTypeIDs.put(CONTACT, singleton( + TSK_CONTACT.getTypeID())); + } private static final Set<Type> PREDEFINED_COMMUNICATION_TYPES = Collections.unmodifiableSet(new HashSet<Relationship.Type>(Arrays.asList( MESSAGE, CALL_LOG))); - static Set<Relationship.Type> getPredefinedRelationshipTypes() { - return PREDEFINED_RELATIONSHIP_TYPES; - } - + /** + * Subset of predefined types that represent communications. + * + * @return A subset of predefined types that represent communications. + * + */ static Set<Relationship.Type> getPredefinedCommunicationTypes() { return PREDEFINED_COMMUNICATION_TYPES; } - private Type(String name, String displayName) { + private Type(String name, String displayName, int id) { this.typeName = name; this.displayName = displayName; - } - - @Override - public boolean equals(Object that) { - if (this == that) { - return true; - } else if (!(that instanceof Type)) { - return false; - } - Type thatType = (Type) that; - return this.typeName.equals(thatType.getTypeName()); + this.typeID = id; } public String getDisplayName() { @@ -78,17 +86,57 @@ public String getTypeName() { return typeName; } + public int getTypeID() { + return typeID; + } + @Override public int hashCode() { - int hash = 11; - hash = 83 * hash + (this.typeName != null ? this.typeName.hashCode() : 0); - hash = 83 * hash + (this.displayName != null ? this.displayName.hashCode() : 0); + int hash = 7; + hash = 37 * hash + (this.typeName != null ? this.typeName.hashCode() : 0); + hash = 37 * hash + this.typeID; return hash; } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Type other = (Type) obj; + if (this.typeID != other.typeID) { + return false; + } + if ((this.typeName == null) ? (other.typeName != null) : !this.typeName.equals(other.typeName)) { + return false; + } + return true; + } + @Override public String toString() { - return "{" + this.getClass().getName() + ": displayName=" + this.displayName + ", typeName=" + this.typeName + "}"; + return "{" + this.getClass().getName() + ": typeID=" + typeName + " displayName=" + this.displayName + ", typeName=" + this.typeName + "}"; + } + + /** + * Is this type creatable from the given artifact. Specifically do they + * have compatible types. + * + * @param relationshipArtifact the relationshipArtifact to test + * creatability from + * + * @return if a relationship of this type can be created from the given + * artifact. + */ + boolean isCreatableFrom(BlackboardArtifact relationshipArtifact) { + Set<Integer> get = typesToArtifactTypeIDs.get(this); + return get != null && get.contains(relationshipArtifact.getArtifactTypeID()); } } } diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index 489e01e52..5d4b838fc 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -3034,7 +3034,7 @@ public BlackboardArtifact.Type getArtifactType(String artTypeName) throws TskCor } /** - * Get the artifact type associated with an artifact type name. + * Get the artifact type associated with an artifact type id. * * @param artTypeId An artifact type id. * diff --git a/bindings/java/test/org/sleuthkit/datamodel/CommunicationsManagerTest.java b/bindings/java/test/org/sleuthkit/datamodel/CommunicationsManagerTest.java index eecddb7ca..e55cda317 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/CommunicationsManagerTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/CommunicationsManagerTest.java @@ -66,6 +66,7 @@ import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO; import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT; import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT; +import static org.sleuthkit.datamodel.CollectionUtils.hashSetOf; import org.sleuthkit.datamodel.CommunicationsFilter.AccountTypeFilter; import org.sleuthkit.datamodel.CommunicationsFilter.DateRangeFilter; import org.sleuthkit.datamodel.CommunicationsFilter.DeviceFilter; @@ -330,9 +331,7 @@ public static void setUpClass() { EMAIL_B_DS1 = new AccountDeviceInstance(commsMgr.getAccount(EMAIL, EMAIL_B), DS1_DEVICEID); EMAIL_C_DS1 = new AccountDeviceInstance(commsMgr.getAccount(EMAIL, EMAIL_C), DS1_DEVICEID); - EMAILS_ABC_DS1 = new HashSet<AccountDeviceInstance>(Arrays.asList( - EMAIL_A_DS1, EMAIL_B_DS1, EMAIL_C_DS1 - )); + EMAILS_ABC_DS1 = hashSetOf(EMAIL_A_DS1, EMAIL_B_DS1, EMAIL_C_DS1); PHONE_1_DS1 = new AccountDeviceInstance(commsMgr.getAccount(PHONE, PHONENUM_1), DS1_DEVICEID); PHONE_1_DS2 = new AccountDeviceInstance(commsMgr.getAccount(PHONE, PHONENUM_1), DS2_DEVICEID); @@ -345,10 +344,8 @@ public static void setUpClass() { PHONE_5_DS1 = new AccountDeviceInstance(commsMgr.getAccount(PHONE, PHONENUM_5), DS1_DEVICEID); PHONE_5_DS2 = new AccountDeviceInstance(commsMgr.getAccount(PHONE, PHONENUM_5), DS2_DEVICEID); - PHONES_2345_DS1 = new HashSet<AccountDeviceInstance>(Arrays.asList( - PHONE_2_DS1, PHONE_3_DS1, PHONE_4_DS1, PHONE_5_DS1)); - PHONES_12345_DS2 = new HashSet<AccountDeviceInstance>(Arrays.asList( - PHONE_1_DS2, PHONE_2_DS2, PHONE_3_DS2, PHONE_4_DS2, PHONE_5_DS2)); + PHONES_2345_DS1 = hashSetOf(PHONE_2_DS1, PHONE_3_DS1, PHONE_4_DS1, PHONE_5_DS1); + PHONES_12345_DS2 = hashSetOf(PHONE_1_DS2, PHONE_2_DS2, PHONE_3_DS2, PHONE_4_DS2, PHONE_5_DS2); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to create new case", ex); @@ -847,15 +844,14 @@ public void communicationsWithFilterTests() throws TskCoreException { // Communications for Email Account A/DS1: No Filters { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(EMAIL_A_DS1)); + Set<AccountDeviceInstance> accountDeviceInstances = singleton(EMAIL_A_DS1); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, null); + = commsMgr.getRelationshipSources(accountDeviceInstances, null); assertEquals(3, communications.size()); - for (AccountDeviceInstance adi : accountDeviceInstanceList) { - long count = commsMgr.getRelationshipSourcesCount(accountDeviceInstanceList.iterator().next(), null); + for (AccountDeviceInstance adi : accountDeviceInstances) { + long count = commsMgr.getRelationshipSourcesCount(accountDeviceInstances.iterator().next(), null); final String typeSpecificID = adi.getAccount().getTypeSpecificID(); if (EMAIL_A.equals(typeSpecificID)) { @@ -870,21 +866,18 @@ public void communicationsWithFilterTests() throws TskCoreException { // Communications for Email Account B/DS1: No Filters { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(EMAIL_B_DS1)); - Set<BlackboardArtifact> communications = commsMgr.getRelationshipSources(accountDeviceInstanceList, null); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(EMAIL_B_DS1); + Set<BlackboardArtifact> communications = commsMgr.getRelationshipSources(accountDeviceInstances, null); assertEquals(2, communications.size()); } // Communications for Email Account A/DS1 & C/DS1: No Filters { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList( - EMAIL_A_DS1, EMAIL_C_DS1 - )); + Set<AccountDeviceInstance> accountDeviceInstances + = hashSetOf(EMAIL_A_DS1, EMAIL_C_DS1); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, null); + = commsMgr.getRelationshipSources(accountDeviceInstances, null); assertEquals(3, communications.size()); } @@ -963,77 +956,71 @@ public void communicationsWithFilterTests() throws TskCoreException { // Communications for Phone 1/DS2: No Filters { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_1_DS2)); + Set<AccountDeviceInstance> accountDeviceInstances + = hashSetOf(PHONE_1_DS2); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, null); + = commsMgr.getRelationshipSources(accountDeviceInstances, null); assertEquals(1, communications.size()); } // Communications for Phone 1/DS2: Filter on CallLogs { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_1_DS2)); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(PHONE_1_DS2); CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList( new RelationshipTypeFilter(singleton(CALL_LOG)))); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(1, communications.size()); } // Communications for Phone 1/DS2: Filter on Contacts { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_1_DS2)); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(PHONE_1_DS2); CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList( new RelationshipTypeFilter(singleton(CONTACT)))); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(0, communications.size()); } // Communications for Phone 1/DS2: Filter on Message { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_1_DS2)); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(PHONE_1_DS2); CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList( new RelationshipTypeFilter(singleton(MESSAGE)) )); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(0, communications.size()); } // Communications for Phone 2/DS1: Filter on Calllogs { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_2_DS1)); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(PHONE_2_DS1); CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList( new RelationshipTypeFilter(singleton(CALL_LOG)))); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(2, communications.size()); } // Communications for Phone 2/DS2: Filter on Calllogs & Messages { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_2_DS2)); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(PHONE_2_DS2); CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList( COMMUNICATIONS_RELATIONSHIP_TYPE_FILTER)); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(3, communications.size()); } // Communications for Phone 1/DS2 & 2/DS1: Filter on Messages, Calllogs { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList(PHONE_1_DS2, PHONE_2_DS1)); + Set<AccountDeviceInstance> accountDeviceInstances = hashSetOf(PHONE_1_DS2, PHONE_2_DS1); CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList( COMMUNICATIONS_RELATIONSHIP_TYPE_FILTER)); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(5, communications.size()); } @@ -1172,16 +1159,15 @@ public void communicationsWithFilterTests() throws TskCoreException { // relationships for Email A/DS1, Phone 1/DS2 2/DS1: No Filters { - Set<AccountDeviceInstance> accountDeviceInstanceList - = new HashSet<AccountDeviceInstance>(Arrays.asList( - EMAIL_A_DS1, PHONE_1_DS2, PHONE_2_DS1)); + Set<AccountDeviceInstance> accountDeviceInstances + = hashSetOf(EMAIL_A_DS1, PHONE_1_DS2, PHONE_2_DS1); Set<BlackboardArtifact> communications - = commsMgr.getRelationshipSources(accountDeviceInstanceList, null); + = commsMgr.getRelationshipSources(accountDeviceInstances, null); assertEquals(9, communications.size()); // Communications for Email A/DS1, Phone 1/DS2 2/DS1: No Filters CommunicationsFilter commsFilter = new CommunicationsFilter(Arrays.asList(COMMUNICATIONS_RELATIONSHIP_TYPE_FILTER)); - communications = commsMgr.getRelationshipSources(accountDeviceInstanceList, commsFilter); + communications = commsMgr.getRelationshipSources(accountDeviceInstances, commsFilter); assertEquals(8, communications.size()); } } @@ -1253,7 +1239,7 @@ private static BlackboardArtifact addEmailMsgArtifact(String fromAddr, String to bbart.addAttributes(bbattributes); // Add account relationships - commsMgr.addRelationships(senderAccountInstance, recipientAccountInstances, bbart, dateSent); + commsMgr.addRelationships(senderAccountInstance, recipientAccountInstances, bbart, MESSAGE, dateSent); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add Email artifact", ex); @@ -1321,7 +1307,7 @@ private static void addCalllogArtifact(AccountFileInstance deviceAccount, String accountInstanceList.add(phoneNumAccount); // Create a Call Log relationship - commsMgr.addRelationships(deviceAccount, accountInstanceList, bbart, date); + commsMgr.addRelationships(deviceAccount, accountInstanceList, bbart, CALL_LOG, date); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Unable to add CallLog artifact ", ex); //NON-NLS @@ -1353,7 +1339,7 @@ private static void addMessageArtifact(AccountFileInstance deviceAccount, String accountInstanceList.add(phoneNumAccount); // Create a Message relationship - commsMgr.addRelationships(deviceAccount, accountInstanceList, bbart, date); + commsMgr.addRelationships(deviceAccount, accountInstanceList, bbart, MESSAGE, date); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Unable to add TSK_MESSAGE artifact ", ex); //NON-NLS @@ -1378,7 +1364,7 @@ private static void addContactArtifact(AccountFileInstance deviceAccount, String accountInstanceList.add(phoneNumAccount); // Create a CONTACT relationship - commsMgr.addRelationships(deviceAccount, accountInstanceList, bbart, 0); + commsMgr.addRelationships(deviceAccount, accountInstanceList, bbart, CONTACT, 0); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Unable to add Contact artifact ", ex); //NON-NLS -- GitLab