Implement module settings persistence for HTML report

This commit is contained in:
Eugene Livis 2019-08-21 16:53:17 -04:00
parent d74e68be49
commit d37354d392
7 changed files with 96 additions and 94 deletions

View File

@ -28,6 +28,11 @@ class HTMLReportModuleSettings implements ReportModuleSettings {
private String header;
private String footer;
HTMLReportModuleSettings() {
this.header = "";
this.footer = "";
}
HTMLReportModuleSettings(String header, String footer) {
this.header = header;
this.footer = footer;

View File

@ -64,7 +64,6 @@ import org.sleuthkit.autopsy.contentviewers.imagetagging.ImageTagsUtil;
import org.sleuthkit.autopsy.coreutils.EscapeUtil;
import org.sleuthkit.autopsy.coreutils.ImageUtils;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.Version;
import org.sleuthkit.autopsy.datamodel.ContentUtils.ExtractFscContentVisitor;
import org.sleuthkit.autopsy.ingest.IngestManager;
@ -99,7 +98,7 @@ class ReportHTML implements TableReportModule {
private Integer rowCount; // number of rows (aka artifacts or tags) for the current data type
private Writer out;
private ReportHTMLConfigurationPanel configPanel;
private final ReportHTMLConfigurationPanel configPanel = new ReportHTMLConfigurationPanel();
private final ReportBranding reportBranding;
@ -118,9 +117,6 @@ class ReportHTML implements TableReportModule {
@Override
public JPanel getConfigurationPanel() {
if (configPanel == null) {
configPanel = new ReportHTMLConfigurationPanel();
}
return configPanel;
}
@ -131,7 +127,7 @@ class ReportHTML implements TableReportModule {
*/
@Override
public ReportModuleSettings getDefaultConfiguration() {
return new NoReportModuleSettings();
return new HTMLReportModuleSettings();
}
/**
@ -141,7 +137,7 @@ class ReportHTML implements TableReportModule {
*/
@Override
public ReportModuleSettings getConfiguration() {
return new NoReportModuleSettings();
return configPanel.getConfiguration();
}
/**
@ -151,7 +147,17 @@ class ReportHTML implements TableReportModule {
*/
@Override
public void setConfiguration(ReportModuleSettings settings) {
// NO-OP
if (settings instanceof HTMLReportModuleSettings) {
configPanel.setConfiguration((HTMLReportModuleSettings) settings);
return;
}
if (settings instanceof NoReportModuleSettings) {
configPanel.setConfiguration((HTMLReportModuleSettings) getDefaultConfiguration());
return;
}
throw new IllegalArgumentException("Expected settings argument to be an instance of HTMLReportModuleSettings");
}
// Refesh the member variables
@ -396,9 +402,6 @@ class ReportHTML implements TableReportModule {
*/
@Override
public void startReport(String baseReportDir) {
// Save settings
ModuleSettings.setConfigSetting("HTMLReport", "header", configPanel.getHeader()); //NON-NLS
ModuleSettings.setConfigSetting("HTMLReport", "footer", configPanel.getFooter()); //NON-NLS
// Refresh the HTML report
try {
@ -706,8 +709,7 @@ class ReportHTML implements TableReportModule {
*
* @param row Values for each data cell in the row
* @param file The file to link to in the report.
* @param tagName the name of the tag that the content was flagged
* by
* @param tagName the name of the tag that the content was flagged by
* @param linkHTMLContent the html that will be the body of the link
*/
public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
@ -834,7 +836,7 @@ class ReportHTML implements TableReportModule {
.getTagsManager().getContentTagsByContent(file);
List<ImageTagRegion> imageTags = getTaggedRegions(contentTags);
if(!imageTags.isEmpty()) {
if (!imageTags.isEmpty()) {
//Write the tags to the fullsize and thumbnail images
BufferedImage fullImageWithTags = ImageTagsUtil.getImageWithTags(file, imageTags);
@ -864,7 +866,7 @@ class ReportHTML implements TableReportModule {
}
// save copies of the orginal image and thumbnail image
if(thumbnailPath == null) {
if (thumbnailPath == null) {
thumbnailPath = prepareThumbnail(file);
}
@ -885,7 +887,7 @@ class ReportHTML implements TableReportModule {
.append("\" target=\"_top\"><img src=\"")
.append(thumbnailPath).append("\" title=\"").append(nameInImage).append("\"/></a><br>") //NON-NLS
.append(file.getName()).append("<br>"); //NON-NLS
if(imageWithTagsFullPath != null) {
if (imageWithTagsFullPath != null) {
linkToThumbnail.append("<a href=\"").append(contentPath).append("\" target=\"_top\">View Original</a><br>");
}

View File

@ -18,8 +18,6 @@
*/
package org.sleuthkit.autopsy.report;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
/**
* The panel shown for all TableReportModules when configuring report modules.
*/
@ -31,14 +29,8 @@ final class ReportHTMLConfigurationPanel extends javax.swing.JPanel {
*/
ReportHTMLConfigurationPanel() {
initComponents();
// Load settings
// ELTODO REMOVE
String header = ModuleSettings.getConfigSetting("HTMLReport", "header"); //NON-NLS
String footer = ModuleSettings.getConfigSetting("HTMLReport", "footer"); //NON-NLS
headerTextField.setText(header != null ? header : "");
footerTextField.setText(footer != null ? footer : "");
headerTextField.setText("");
footerTextField.setText("");
}
void setConfiguration(HTMLReportModuleSettings settings) {

View File

@ -32,7 +32,7 @@ final class ReportModuleConfig implements Serializable {
private boolean enabled;
/**
* Creates ModuleStatus object.
* Creates ReportModuleConfig object.
*
* @param module Implementation of a ReportModule interface
* @param enabled Boolean flag whether the module is enabled
@ -43,6 +43,19 @@ final class ReportModuleConfig implements Serializable {
this.settings = new NoReportModuleSettings();
}
/**
* Creates ReportModuleConfig object.
*
* @param module Implementation of a ReportModule interface
* @param enabled Boolean flag whether the module is enabled
* @param settings Report module settings object
*/
ReportModuleConfig(ReportModule module, boolean enabled, ReportModuleSettings settings) {
this.moduleName = module.getClass().getCanonicalName();
this.enabled = enabled;
this.settings = settings;
}
/**
* Get full canonical report module name.
*

View File

@ -22,6 +22,7 @@ import java.awt.BorderLayout;
import java.awt.Component;
import java.util.ArrayList;
import static java.util.Collections.swap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@ -50,7 +51,7 @@ final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
private List<TableReportModule> tableModules = new ArrayList<>();
private List<FileReportModule> fileModules = new ArrayList<>();
private PortableCaseReportModule portableCaseModule;
private final Map<String, ReportModuleConfig> moduleConfigs;
private Map<String, ReportModuleConfig> moduleConfigs;
private Integer selectedIndex;
/**
@ -120,10 +121,6 @@ final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
if (moduleConfigs == null) {
// get default module configuration
settings = module.getDefaultConfiguration();
// update config for this module
ReportModuleConfig moduleConfig = new ReportModuleConfig(module, false);
moduleConfig.setModuleSettings(settings);
moduleConfigs.put(module.getName(), moduleConfig);
} else {
// get configuration for this module
ReportModuleConfig config = moduleConfigs.get(module.getClass().getCanonicalName());
@ -133,10 +130,6 @@ final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
} else {
// get default module configuration
settings = module.getDefaultConfiguration();
// update config for this module
ReportModuleConfig moduleConfig = new ReportModuleConfig(module, false);
moduleConfig.setModuleSettings(settings);
moduleConfigs.put(module.getName(), moduleConfig);
}
}
// set module configuration
@ -230,14 +223,11 @@ final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
* @return
*/
Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
moduleConfigs = new HashMap<>();
for (ReportModule module : modules) {
// get updated module configuration
ReportModuleSettings settings = module.getConfiguration();
// update ReportModuleConfig for this module
ReportModuleConfig moduleConfig = new ReportModuleConfig(module, false);
moduleConfig.setModuleSettings(settings);
moduleConfigs.put(module.getName(), moduleConfig);
moduleConfigs.put(module.getClass().getCanonicalName(), new ReportModuleConfig(module, false, settings));
}
return moduleConfigs;
}

View File

@ -57,7 +57,7 @@ public final class ReportWizardAction extends CallableSystemAction implements Pr
private static final Logger logger = Logger.getLogger(ReportWizardAction.class.getName());
private static final String REPORTING_CONFIGURATION_NAME = "ReportAction";
private static final boolean DISPLAY_CASE_SPECIFIC_DATA = false; //ELTODO true;
private static final boolean DISPLAY_CASE_SPECIFIC_DATA = true;
private static final boolean RUN_REPORTS = true;
private final JButton toolbarButton = new JButton();
private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text");

View File

@ -108,7 +108,7 @@ final class ReportingConfigLoader {
// read each ReportModuleSettings object individually
for (Iterator<Entry<String, ReportModuleConfig>> iterator = moduleConfigs.entrySet().iterator(); iterator.hasNext();) {
ReportModuleConfig moduleConfig = (ReportModuleConfig) iterator.next().getValue();
ReportModuleConfig moduleConfig = iterator.next().getValue();
filePath = reportDirPath.toString() + File.separator + moduleConfig.getModuleClassName() + REPORT_SETTINGS_FILE_EXTENSION;
try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(filePath))) {
moduleConfig.setModuleSettings((ReportModuleSettings) in.readObject());