Autopsy  4.7.0
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 final List<String> toolTipList = new ArrayList<>();
47  private List<DataSource> dataSources = new ArrayList<>();
48  private final DefaultListModel<String> dataSourceListModel = new DefaultListModel<>();
49 
50  AdHocSearchPanel() {
51  initListeners();
52  }
53 
54  private void initListeners() {
55  KeywordSearch.addNumIndexedFilesChangeListener(
56  new PropertyChangeListener() {
57  @Override
58  public void propertyChange(PropertyChangeEvent evt) {
59  String changed = evt.getPropertyName();
60  Object newValue = evt.getNewValue();
61 
62  if (changed.equals(KeywordSearch.NUM_FILES_CHANGE_EVT)) {
63  int newFilesIndexed = ((Integer) newValue);
64  filesIndexed = newFilesIndexed;
65  postFilesIndexedChange();
66  }
67  }
68  });
69  }
70 
74  protected abstract void postFilesIndexedChange();
75 
81  abstract List<KeywordList> getKeywordLists();
82 
88  abstract Set<Long> getDataSourcesSelected();
89 
95  public void setFilesIndexed(int filesIndexed) {
96  this.filesIndexed = filesIndexed;
97  }
98 
103  public void search() {
104  boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
105 
106  if (filesIndexed == 0) {
107  try { // see if another node added any indexed files
108  filesIndexed = KeywordSearch.getServer().queryNumIndexedFiles();
109  } catch (KeywordSearchModuleException | NoOpenCoreException ignored) {
110  }
111  }
112  if (filesIndexed == 0) {
113  if (isIngestRunning) {
114  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
115  "AbstractKeywordSearchPerformer.search.noFilesInIdxMsg",
116  KeywordSearchSettings.getUpdateFrequency().getTime()), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
117  } else {
118  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
119  "AbstractKeywordSearchPerformer.search.noFilesIdxdMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
120  }
121  return;
122  }
123 
124  //check if keyword search module ingest is running (indexing, etc)
125  if (isIngestRunning) {
126  if (KeywordSearchUtil.displayConfirmDialog(org.openide.util.NbBundle.getMessage(this.getClass(), "AbstractKeywordSearchPerformer.search.searchIngestInProgressTitle"),
127  NbBundle.getMessage(this.getClass(), "AbstractKeywordSearchPerformer.search.ingestInProgressBody"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN) == false) {
128  return;
129  }
130  }
131 
132  final List<KeywordList> keywordLists = getKeywordLists();
133  if (keywordLists.isEmpty()) {
134  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
135  "AbstractKeywordSearchPerformer.search.emptyKeywordErrorBody"),
136  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
137  return;
138  }
139 
140  AdHocSearchDelegator man = new AdHocSearchDelegator(keywordLists, getDataSourcesSelected());
141  if (man.validate()) {
142  man.execute();
143  } else {
144  KeywordSearchUtil.displayDialog(keywordSearchErrorDialogHeader, NbBundle.getMessage(this.getClass(),
145  "AbstractKeywordSearchPerformer.search.invalidSyntaxHeader"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
146  }
147  }
148 
154  synchronized List<String> getDataSourceArray() {
155  List<String> dsList = new ArrayList<>();
156  toolTipList.clear();
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  toolTipList.add(dsName);
164  dsList.add(displayName);
165  }
166  return dsList;
167  }
168 
173  synchronized void setDataSources(List<DataSource> dataSources) {
174  this.dataSources = dataSources;
175  }
176 
183  Map<Long, String> getDataSourceMap() {
184  return dataSourceMap;
185  }
186 
191  List<String> getDataSourceToolTipList() {
192  return toolTipList;
193  }
194 
199  final DefaultListModel<String> getDataSourceListModel() {
200  return dataSourceListModel;
201  }
202 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.