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.EnumSet;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.LinkedHashMap;
31 import java.util.List;
33 import java.util.Observable;
34 import java.util.Observer;
36 import java.util.logging.Level;
37 import org.openide.nodes.ChildFactory;
38 import org.openide.nodes.Children;
39 import org.openide.nodes.Node;
40 import org.openide.nodes.Sheet;
41 import org.openide.util.NbBundle;
42 import org.openide.util.WeakListeners;
43 import org.openide.util.lookup.Lookups;
52 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
92 this.filteringDSObjId = objId;
93 interestingResults.update();
111 List<String> getSetNames() {
112 List<String> setNames;
114 setNames =
new ArrayList<>(interestingItemsMap.keySet());
116 Collections.sort(setNames, (a, b) -> a.compareToIgnoreCase(b));
129 Set<Long> getArtifactIds(String setName) {
131 return new HashSet<>(interestingItemsMap.getOrDefault(setName, Collections.emptySet()));
140 interestingItemsMap.clear();
151 @SuppressWarnings(
"deprecation")
153 if (skCase == null) {
157 int setNameId = BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID();
159 String query =
"SELECT value_text, blackboard_artifacts.artifact_obj_id "
160 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
161 +
"attribute_type_id=" + setNameId
162 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
163 +
" AND blackboard_artifacts.artifact_type_id = " +
artifactType.getTypeID();
164 if (filteringDSObjId > 0) {
165 query +=
" AND blackboard_artifacts.data_source_obj_id = " +
filteringDSObjId;
168 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
170 ResultSet resultSet = dbQuery.getResultSet();
171 while (resultSet.next()) {
172 String value = resultSet.getString(
"value_text");
173 long artifactObjId = resultSet.getLong(
"artifact_obj_id");
175 .computeIfAbsent(value, (k) ->
new HashSet<>())
179 }
catch (TskCoreException | SQLException ex) {
180 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
187 return visitor.
visit(
this);
193 private class SetNameFactory extends ChildFactory.Detachable<String> implements Observer {
200 private final PropertyChangeListener
pcl = (PropertyChangeEvent evt) -> {
201 String eventType = evt.getPropertyName();
219 interestingResults.update();
236 interestingResults.update();
244 if (evt.getNewValue() == null) {
251 private final PropertyChangeListener
weakPcl = WeakListeners.propertyChange(pcl, null);
255 list.addAll(interestingResults.getSetNames());
265 public void update(Observable o, Object arg) {
274 interestingResults.addObserver(
this);
275 interestingResults.update();
284 interestingResults.deleteObserver(
this);
296 super(Children.create(
new HitFactory(setName),
true), Lookups.singleton(setName));
298 super.setName(setName);
300 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/interesting_item.png");
301 interestingResults.addObserver(
this);
305 int sizeOfSet = interestingResults.getArtifactIds(setName).size();
306 super.setDisplayName(setName +
" (" + sizeOfSet +
")");
316 Sheet sheet = super.createSheet();
317 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
318 if (sheetSet == null) {
319 sheetSet = Sheet.createPropertiesSet();
323 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"InterestingHits.createSheet.name.name"),
324 NbBundle.getMessage(
this.getClass(),
"InterestingHits.createSheet.name.name"),
325 NbBundle.getMessage(
this.getClass(),
"InterestingHits.createSheet.name.desc"),
333 return visitor.
visit(
this);
337 public void update(Observable o, Object arg) {
347 return getClass().getName();
372 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/interesting_item.png");
382 Sheet sheet = super.createSheet();
383 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
384 if (sheetSet == null) {
385 sheetSet = Sheet.createPropertiesSet();
388 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"InterestingHits.createSheet.name.name"),
389 NbBundle.getMessage(
this.getClass(),
"InterestingHits.createSheet.name.name"),
390 NbBundle.getMessage(
this.getClass(),
"InterestingHits.createSheet.name.desc"),
397 return visitor.
visit(
this);
406 return getClass().getName();
416 private final Map<Long, AnalysisResult>
artifactHits =
new HashMap<>();
431 interestingResults.addObserver(
this);
437 if (skCase != null) {
438 interestingResults.getArtifactIds(setName).forEach((
id) -> {
440 if (!artifactHits.containsKey(
id)) {
441 AnalysisResult art = skCase.getBlackboard().getAnalysisResultById(
id);
445 artifactHits.put(
id, art);
447 }
catch (TskCoreException ex) {
448 logger.log(Level.SEVERE,
"TSK Exception occurred", ex);
452 return new ArrayList<>(artifactHits.values());
454 return Collections.emptyList();
463 public void update(Observable o, Object arg) {
BlackboardArtifact.Type getBlackboardArtifactType()
Node createNodeForKey(AnalysisResult art)
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
final long filteringDSObjId
static synchronized IngestManager getInstance()
void update(Observable o, Object arg)
boolean createKeys(List< String > list)
final Map< Long, AnalysisResult > artifactHits
void removeIngestJobEventListener(final PropertyChangeListener listener)
final PropertyChangeListener pcl
SetNameNode(String setName)
void addIngestJobEventListener(final PropertyChangeListener listener)
final long filteringDSObjId
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
final PropertyChangeListener weakPcl
void update(Observable o, Object arg)
void update(Observable o, Object arg)
T visit(DataSourceFilesNode in)
HitFactory(String setName)
InterestingHits(SleuthkitCase skCase, BlackboardArtifact.Type artifactType)
List< AnalysisResult > makeKeys()
void addIngestModuleEventListener(final PropertyChangeListener listener)
final Map< String, Set< Long > > interestingItemsMap
Node createNodeForKey(String key)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
final BlackboardArtifact.Type artifactType
InterestingHits(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, long objId)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
final InterestingResults interestingResults
static final Logger logger