19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.HashSet;
28 import java.util.LinkedHashMap;
29 import java.util.List;
31 import java.util.Observable;
32 import java.util.Observer;
34 import java.util.logging.Level;
35 import org.openide.nodes.ChildFactory;
36 import org.openide.nodes.Children;
37 import org.openide.nodes.Node;
38 import org.openide.nodes.Sheet;
39 import org.openide.util.NbBundle;
40 import org.openide.util.lookup.Lookups;
46 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
47 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
49 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
58 private static final String
HASHSET_HITS = BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getLabel();
59 private static final String
DISPLAY_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getDisplayName();
88 List<String> getSetNames() {
91 names =
new ArrayList<>(hashSetHitsMap.keySet());
93 Collections.sort(names);
97 Set<Long> getArtifactIds(String hashSetName) {
99 return hashSetHitsMap.get(hashSetName);
103 @SuppressWarnings(
"deprecation")
104 final
void update() {
106 hashSetHitsMap.clear();
109 if (skCase == null) {
113 int setNameId = ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID();
114 int artId = ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID();
115 String query =
"SELECT value_text,blackboard_attributes.artifact_id,attribute_type_id "
116 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
117 +
"attribute_type_id=" + setNameId
118 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
119 +
" AND blackboard_artifacts.artifact_type_id=" + artId;
121 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
122 ResultSet resultSet = dbQuery.getResultSet();
124 while (resultSet.next()) {
125 String setName = resultSet.getString(
"value_text");
126 long artifactId = resultSet.getLong(
"artifact_id");
127 if (!hashSetHitsMap.containsKey(setName)) {
128 hashSetHitsMap.put(setName,
new HashSet<Long>());
130 hashSetHitsMap.get(setName).add(artifactId);
133 }
catch (TskCoreException | SQLException ex) {
134 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
148 super(Children.create(
new HashsetNameFactory(),
true), Lookups.singleton(DISPLAY_NAME));
149 super.setName(HASHSET_HITS);
150 super.setDisplayName(DISPLAY_NAME);
151 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
161 return v.
visit(
this);
166 Sheet s = super.createSheet();
167 Sheet.Set ss = s.get(Sheet.PROPERTIES);
169 ss = Sheet.createPropertiesSet();
173 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
174 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
175 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
202 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
204 public void propertyChange(PropertyChangeEvent evt) {
205 String eventType = evt.getPropertyName();
221 if (null != eventData && eventData.
getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()) {
222 hashsetResults.update();
224 }
catch (IllegalStateException notUsed) {
239 hashsetResults.update();
240 }
catch (IllegalStateException notUsed) {
247 if (evt.getNewValue() == null) {
260 hashsetResults.update();
261 hashsetResults.addObserver(
this);
269 hashsetResults.deleteObserver(
this);
274 list.addAll(hashsetResults.getSetNames());
284 public void update(Observable o, Object arg) {
297 super(Children.create(
new HitFactory(hashSetName),
true), Lookups.singleton(hashSetName));
298 super.setName(hashSetName);
301 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
302 hashsetResults.addObserver(
this);
309 super.setDisplayName(hashSetName +
" (" + hashsetResults.getArtifactIds(hashSetName).size() +
")");
319 Sheet s = super.createSheet();
320 Sheet.Set ss = s.get(Sheet.PROPERTIES);
322 ss = Sheet.createPropertiesSet();
326 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
327 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
328 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
336 return v.
visit(
this);
340 public void update(Observable o, Object arg) {
358 private class HitFactory extends ChildFactory.Detachable<Long> implements Observer {
369 hashsetResults.addObserver(
this);
374 hashsetResults.deleteObserver(
this);
379 list.addAll(hashsetResults.getArtifactIds(hashsetName));
385 if (skCase == null) {
390 BlackboardArtifact art = skCase.getBlackboardArtifact(
id);
392 }
catch (TskException ex) {
393 logger.log(Level.WARNING,
"TSK Exception occurred", ex);
399 public void update(Observable o, Object arg) {
BlackboardArtifact.Type getBlackboardArtifactType()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
HashsetNameNode(String hashSetName)
static void removePropertyChangeListener(PropertyChangeListener listener)
static final String DISPLAY_NAME
HitFactory(String hashsetName)
boolean createKeys(List< String > list)
Node createNodeForKey(String key)
static final String HASHSET_HITS
static final Logger logger
T visit(DataSourcesNode in)
void update(Observable o, Object arg)
HashsetHits(SleuthkitCase skCase)
void removeIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< Long > list)
void addIngestJobEventListener(final PropertyChangeListener listener)
final Map< String, Set< Long > > hashSetHitsMap
void update(Observable o, Object arg)
final PropertyChangeListener pcl
static void addPropertyChangeListener(PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
void update(Observable o, Object arg)
Node createNodeForKey(Long id)
final HashsetResults hashsetResults