19 package org.sleuthkit.autopsy.guiutils;
 
   21 import com.google.common.cache.CacheBuilder;
 
   22 import com.google.common.cache.CacheLoader;
 
   23 import com.google.common.cache.LoadingCache;
 
   24 import java.beans.PropertyChangeListener;
 
   25 import java.sql.SQLException;
 
   26 import java.util.ArrayList;
 
   27 import java.util.EnumSet;
 
   28 import java.util.HashMap;
 
   29 import java.util.List;
 
   31 import java.util.concurrent.ExecutionException;
 
   32 import java.util.concurrent.TimeUnit;
 
   33 import java.util.logging.Level;
 
   42 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME;
 
   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())) {
 
  148         if (instance == null) {
 
  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);
 
BlackboardArtifact.Type getBlackboardArtifactType()
 
static synchronized IngestManager getInstance()
 
SleuthkitCase getSleuthkitCase()
 
void addIngestModuleEventListener(final PropertyChangeListener listener)
 
static Case getCurrentCase()
 
synchronized static Logger getLogger(String name)