Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardIngestConfigPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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.casemodule;
20 
21 import org.openide.util.NbBundle;
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Window;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 import javax.swing.JButton;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingUtilities;
31 import javax.swing.event.ChangeListener;
32 import org.openide.WizardDescriptor;
33 import org.openide.util.HelpCtx;
47 class AddImageWizardIngestConfigPanel implements WizardDescriptor.Panel<WizardDescriptor> {
48 
49 
50  private IngestJobSettingsPanel ingestJobSettingsPanel;
51 
56  private Component component = null;
57 
58  private final List<Content> newContents = Collections.synchronizedList(new ArrayList<Content>());
59  private boolean ingested = false;
60  private boolean readyToIngest = false;
61 
62  // task that will clean up the created database file if the wizard is cancelled before it finishes
63  private AddImageAction.CleanupTask cleanupTask;
64 
65  private final AddImageAction addImageAction;
66 
67  private final AddImageWizardAddingProgressPanel progressPanel;
68  private final AddImageWizardChooseDataSourcePanel dataSourcePanel;
69 
70  private DataSourceProcessor dsProcessor;
71 
72 
73  AddImageWizardIngestConfigPanel(AddImageWizardChooseDataSourcePanel dsPanel, AddImageAction action, AddImageWizardAddingProgressPanel proPanel) {
74  this.addImageAction = action;
75  this.progressPanel = proPanel;
76  this.dataSourcePanel = dsPanel;
77 
78  IngestJobSettings ingestJobSettings = new IngestJobSettings(AddImageWizardIngestConfigPanel.class.getCanonicalName());
79  showWarnings(ingestJobSettings);
80  this.ingestJobSettingsPanel = new IngestJobSettingsPanel(ingestJobSettings);
81  }
82 
91  @Override
92  public Component getComponent() {
93  if (component == null) {
94  component = new AddImageWizardIngestConfigVisual(this.ingestJobSettingsPanel);
95  }
96  return component;
97  }
98 
105  @Override
106  public HelpCtx getHelp() {
107  // Show no Help button for this panel:
108  return HelpCtx.DEFAULT_HELP;
109  // If you have context help:
110  // return new HelpCtx(SampleWizardPanel1.class);
111  }
112 
119  @Override
120  public boolean isValid() {
121  // If it is always OK to press Next or Finish, then:
122  return true;
123  // If it depends on some condition (form filled out...), then:
124  // return someCondition();
125  // and when this condition changes (last form field filled in...) then:
126  // fireChangeEvent();
127  // and uncomment the complicated stuff below.
128  }
129 
135  @Override
136  public final void addChangeListener(ChangeListener l) {
137  }
138 
144  @Override
145  public final void removeChangeListener(ChangeListener l) {
146  }
147 
148  // You can use a settings object to keep track of state. Normally the
149  // settings object will be the WizardDescriptor, so you can use
150  // WizardDescriptor.getProperty & putProperty to store information entered
151  // by the user.
160  @Override
161  public void readSettings(WizardDescriptor settings) {
162  JButton cancel = new JButton(
163  NbBundle.getMessage(this.getClass(), "AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text"));
164  cancel.setEnabled(false);
165  settings.setOptions(new Object[]{WizardDescriptor.PREVIOUS_OPTION, WizardDescriptor.NEXT_OPTION, WizardDescriptor.FINISH_OPTION, cancel});
166  cleanupTask = null;
167  readyToIngest = false;
168 
169  newContents.clear();
170 
171  // Start processing the data source by handing it off to the selected DSP,
172  // so it gets going in the background while the user is still picking the Ingest modules
173  startDataSourceProcessing(settings);
174  }
175 
185  @Override
186  public void storeSettings(WizardDescriptor settings) {
187  IngestJobSettings ingestJobSettings = this.ingestJobSettingsPanel.getSettings();
188  ingestJobSettings.save();
189  showWarnings(ingestJobSettings);
190 
191  // Start ingest if it hasn't already been started
192  readyToIngest = true;
193  startIngest();
194  }
195 
196  private static void showWarnings(IngestJobSettings ingestJobSettings) {
197  List<String> warnings = ingestJobSettings.getWarnings();
198  if (warnings.isEmpty() == false) {
199  StringBuilder warningMessage = new StringBuilder();
200  for (String warning : warnings) {
201  warningMessage.append(warning).append("\n");
202  }
203  JOptionPane.showMessageDialog(null, warningMessage.toString());
204  }
205  }
206 
211  private void startIngest() {
212  if (!newContents.isEmpty() && readyToIngest && !ingested) {
213  ingested = true;
214  IngestManager.getInstance().queueIngestJob(newContents, ingestJobSettingsPanel.getSettings());
215  progressPanel.setStateFinished();
216  }
217  }
218 
222  private void startDataSourceProcessing(WizardDescriptor settings) {
223 
224 
225 
226  // Add a cleanup task to interrupt the background process if the
227  // wizard exits while the background process is running.
228  cleanupTask = addImageAction.new CleanupTask() {
229  @Override
230  void cleanup() throws Exception {
231  cancelDataSourceProcessing();
232  }
233  };
234 
235  cleanupTask.enable();
236 
237  // get the selected DSProcessor
238  dsProcessor = dataSourcePanel.getComponent().getCurrentDSProcessor();
239 
240  DataSourceProcessorCallback cbObj = new DataSourceProcessorCallback () {
241  @Override
242  public void doneEDT(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errList, List<Content> contents) {
243  dataSourceProcessorDone(result, errList, contents );
244  }
245 
246  };
247 
248  progressPanel.setStateStarted();
249 
250  // Kick off the DSProcessor
251  dsProcessor.run(progressPanel.getDSPProgressMonitorImpl(), cbObj);
252 
253  }
254 
255  /*
256  * Cancels the data source processing - in case the users presses 'Cancel'
257  */
258  private void cancelDataSourceProcessing() {
259  dsProcessor.cancel();
260  }
261 
262  /*
263  * Callback for the data source processor.
264  * Invoked by the DSP on the EDT thread, when it finishes processing the data source.
265  */
266  private void dataSourceProcessorDone(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errList, List<Content> contents) {
267 
268  // disable the cleanup task
269  cleanupTask.disable();
270 
271  // Get attention for the process finish
272  java.awt.Toolkit.getDefaultToolkit().beep(); //BEEP!
273  AddImageWizardAddingProgressVisual panel = progressPanel.getComponent();
274  if (panel != null) {
275  Window w = SwingUtilities.getWindowAncestor(panel);
276  if (w != null) {
277  w.toFront();
278  }
279  }
280  // Tell the panel we're done
281  progressPanel.setStateFinished();
282 
283 
284  //check the result and display to user
285  if (result == DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS)
286  progressPanel.getComponent().setProgressBarTextAndColor(
287  NbBundle.getMessage(this.getClass(), "AddImageWizardIngestConfigPanel.dsProcDone.noErrs.text"), 100, Color.black);
288  else
289  progressPanel.getComponent().setProgressBarTextAndColor(
290  NbBundle.getMessage(this.getClass(), "AddImageWizardIngestConfigPanel.dsProcDone.errs.text"), 100, Color.red);
291 
292 
293  //if errors, display them on the progress panel
294  boolean critErr = false;
295  if (result == DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS) {
296  critErr = true;
297  }
298  for ( String err: errList ) {
299  // TBD: there probably should be an error level for each error
300  progressPanel.addErrors(err, critErr);
301  }
302 
303  newContents.clear();
304  newContents.addAll(contents);
305 
306  //notify the UI of the new content added to the case
307  if (!newContents.isEmpty()) {
308 
309  Case.getCurrentCase().notifyNewDataSource(newContents.get(0));
310  }
311 
312 
313  // Start ingest if we can
314  progressPanel.setStateStarted();
315  startIngest();
316 
317  }
318 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.