19package org.sleuthkit.autopsy.guiutils;
21import com.google.common.cache.CacheBuilder;
22import com.google.common.cache.CacheLoader;
23import com.google.common.cache.LoadingCache;
24import java.beans.PropertyChangeListener;
25import java.sql.SQLException;
26import java.util.ArrayList;
27import java.util.EnumSet;
28import java.util.HashMap;
31import java.util.concurrent.ExecutionException;
32import java.util.concurrent.TimeUnit;
33import java.util.logging.Level;
34import org.sleuthkit.autopsy.casemodule.Case;
35import org.sleuthkit.autopsy.coreutils.Logger;
36import org.sleuthkit.autopsy.ingest.IngestManager;
37import static org.sleuthkit.autopsy.ingest.IngestManager.IngestModuleEvent.DATA_ADDED;
38import org.sleuthkit.autopsy.ingest.ModuleDataEvent;
39import org.sleuthkit.datamodel.Account;
40import org.sleuthkit.datamodel.BlackboardArtifact;
41import org.sleuthkit.datamodel.BlackboardAttribute;
42import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME;
43import org.sleuthkit.datamodel.TskCoreException;
57 private final LoadingCache<String, Map<String, List<BlackboardArtifact>>>
accountMap;
69 public static synchronized List<BlackboardArtifact>
getContacts(Account account)
throws ExecutionException {
83 public static synchronized List<String>
getContactNameList(String accountTypeSpecificID)
throws TskCoreException {
84 List<BlackboardArtifact> contactList;
87 }
catch (ExecutionException ex) {
88 throw new TskCoreException(
"Unable to get contact list from cache", ex);
90 List<String> contactNameList =
new ArrayList<>();
92 if (contactList !=
null) {
93 for (BlackboardArtifact artifact : contactList) {
94 BlackboardAttribute attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(TSK_NAME.getTypeID())));
95 if (attribute !=
null && !contactNameList.contains(attribute.getValueString())) {
96 contactNameList.add(attribute.getValueString());
101 return contactNameList;
107 static synchronized void invalidateCache() {
116 accountMap = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).build(
117 new CacheLoader<String, Map<String, List<BlackboardArtifact>>>() {
119 public Map<String, List<BlackboardArtifact>> load(String key) {
122 }
catch (SQLException | TskCoreException ex) {
123 logger.log(Level.WARNING,
"Failed to build account to contact map", ex);
125 return new HashMap<>();
129 PropertyChangeListener ingestListener = pce -> {
130 String eventType = pce.getPropertyName();
131 if (eventType.equals(DATA_ADDED.toString())) {
163 private Map<String, List<BlackboardArtifact>>
buildMap() throws TskCoreException, SQLException {
164 Map<String, List<BlackboardArtifact>> acctMap =
new HashMap<>();
167 for (BlackboardArtifact contactArtifact : contactList) {
168 List<BlackboardAttribute> contactAttributes = contactArtifact.getAttributes();
169 for (BlackboardAttribute attribute : contactAttributes) {
170 String typeName = attribute.getAttributeType().getTypeName();
172 if (typeName.startsWith(
"TSK_EMAIL")
173 || typeName.startsWith(
"TSK_PHONE")
174 || typeName.startsWith(
"TSK_NAME")
175 || typeName.startsWith(
"TSK_ID")) {
176 String accountID = attribute.getValueString();
177 List<BlackboardArtifact> artifactList = acctMap.get(accountID);
178 if (artifactList ==
null) {
179 artifactList =
new ArrayList<>();
180 acctMap.put(accountID, artifactList);
182 if (!artifactList.contains(contactArtifact)) {
183 artifactList.add(contactArtifact);
SleuthkitCase getSleuthkitCase()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static synchronized IngestManager getInstance()
void addIngestModuleEventListener(final PropertyChangeListener listener)
BlackboardArtifact.Type getBlackboardArtifactType()