Autopsy 4.22.1
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-2022 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 */
23package org.sleuthkit.autopsy.report.infrastructure;
24
25import org.sleuthkit.autopsy.report.modules.portablecase.PortableCaseReportModuleSettings;
26import org.sleuthkit.autopsy.report.modules.portablecase.PortableCaseReportModule;
27import java.awt.Component;
28import java.awt.Cursor;
29import java.awt.event.ActionEvent;
30import java.awt.event.ActionListener;
31import java.beans.PropertyChangeEvent;
32import java.text.MessageFormat;
33import java.util.EnumSet;
34import java.util.List;
35import java.util.Map;
36import java.util.Set;
37import java.util.concurrent.ExecutionException;
38import java.util.logging.Level;
39import javax.swing.ImageIcon;
40import javax.swing.JButton;
41import javax.swing.SwingWorker;
42import org.openide.DialogDisplayer;
43import org.openide.NotifyDescriptor;
44import org.openide.WizardDescriptor;
45import org.openide.awt.ActionID;
46import org.openide.awt.ActionReference;
47import org.openide.awt.ActionReferences;
48import org.openide.awt.ActionRegistration;
49import org.openide.util.HelpCtx;
50import org.openide.util.NbBundle;
51import org.openide.util.actions.CallableSystemAction;
52import org.openide.util.actions.Presenter;
53import org.openide.windows.WindowManager;
54import org.sleuthkit.autopsy.casemodule.Case;
55import org.sleuthkit.autopsy.core.RuntimeProperties;
56import org.sleuthkit.autopsy.coreutils.Logger;
57import org.sleuthkit.autopsy.report.GeneralReportSettings;
58import org.sleuthkit.autopsy.report.ReportModule;
59
60@ActionID(category = "Tools", id = "org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
61@ActionRegistration(displayName = "#CTL_ReportWizardAction", lazy = false)
62@ActionReferences(value = {
63 @ActionReference(path = "Menu/Tools", position = 301, separatorAfter = 399)
64 ,
65 @ActionReference(path = "Toolbars/Case", position = 106)})
66public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
67
68 private static final Logger logger = Logger.getLogger(ReportWizardAction.class.getName());
69 private static final String REPORTING_CONFIGURATION_NAME = "ReportAction";
70 private static final boolean DISPLAY_CASE_SPECIFIC_DATA = true;
71 private static final boolean RUN_REPORTS = true;
72 private final JButton toolbarButton = new JButton();
73 private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text");
74 private static ReportGenerationPanel panel;
75
87 @SuppressWarnings("unchecked")
88 public static void doReportWizard(String configName, boolean displayCaseSpecificData, boolean runReports) {
89 WizardDescriptor wiz = new WizardDescriptor(new ReportWizardIterator(configName, displayCaseSpecificData));
90 wiz.setTitleFormat(new MessageFormat("{0} {1}"));
91 wiz.setTitle(NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.reportWiz.title"));
92 if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
93
94 // save reporting configuration
95 try {
96 saveReportingConfiguration(configName, wiz);
97 } catch (ReportConfigException ex) {
98 logger.log(Level.SEVERE, "Failed to save reporting configuration " + configName, ex); //NON-NLS
99 NotifyDescriptor descriptor = new NotifyDescriptor.Message(
100 NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.unableToSaveConfig.errorLabel.text"),
101 NotifyDescriptor.ERROR_MESSAGE);
102 DialogDisplayer.getDefault().notify(descriptor);
103 }
104
105 if (runReports) {
106 // generate reports in a separate thread
107 panel = new ReportGenerationPanel();
108 Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty("modules");
109 ReportGenerator generator = new ReportGenerator(configName, panel); //NON-NLS
110 ReportWorker worker = new ReportWorker(() -> {
111 try {
112 generator.generateReports(modules);
113 } catch (ReportGenerationException ex) {
114 // do nothing. the error message will be logged and
115 // displayed by the progress panel.
116 }
117 });
118 worker.execute();
119 generator.displayProgressPanel();
120 }
121 }
122 }
123
124 @SuppressWarnings(value = "unchecked")
125 private static void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
126
127 ReportingConfig reportingConfig = new ReportingConfig(configName);
128 List<Long> selectedDataSourceIds = (List<Long>) wiz.getProperty("dataSourceSelections");
129
130 // Set the selected data source ids.
131 FileReportSettings fileSettings = (FileReportSettings) wiz.getProperty("fileReportSettings");
132 TableReportSettings tableSettings = (TableReportSettings) wiz.getProperty("tableReportSettings");
133 GeneralReportSettings generalSettings = new GeneralReportSettings();
134 if(selectedDataSourceIds != null) {
135 generalSettings.setSelectedDataSources(selectedDataSourceIds);
136 if(fileSettings != null) {
137 fileSettings.setSelectedDataSources(selectedDataSourceIds);
138 }
139 if(tableSettings != null) {
140 tableSettings.setSelectedDataSources(selectedDataSourceIds);
141 }
142 }
143
144 reportingConfig.setFileReportSettings(fileSettings);
145 reportingConfig.setTableReportSettings(tableSettings);
146 reportingConfig.setGeneralReportSettings(generalSettings);
147
148 Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty("moduleConfigs");
149
150 // update portable case settings
151 ReportModuleConfig config = moduleConfigs.get(PortableCaseReportModule.class.getCanonicalName());
152 PortableCaseReportModuleSettings portableCaseReportSettings = (PortableCaseReportModuleSettings) wiz.getProperty("portableCaseReportSettings");
153 if (portableCaseReportSettings != null) {
154 config.setModuleSettings(portableCaseReportSettings);
155 moduleConfigs.put(PortableCaseReportModule.class.getCanonicalName(), config);
156 }
157
158 // set module configs
159 reportingConfig.setModuleConfigs(moduleConfigs);
160
161 // save reporting configuration
162 ReportingConfigLoader.saveConfig(reportingConfig);
163 }
164
166 setEnabled(false);
167 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
168 if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
169 Case newCase = (Case) evt.getNewValue();
170 setEnabled(newCase != null && RuntimeProperties.runningWithGUI());
171 }
172 });
173
174 // Initialize the Generate Report button
175 toolbarButton.addActionListener(ReportWizardAction.this::actionPerformed);
176 }
177
178 @Override
179 @SuppressWarnings("unchecked")
180 public void actionPerformed(ActionEvent e) {
181 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
183 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
184 }
185
186 @Override
187 public void performAction() {
188 }
189
190 @Override
191 public String getName() {
192 return ACTION_NAME;
193 }
194
195 @Override
196 public HelpCtx getHelpCtx() {
197 return HelpCtx.DEFAULT_HELP;
198 }
199
205 @Override
206 public Component getToolbarPresenter() {
207 ImageIcon icon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png")); //NON-NLS
208 toolbarButton.setIcon(icon);
209 toolbarButton.setText(NbBundle.getMessage(this.getClass(), "ReportWizardAction.toolBarButton.text"));
210 return toolbarButton;
211 }
212
220 public static Set<String> getReportConfigNames() {
221 Set<String> nameList = ReportingConfigLoader.getListOfReportConfigs();
222 //Remove this default name, users cannot change this report.
223 nameList.remove(REPORTING_CONFIGURATION_NAME);
224
225 return nameList;
226 }
227
233 @Override
234 public void setEnabled(boolean value) {
235 super.setEnabled(value);
236 toolbarButton.setEnabled(value);
237 }
238
239 private static class ReportWorker extends SwingWorker<Void, Void> {
240
241 private final Runnable doInBackground;
242
243 private ReportWorker(Runnable doInBackground) {
244 this.doInBackground = doInBackground;
245 }
246
247 @Override
248 protected Void doInBackground() throws Exception {
249 doInBackground.run();
250 return null;
251 }
252
253 @Override
254 protected void done() {
255 try {
256 get();
257 } catch (InterruptedException | ExecutionException ex) {
258 panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
259 logger.log(Level.SEVERE, "failed to generate reports", ex); //NON-NLS
260 } // catch and ignore if we were cancelled
261 catch (java.util.concurrent.CancellationException ex) {
262 }
263 }
264 }
265}
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition Case.java:712
synchronized static Logger getLogger(String name)
Definition Logger.java:124
void setSelectedDataSources(List< Long > selectedDataSources)
static void doReportWizard(String configName, boolean displayCaseSpecificData, boolean runReports)
static void saveReportingConfiguration(String configName, WizardDescriptor wiz)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.