19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.List;
31 import org.openide.util.NbBundle;
33 import javax.swing.DefaultListModel;
40 @SuppressWarnings(
"PMD.SingularField")
41 abstract class AdHocSearchPanel extends javax.swing.JPanel {
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<>();
53 private void initListeners() {
54 KeywordSearch.addNumIndexedFilesChangeListener(
55 new PropertyChangeListener() {
57 public void propertyChange(PropertyChangeEvent evt) {
58 String changed = evt.getPropertyName();
59 Object newValue = evt.getNewValue();
61 if (changed.equals(KeywordSearch.NUM_FILES_CHANGE_EVT)) {
62 int newFilesIndexed = ((Integer) newValue);
63 filesIndexed = newFilesIndexed;
64 postFilesIndexedChange();
73 protected abstract void postFilesIndexedChange();
80 abstract List<KeywordList> getKeywordLists();
87 abstract Set<Long> getDataSourcesSelected();
94 public void setFilesIndexed(
int filesIndexed) {
95 this.filesIndexed = filesIndexed;
104 public void search(
boolean saveResults) {
105 boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
107 if (filesIndexed == 0) {
109 filesIndexed = KeywordSearch.getServer().queryNumIndexedFiles();
110 }
catch (KeywordSearchModuleException | NoOpenCoreException ignored) {
113 if (filesIndexed == 0) {
114 if (isIngestRunning) {
116 KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(
this.getClass(),
117 "AbstractKeywordSearchPerformer.search.noFilesInIdxMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
119 KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(
this.getClass(),
120 "AbstractKeywordSearchPerformer.search.noFilesIdxdMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
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) {
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);
141 AdHocSearchDelegator man =
new AdHocSearchDelegator(keywordLists, getDataSourcesSelected());
142 if (man.validate()) {
143 man.execute(saveResults);
145 KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(
this.getClass(),
146 "AbstractKeywordSearchPerformer.search.invalidSyntaxHeader"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
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);
172 synchronized void setDataSources(List<DataSource> dataSources) {
173 this.dataSources = dataSources;
181 Map<Long, String> getDataSourceMap() {
182 return dataSourceMap;
189 final DefaultListModel<String> getDataSourceListModel() {
190 return dataSourceListModel;