Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportWizardAction.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2012-2019 Basis Technology Corp.
6  *
7  * Copyright 2012 42six Solutions.
8  * Contact: aebadirad <at> 42six <dot> com
9  * Project Contact/Architect: carrier <at> sleuthkit <dot> org
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.sleuthkit.autopsy.report.infrastructure;
24 
27 import java.awt.Component;
28 import java.awt.Cursor;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.beans.PropertyChangeEvent;
32 import java.text.MessageFormat;
33 import java.util.EnumSet;
34 import java.util.Map;
35 import java.util.concurrent.ExecutionException;
36 import java.util.logging.Level;
37 import javax.swing.ImageIcon;
38 import javax.swing.JButton;
39 import javax.swing.SwingWorker;
40 import org.openide.DialogDisplayer;
41 import org.openide.NotifyDescriptor;
42 import org.openide.WizardDescriptor;
43 import org.openide.awt.ActionID;
44 import org.openide.awt.ActionReference;
45 import org.openide.awt.ActionReferences;
46 import org.openide.awt.ActionRegistration;
47 import org.openide.util.HelpCtx;
48 import org.openide.util.NbBundle;
49 import org.openide.util.actions.CallableSystemAction;
50 import org.openide.util.actions.Presenter;
51 import org.openide.windows.WindowManager;
56 
57 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
58 @ActionRegistration(displayName = "#CTL_ReportWizardAction", lazy = false)
59 @ActionReferences(value = {
60  @ActionReference(path = "Menu/Tools", position = 301, separatorAfter = 399)
61  ,
62  @ActionReference(path = "Toolbars/Case", position = 106)})
63 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
64 
65  private static final Logger logger = Logger.getLogger(ReportWizardAction.class.getName());
66  private static final String REPORTING_CONFIGURATION_NAME = "ReportAction";
67  private static final boolean DISPLAY_CASE_SPECIFIC_DATA = true;
68  private static final boolean RUN_REPORTS = true;
69  private final JButton toolbarButton = new JButton();
70  private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text");
71  private static ReportGenerationPanel panel;
72 
84  @SuppressWarnings("unchecked")
85  public static void doReportWizard(String configName, boolean displayCaseSpecificData, boolean runReports) {
86  WizardDescriptor wiz = new WizardDescriptor(new ReportWizardIterator(configName, displayCaseSpecificData));
87  wiz.setTitleFormat(new MessageFormat("{0} {1}"));
88  wiz.setTitle(NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.reportWiz.title"));
89  if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
90 
91  // save reporting configuration
92  try {
93  saveReportingConfiguration(configName, wiz);
94  } catch (ReportConfigException ex) {
95  logger.log(Level.SEVERE, "Failed to save reporting configuration " + configName, ex); //NON-NLS
96  NotifyDescriptor descriptor = new NotifyDescriptor.Message(
97  NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.unableToSaveConfig.errorLabel.text"),
98  NotifyDescriptor.ERROR_MESSAGE);
99  DialogDisplayer.getDefault().notify(descriptor);
100  }
101 
102  if (runReports) {
103  // generate reports in a separate thread
104  panel = new ReportGenerationPanel();
105  Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty("modules");
106  ReportGenerator generator = new ReportGenerator(configName, panel); //NON-NLS
107  ReportWorker worker = new ReportWorker(() -> {
108  generator.generateReports(modules);
109  });
110  worker.execute();
111  generator.displayProgressPanel();
112  }
113  }
114  }
115 
116  @SuppressWarnings(value = "unchecked")
117  private static void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
118 
119  ReportingConfig reportingConfig = new ReportingConfig(configName);
120  reportingConfig.setFileReportSettings((FileReportSettings) wiz.getProperty("fileReportSettings"));
121  reportingConfig.setTableReportSettings((TableReportSettings) wiz.getProperty("tableReportSettings"));
122 
123  Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty("moduleConfigs");
124 
125  // update portable case settings
126  ReportModuleConfig config = moduleConfigs.get(PortableCaseReportModule.class.getCanonicalName());
127  PortableCaseReportModuleSettings portableCaseReportSettings = (PortableCaseReportModuleSettings) wiz.getProperty("portableCaseReportSettings");
128  if (portableCaseReportSettings != null) {
129  config.setModuleSettings(portableCaseReportSettings);
130  moduleConfigs.put(PortableCaseReportModule.class.getCanonicalName(), config);
131  }
132 
133  // set module configs
134  reportingConfig.setModuleConfigs(moduleConfigs);
135 
136  // save reporting configuration
137  ReportingConfigLoader.saveConfig(reportingConfig);
138  }
139 
141  setEnabled(false);
142  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
143  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
144  Case newCase = (Case) evt.getNewValue();
145  setEnabled(newCase != null && RuntimeProperties.runningWithGUI());
146  }
147  });
148 
149  // Initialize the Generate Report button
150  toolbarButton.addActionListener(ReportWizardAction.this::actionPerformed);
151  }
152 
153  @Override
154  @SuppressWarnings("unchecked")
155  public void actionPerformed(ActionEvent e) {
156  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
157  doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
158  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
159  }
160 
161  @Override
162  public void performAction() {
163  }
164 
165  @Override
166  public String getName() {
167  return ACTION_NAME;
168  }
169 
170  @Override
171  public HelpCtx getHelpCtx() {
172  return HelpCtx.DEFAULT_HELP;
173  }
174 
180  @Override
181  public Component getToolbarPresenter() {
182  ImageIcon icon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png")); //NON-NLS
183  toolbarButton.setIcon(icon);
184  toolbarButton.setText(NbBundle.getMessage(this.getClass(), "ReportWizardAction.toolBarButton.text"));
185  return toolbarButton;
186  }
187 
193  @Override
194  public void setEnabled(boolean value) {
195  super.setEnabled(value);
196  toolbarButton.setEnabled(value);
197  }
198 
199  private static class ReportWorker extends SwingWorker<Void, Void> {
200 
201  private final Runnable doInBackground;
202 
203  private ReportWorker(Runnable doInBackground) {
204  this.doInBackground = doInBackground;
205  }
206 
207  @Override
208  protected Void doInBackground() throws Exception {
209  doInBackground.run();
210  return null;
211  }
212 
213  @Override
214  protected void done() {
215  try {
216  get();
217  } catch (InterruptedException | ExecutionException ex) {
218  panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
219  logger.log(Level.SEVERE, "failed to generate reports", ex); //NON-NLS
220  } // catch and ignore if we were cancelled
221  catch (java.util.concurrent.CancellationException ex) {
222  }
223  }
224  }
225 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:486

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.