Autopsy  4.13.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;
55 
56 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
57 @ActionRegistration(displayName = "#CTL_ReportWizardAction", lazy = false)
58 @ActionReferences(value = {
59  @ActionReference(path = "Menu/Tools", position = 301, separatorAfter = 399)
60  ,
61  @ActionReference(path = "Toolbars/Case", position = 106)})
62 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
63 
64  private static final Logger logger = Logger.getLogger(ReportWizardAction.class.getName());
65  private static final String REPORTING_CONFIGURATION_NAME = "ReportAction";
66  private static final boolean DISPLAY_CASE_SPECIFIC_DATA = true;
67  private static final boolean RUN_REPORTS = true;
68  private final JButton toolbarButton = new JButton();
69  private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text");
70  private static ReportGenerationPanel panel;
71 
83  @SuppressWarnings("unchecked")
84  public static void doReportWizard(String configName, boolean displayCaseSpecificData, boolean runReports) {
85  WizardDescriptor wiz = new WizardDescriptor(new ReportWizardIterator(configName, displayCaseSpecificData));
86  wiz.setTitleFormat(new MessageFormat("{0} {1}"));
87  wiz.setTitle(NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.reportWiz.title"));
88  if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
89 
90  // save reporting configuration
91  try {
92  saveReportingConfiguration(configName, wiz);
93  } catch (ReportConfigException ex) {
94  logger.log(Level.SEVERE, "Failed to save reporting configuration " + configName, ex); //NON-NLS
95  NotifyDescriptor descriptor = new NotifyDescriptor.Message(
96  NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.unableToSaveConfig.errorLabel.text"),
97  NotifyDescriptor.ERROR_MESSAGE);
98  DialogDisplayer.getDefault().notify(descriptor);
99  }
100 
101  if (runReports) {
102  // generate reports in a separate thread
103  panel = new ReportGenerationPanel();
104  ReportGenerator generator = new ReportGenerator(configName, panel); //NON-NLS
105  ReportWorker worker = new ReportWorker(() -> {
106  generator.generateReports();
107  });
108  worker.execute();
109  generator.displayProgressPanel();
110  }
111  }
112  }
113 
114  @SuppressWarnings(value = "unchecked")
115  private static void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
116 
117  ReportingConfig reportingConfig = new ReportingConfig(configName);
118  reportingConfig.setFileReportSettings((FileReportSettings) wiz.getProperty("fileReportSettings"));
119  reportingConfig.setTableReportSettings((TableReportSettings) wiz.getProperty("tableReportSettings"));
120 
121  Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty("moduleConfigs");
122 
123  // update portable case settings
124  ReportModuleConfig config = moduleConfigs.get(PortableCaseReportModule.class.getCanonicalName());
125  PortableCaseReportModuleSettings portableCaseReportSettings = (PortableCaseReportModuleSettings) wiz.getProperty("portableCaseReportSettings");
126  if (portableCaseReportSettings != null) {
127  config.setModuleSettings(portableCaseReportSettings);
128  moduleConfigs.put(PortableCaseReportModule.class.getCanonicalName(), config);
129  }
130 
131  // set module configs
132  reportingConfig.setModuleConfigs(moduleConfigs);
133 
134  // save reporting configuration
135  ReportingConfigLoader.saveConfig(reportingConfig);
136  }
137 
139  setEnabled(false);
140  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
141  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
142  Case newCase = (Case) evt.getNewValue();
143  setEnabled(newCase != null && RuntimeProperties.runningWithGUI());
144  }
145  });
146 
147  // Initialize the Generate Report button
148  toolbarButton.addActionListener(ReportWizardAction.this::actionPerformed);
149  }
150 
151  @Override
152  @SuppressWarnings("unchecked")
153  public void actionPerformed(ActionEvent e) {
154  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
155  doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
156  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
157  }
158 
159  @Override
160  public void performAction() {
161  }
162 
163  @Override
164  public String getName() {
165  return ACTION_NAME;
166  }
167 
168  @Override
169  public HelpCtx getHelpCtx() {
170  return HelpCtx.DEFAULT_HELP;
171  }
172 
178  @Override
179  public Component getToolbarPresenter() {
180  ImageIcon icon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png")); //NON-NLS
181  toolbarButton.setIcon(icon);
182  toolbarButton.setText(NbBundle.getMessage(this.getClass(), "ReportWizardAction.toolBarButton.text"));
183  return toolbarButton;
184  }
185 
191  @Override
192  public void setEnabled(boolean value) {
193  super.setEnabled(value);
194  toolbarButton.setEnabled(value);
195  }
196 
197  private static class ReportWorker extends SwingWorker<Void, Void> {
198 
199  private final Runnable doInBackground;
200 
201  private ReportWorker(Runnable doInBackground) {
202  this.doInBackground = doInBackground;
203  }
204 
205  @Override
206  protected Void doInBackground() throws Exception {
207  doInBackground.run();
208  return null;
209  }
210 
211  @Override
212  protected void done() {
213  try {
214  get();
215  } catch (InterruptedException | ExecutionException ex) {
216  panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
217  logger.log(Level.SEVERE, "failed to generate reports", ex); //NON-NLS
218  } // catch and ignore if we were cancelled
219  catch (java.util.concurrent.CancellationException ex) {
220  }
221  }
222  }
223 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:486

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.