Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AdHocSearchPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.io.File;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
31 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.DataSource;
33 import javax.swing.DefaultListModel;
40 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
41 abstract class AdHocSearchPanel extends javax.swing.JPanel {
42 
43  private final String keywordSearchErrorDialogHeader = org.openide.util.NbBundle.getMessage(this.getClass(), "AbstractKeywordSearchPerformer.search.dialogErrorHeader");
44  protected int filesIndexed;
45  private final Map<Long, String> dataSourceMap = new HashMap<>();
46  private List<DataSource> dataSources = new ArrayList<>();
47  private final DefaultListModel<String> dataSourceListModel = new DefaultListModel<>();
48 
49  AdHocSearchPanel() {
50  initListeners();
51  }
52 
53  private void initListeners() {
54  KeywordSearch.addNumIndexedFilesChangeListener(
55  new PropertyChangeListener() {
56  @Override
57  public void propertyChange(PropertyChangeEvent evt) {
58  String changed = evt.getPropertyName();
59  Object newValue = evt.getNewValue();
60 
61  if (changed.equals(KeywordSearch.NUM_FILES_CHANGE_EVT)) {
62  int newFilesIndexed = ((Integer) newValue);
63  filesIndexed = newFilesIndexed;
64  postFilesIndexedChange();
65  }
66  }
67  });
68  }
69 
73  protected abstract void postFilesIndexedChange();
74 
80  abstract List<KeywordList> getKeywordLists();
81 
87  abstract Set<Long> getDataSourcesSelected();
88 
94  public void setFilesIndexed(int filesIndexed) {
95  this.filesIndexed = filesIndexed;
96  }
97 
104  public void search(boolean saveResults) {
105  boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
106 
107  if (filesIndexed == 0) {
108  try { // see if another node added any indexed files
109  filesIndexed = KeywordSearch.getServer().queryNumIndexedFiles();
110  } catch (KeywordSearchModuleException | NoOpenCoreException ignored) {
111  }
112  }
113  if (filesIndexed == 0) {
114  if (isIngestRunning) {
115  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
116  "AbstractKeywordSearchPerformer.search.noFilesInIdxMsg",
117  KeywordSearchSettings.getUpdateFrequency().getTime()), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
118  } else {
119  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
120  "AbstractKeywordSearchPerformer.search.noFilesIdxdMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
121  }
122  return;
123  }
124 
125  //check if keyword search module ingest is running (indexing, etc)
126  if (isIngestRunning) {
127  if (KeywordSearchUtil.displayConfirmDialog(org.openide.util.NbBundle.getMessage(this.getClass(), "AbstractKeywordSearchPerformer.search.searchIngestInProgressTitle"),
128  NbBundle.getMessage(this.getClass(), "AbstractKeywordSearchPerformer.search.ingestInProgressBody"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN) == false) {
129  return;
130  }
131  }
132 
133  final List<KeywordList> keywordLists = getKeywordLists();
134  if (keywordLists.isEmpty()) {
135  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
136  "AbstractKeywordSearchPerformer.search.emptyKeywordErrorBody"),
137  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
138  return;
139  }
140 
141  AdHocSearchDelegator man = new AdHocSearchDelegator(keywordLists, getDataSourcesSelected());
142  if (man.validate()) {
143  man.execute(saveResults);
144  } else {
145  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
146  "AbstractKeywordSearchPerformer.search.invalidSyntaxHeader"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
147  }
148  }
149 
155  synchronized List<String> getDataSourceArray() {
156  List<String> dsList = new ArrayList<>();
157  Collections.sort(this.dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
158  for (DataSource ds : dataSources) {
159  String dsName = ds.getName();
160  File dataSourceFullName = new File(dsName);
161  String displayName = dataSourceFullName.getName();
162  dataSourceMap.put(ds.getId(), displayName);
163  dsList.add(displayName);
164  }
165  return dsList;
166  }
167 
172  synchronized void setDataSources(List<DataSource> dataSources) {
173  this.dataSources = dataSources;
174  }
175 
181  Map<Long, String> getDataSourceMap() {
182  return dataSourceMap;
183  }
184 
189  final DefaultListModel<String> getDataSourceListModel() {
190  return dataSourceListModel;
191  }
192 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.