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;
71 public <T> T accept(AutopsyItemVisitor<T> v) {
87 List<String> getSetNames() {
88 List<String> names =
new ArrayList<>(hashSetHitsMap.keySet());
89 Collections.sort(names);
93 Set<Long> getArtifactIds(String hashSetName) {
94 return hashSetHitsMap.get(hashSetName);
96 @SuppressWarnings(
"deprecation")
98 hashSetHitsMap.clear();
100 if (skCase == null) {
104 int setNameId = ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID();
105 int artId = ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID();
106 String query =
"SELECT value_text,blackboard_attributes.artifact_id,attribute_type_id "
107 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
108 +
"attribute_type_id=" + setNameId
109 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
110 +
" AND blackboard_artifacts.artifact_type_id=" + artId;
112 try (CaseDbQuery dbQuery = skCase.
executeQuery(query)) {
113 ResultSet resultSet = dbQuery.getResultSet();
114 while (resultSet.next()) {
115 String setName = resultSet.getString(
"value_text");
116 long artifactId = resultSet.getLong(
"artifact_id");
117 if (!hashSetHitsMap.containsKey(setName)) {
118 hashSetHitsMap.put(setName,
new HashSet<Long>());
120 hashSetHitsMap.get(setName).add(artifactId);
122 }
catch (TskCoreException | SQLException ex) {
123 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
137 super(Children.create(
new HashsetNameFactory(),
true), Lookups.singleton(DISPLAY_NAME));
138 super.setName(HASHSET_HITS);
139 super.setDisplayName(DISPLAY_NAME);
140 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
150 return v.
visit(
this);
155 Sheet s = super.createSheet();
156 Sheet.Set ss = s.get(Sheet.PROPERTIES);
158 ss = Sheet.createPropertiesSet();
162 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
163 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
164 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
180 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
182 public void propertyChange(PropertyChangeEvent evt) {
183 String eventType = evt.getPropertyName();
187 hashsetResults.update();
192 hashsetResults.update();
196 if (evt.getNewValue() == null) {
209 hashsetResults.update();
210 hashsetResults.addObserver(
this);
218 hashsetResults.deleteObserver(
this);
223 list.addAll(hashsetResults.getSetNames());
233 public void update(Observable o, Object arg) {
244 super(Children.create(
new HitFactory(hashSetName),
true), Lookups.singleton(hashSetName));
245 super.setName(hashSetName);
248 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
249 hashsetResults.addObserver(
this);
256 super.setDisplayName(hashSetName +
" (" + hashsetResults.getArtifactIds(hashSetName).size() +
")");
266 Sheet s = super.createSheet();
267 Sheet.Set ss = s.get(Sheet.PROPERTIES);
269 ss = Sheet.createPropertiesSet();
273 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
274 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
275 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
283 return v.
visit(
this);
287 public void update(Observable o, Object arg) {
295 private class HitFactory extends ChildFactory.Detachable<Long> implements Observer {
305 hashsetResults.addObserver(
this);
310 hashsetResults.deleteObserver(
this);
315 list.addAll(hashsetResults.getArtifactIds(hashsetName));
321 if (skCase == null) {
329 logger.log(Level.WARNING,
"TSK Exception occurred", ex);
335 public void update(Observable o, Object arg) {
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
HashsetNameNode(String hashSetName)
static final String DISPLAY_NAME
HitFactory(String hashsetName)
boolean createKeys(List< String > list)
Node createNodeForKey(String key)
BlackboardArtifact getBlackboardArtifact(long artifactID)
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 synchronized void removePropertyChangeListener(PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
void update(Observable o, Object arg)
static Logger getLogger(String name)
Node createNodeForKey(Long id)
final HashsetResults hashsetResults
CaseDbQuery executeQuery(String query)