mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-19 11:07:43 +00:00
Tidy up IngestJobSettings
This commit is contained in:
parent
29c5ed1f0f
commit
4d594948e8
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2011-2017 Basis Technology Corp.
|
* Copyright 2014-2018 Basis Technology Corp.
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -26,12 +26,14 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.openide.util.io.NbObjectInputStream;
|
import org.openide.util.io.NbObjectInputStream;
|
||||||
import org.openide.util.io.NbObjectOutputStream;
|
import org.openide.util.io.NbObjectOutputStream;
|
||||||
@ -43,113 +45,93 @@ import org.sleuthkit.autopsy.modules.interestingitems.FilesSet;
|
|||||||
import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager;
|
import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates the ingest job settings for a particular execution context.
|
* The settings for an ingest job.
|
||||||
* Examples of execution contexts include the add data source wizard and the run
|
|
||||||
* ingest modules dialog. Different execution contexts may have different ingest
|
|
||||||
* job settings.
|
|
||||||
*/
|
*/
|
||||||
public class IngestJobSettings {
|
public class IngestJobSettings {
|
||||||
|
|
||||||
private static final String ENABLED_MODULES_KEY = "Enabled_Ingest_Modules"; //NON-NLS
|
private static final String ENABLED_MODULES_PROPERTY = "Enabled_Ingest_Modules"; //NON-NLS
|
||||||
private static final String DISABLED_MODULES_KEY = "Disabled_Ingest_Modules"; //NON-NLS
|
private static final String DISABLED_MODULES_PROPERTY = "Disabled_Ingest_Modules"; //NON-NLS
|
||||||
private static final String LAST_FILE_INGEST_FILTER_KEY = "Last_File_Ingest_Filter"; //NON-NLS
|
private static final String LAST_FILE_INGEST_FILTER_PROPERTY = "Last_File_Ingest_Filter"; //NON-NLS
|
||||||
private static final String MODULE_SETTINGS_FOLDER = "IngestModuleSettings"; //NON-NLS
|
private static final String MODULE_SETTINGS_FOLDER = "IngestModuleSettings"; //NON-NLS
|
||||||
private static final String MODULE_SETTINGS_FOLDER_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), IngestJobSettings.MODULE_SETTINGS_FOLDER).toAbsolutePath().toString();
|
private static final String MODULE_SETTINGS_FOLDER_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), IngestJobSettings.MODULE_SETTINGS_FOLDER).toAbsolutePath().toString();
|
||||||
private static final String MODULE_SETTINGS_FILE_EXT = ".settings"; //NON-NLS
|
private static final String MODULE_SETTINGS_FILE_EXT = ".settings"; //NON-NLS
|
||||||
private static final Logger LOGGER = Logger.getLogger(IngestJobSettings.class.getName());
|
private static final CharSequence PYTHON_CLASS_PROXY_PREFIX = "org.python.proxies.".subSequence(0, "org.python.proxies.".length() - 1); //NON-NLS
|
||||||
private FilesSet fileIngestFilter;
|
private static final Logger logger = Logger.getLogger(IngestJobSettings.class.getName());
|
||||||
private String executionContext;
|
|
||||||
private final IngestType ingestType;
|
private final IngestType ingestType;
|
||||||
private String moduleSettingsFolderPath;
|
|
||||||
private static final CharSequence pythonModuleSettingsPrefixCS = "org.python.proxies.".subSequence(0, "org.python.proxies.".length() - 1); //NON-NLS
|
|
||||||
private final List<IngestModuleTemplate> moduleTemplates;
|
private final List<IngestModuleTemplate> moduleTemplates;
|
||||||
private final List<String> warnings;
|
private final List<String> warnings;
|
||||||
|
private String executionContext;
|
||||||
|
private FilesSet fileIngestFilter;
|
||||||
|
private String moduleSettingsFolderPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last selected FileIngestFilter saved in settings which is
|
* Gets the path to the module settings folder for a given execution
|
||||||
* represented by a FilesSet, if the last selected filter is null the
|
* context.
|
||||||
* default filter will be returned.
|
|
||||||
*
|
*
|
||||||
* @return FilesSet which represents the FileIngestFilter
|
* Some examples of execution contexts include the Add Data Source wizard,
|
||||||
|
* the Run Ingest Modules dialog, and auto ingest. Different execution
|
||||||
|
* contexts may have different ingest job settings.
|
||||||
|
*
|
||||||
|
* @return The execution context identifier.
|
||||||
|
*
|
||||||
|
* @return The path to the module settings folder
|
||||||
*/
|
*/
|
||||||
FilesSet getFileIngestFilter() {
|
static Path getSavedModuleSettingsFolder(String executionContext) {
|
||||||
if (fileIngestFilter == null) {
|
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext);
|
||||||
fileIngestFilter = FilesSetsManager.getDefaultFilter();
|
|
||||||
}
|
|
||||||
return fileIngestFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the FileIngestFilter which is currently being used by ingest.
|
* Loads the ingest job settings for a given execution context. If settings
|
||||||
|
* for the context have not been previously saved, default settings are
|
||||||
|
* used.
|
||||||
*
|
*
|
||||||
* @param fileIngestFilter the FilesSet which represents the
|
* Some examples of execution contexts include the Add Data Source wizard,
|
||||||
* FileIngestFilter
|
* the Run Ingest Modules dialog, and auto ingest. Different execution
|
||||||
|
* contexts may have different ingest job settings.
|
||||||
|
*
|
||||||
|
* @param executionContext The execution context identifier.
|
||||||
*/
|
*/
|
||||||
void setFileIngestFilter(FilesSet fileIngestFilter) {
|
public IngestJobSettings(final String executionContext) {
|
||||||
this.fileIngestFilter = fileIngestFilter;
|
this(executionContext, IngestType.ALL_MODULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of ingest modules to run.
|
* Loads the ingest job settings for a given execution context. If settings
|
||||||
*/
|
* for the context have not been previously saved, default settings are
|
||||||
public enum IngestType {
|
* used.
|
||||||
|
|
||||||
/**
|
|
||||||
* Run both data source level and file-level ingest modules.
|
|
||||||
*/
|
|
||||||
ALL_MODULES,
|
|
||||||
/**
|
|
||||||
* Run only data source level ingest modules.
|
|
||||||
*/
|
|
||||||
DATA_SOURCE_ONLY,
|
|
||||||
/**
|
|
||||||
* Run only file level ingest modules.
|
|
||||||
*/
|
|
||||||
FILES_ONLY
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an ingest job settings object for a given execution context.
|
|
||||||
* Examples of execution contexts include the add data source wizard and the
|
|
||||||
* run ingest modules dialog. Different execution contexts may have
|
|
||||||
* different ingest job settings.
|
|
||||||
*
|
*
|
||||||
* @param executionContext The ingest execution context identifier.
|
* Some examples of execution contexts include the Add Data Source wizard,
|
||||||
*/
|
* the Run Ingest Modules dialog, and auto ingest. Different execution
|
||||||
public IngestJobSettings(String executionContext) {
|
* contexts may have different ingest job settings.
|
||||||
this.executionContext = executionContext;
|
|
||||||
this.ingestType = IngestType.ALL_MODULES;
|
|
||||||
this.moduleTemplates = new ArrayList<>();
|
|
||||||
this.warnings = new ArrayList<>();
|
|
||||||
this.createSavedModuleSettingsFolder();
|
|
||||||
this.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an ingest job settings object for a given context. Examples of
|
|
||||||
* execution contexts include the add data source wizard and the run ingest
|
|
||||||
* modules dialog. Different execution contexts may have different ingest
|
|
||||||
* job settings.
|
|
||||||
*
|
*
|
||||||
* @param context The context identifier string.
|
* @param executionContext The execution context identifier.
|
||||||
* @param ingestType The type of modules ingest is running.
|
* @param ingestType Whether to run all ingest modules, data source
|
||||||
|
* level ingest modules only, or file level ingest
|
||||||
|
* modules only.
|
||||||
*/
|
*/
|
||||||
public IngestJobSettings(String context, IngestType ingestType) {
|
public IngestJobSettings(String executionContext, IngestType ingestType) {
|
||||||
this.ingestType = ingestType;
|
this.ingestType = ingestType;
|
||||||
|
|
||||||
if (this.ingestType.equals(IngestType.ALL_MODULES)) {
|
|
||||||
this.executionContext = context;
|
|
||||||
} else {
|
|
||||||
this.executionContext = context + "." + this.ingestType.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.moduleTemplates = new ArrayList<>();
|
this.moduleTemplates = new ArrayList<>();
|
||||||
|
|
||||||
this.warnings = new ArrayList<>();
|
this.warnings = new ArrayList<>();
|
||||||
|
if (this.ingestType.equals(IngestType.ALL_MODULES)) {
|
||||||
|
this.executionContext = executionContext;
|
||||||
|
} else {
|
||||||
|
this.executionContext = executionContext + "." + this.ingestType.name();
|
||||||
|
}
|
||||||
this.createSavedModuleSettingsFolder();
|
this.createSavedModuleSettingsFolder();
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the path to the module settings folder for these ingest job
|
||||||
|
* settings.
|
||||||
|
*
|
||||||
|
* @return The path to the ingest module settings folder.
|
||||||
|
*/
|
||||||
|
public Path getSavedModuleSettingsFolder() {
|
||||||
|
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves these ingest job settings.
|
* Saves these ingest job settings.
|
||||||
*/
|
*/
|
||||||
@ -158,11 +140,13 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the settings with a new context name removing the old profile
|
* Saves these ingest job settings for use in a different execution context.
|
||||||
* folder
|
|
||||||
*
|
*
|
||||||
* @param executionContext will be used to name the new folder for storing
|
* Some examples of execution contexts include the Add Data Source wizard,
|
||||||
* the settings
|
* the Run Ingest Modules dialog, and auto ingest. Different execution
|
||||||
|
* contexts may have different ingest job settings.
|
||||||
|
*
|
||||||
|
* @param executionContext The new execution context.
|
||||||
*/
|
*/
|
||||||
void saveAs(String executionContext) {
|
void saveAs(String executionContext) {
|
||||||
this.executionContext = executionContext;
|
this.executionContext = executionContext;
|
||||||
@ -171,20 +155,8 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ingest execution context identifier. Examples of execution
|
* Gets and clears any accumulated warnings associated with the loading or
|
||||||
* contexts include the add data source wizard and the run ingest modules
|
* saving of these ingest job settings.
|
||||||
* dialog. Different execution contexts may have different ingest job
|
|
||||||
* settings.
|
|
||||||
*
|
|
||||||
* @return The execution context identifier.
|
|
||||||
*/
|
|
||||||
String getExecutionContext() {
|
|
||||||
return this.executionContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets and clears any accumulated warnings associated with these ingest job
|
|
||||||
* settings.
|
|
||||||
*
|
*
|
||||||
* @return A list of warning messages, possibly empty.
|
* @return A list of warning messages, possibly empty.
|
||||||
*/
|
*/
|
||||||
@ -195,7 +167,41 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ingest module templates part of these ingest job settings.
|
* Gets the execution context identifier.
|
||||||
|
*
|
||||||
|
* Some examples of execution contexts include the Add Data Source wizard,
|
||||||
|
* the Run Ingest Modules dialog, and auto ingest. Different execution
|
||||||
|
* contexts may have different ingest job settings.
|
||||||
|
*
|
||||||
|
* @return The execution context identifier.
|
||||||
|
*/
|
||||||
|
String getExecutionContext() {
|
||||||
|
return this.executionContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the file ingest filter for the ingest job.
|
||||||
|
*
|
||||||
|
* @return FilesSet The filter as a files set.
|
||||||
|
*/
|
||||||
|
FilesSet getFileIngestFilter() {
|
||||||
|
if (fileIngestFilter == null) {
|
||||||
|
fileIngestFilter = FilesSetsManager.getDefaultFilter();
|
||||||
|
}
|
||||||
|
return fileIngestFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the file ingest filter for the ingest job.
|
||||||
|
*
|
||||||
|
* @param fileIngestFilter The filter as a files set.
|
||||||
|
*/
|
||||||
|
void setFileIngestFilter(FilesSet fileIngestFilter) {
|
||||||
|
this.fileIngestFilter = fileIngestFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the enabled ingest module templates for the ingest job.
|
||||||
*
|
*
|
||||||
* @return The list of ingest module templates.
|
* @return The list of ingest module templates.
|
||||||
*/
|
*/
|
||||||
@ -204,8 +210,17 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the enabled ingest module templates part of these ingest job
|
* Sets the enabled ingest module templates for the ingest job.
|
||||||
* settings.
|
*
|
||||||
|
* @param moduleTemplates The ingest module templates.
|
||||||
|
*/
|
||||||
|
void setIngestModuleTemplates(List<IngestModuleTemplate> moduleTemplates) {
|
||||||
|
this.moduleTemplates.clear();
|
||||||
|
this.moduleTemplates.addAll(moduleTemplates);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the enabled ingest module templates for this ingest job.
|
||||||
*
|
*
|
||||||
* @return The list of enabled ingest module templates.
|
* @return The list of enabled ingest module templates.
|
||||||
*/
|
*/
|
||||||
@ -220,29 +235,12 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the ingest module templates part of these ingest job settings.
|
* Gets the process unallocated space flag for this ingest job.
|
||||||
*
|
|
||||||
* @param moduleTemplates The ingest module templates.
|
|
||||||
*/
|
|
||||||
void setIngestModuleTemplates(List<IngestModuleTemplate> moduleTemplates) {
|
|
||||||
this.moduleTemplates.clear();
|
|
||||||
this.moduleTemplates.addAll(moduleTemplates);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the process unallocated space flag part of these ingest job
|
|
||||||
* settings.
|
|
||||||
*
|
*
|
||||||
* @return True or false.
|
* @return True or false.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
boolean getProcessUnallocatedSpace() {
|
boolean getProcessUnallocatedSpace() {
|
||||||
/*
|
|
||||||
* Used to be a simple flag but the processUnallocated checkbox was
|
|
||||||
* changed to a skip unallocated. This was due to the FileIngestFilters
|
|
||||||
* needing a default value which did not skip unallocated files. This
|
|
||||||
* method exists to maintain existing functionality.
|
|
||||||
*/
|
|
||||||
boolean processUnallocated = true;
|
boolean processUnallocated = true;
|
||||||
if (!Objects.isNull(this.fileIngestFilter)) {
|
if (!Objects.isNull(this.fileIngestFilter)) {
|
||||||
processUnallocated = (this.fileIngestFilter.ingoresUnallocatedSpace() == false);
|
processUnallocated = (this.fileIngestFilter.ingoresUnallocatedSpace() == false);
|
||||||
@ -251,29 +249,7 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the path to the ingest module settings folder.
|
* Creates the module folder for these ingest job settings.
|
||||||
*
|
|
||||||
* @return path to the module settings folder
|
|
||||||
*/
|
|
||||||
public Path getSavedModuleSettingsFolder() {
|
|
||||||
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the path to the ingest module settings folder from a static
|
|
||||||
* manner.
|
|
||||||
*
|
|
||||||
* @param context specify the context of the folder you wish to get
|
|
||||||
*
|
|
||||||
* @return path to the module settings folder
|
|
||||||
*/
|
|
||||||
static Path getSavedModuleSettingsFolder(String context) {
|
|
||||||
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the folder for saving the individual ingest module settings part
|
|
||||||
* of these ingest job settings.
|
|
||||||
*/
|
*/
|
||||||
private void createSavedModuleSettingsFolder() {
|
private void createSavedModuleSettingsFolder() {
|
||||||
try {
|
try {
|
||||||
@ -281,13 +257,14 @@ public class IngestJobSettings {
|
|||||||
Files.createDirectories(folder);
|
Files.createDirectories(folder);
|
||||||
this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
|
this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
|
||||||
} catch (IOException | SecurityException ex) {
|
} catch (IOException | SecurityException ex) {
|
||||||
LOGGER.log(Level.SEVERE, "Failed to create ingest module settings directory " + this.moduleSettingsFolderPath, ex); //NON-NLS
|
logger.log(Level.SEVERE, "Failed to create ingest module settings directory " + this.moduleSettingsFolderPath, ex); //NON-NLS
|
||||||
this.warnings.add(NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.createModuleSettingsFolder.warning")); //NON-NLS
|
this.warnings.add(NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.createModuleSettingsFolder.warning")); //NON-NLS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the saved or default ingest job settings context into memory.
|
* Loads the saved or default ingest job settings for the execution context
|
||||||
|
* into memory.
|
||||||
*/
|
*/
|
||||||
private void load() {
|
private void load() {
|
||||||
/**
|
/**
|
||||||
@ -317,8 +294,8 @@ public class IngestJobSettings {
|
|||||||
* Get the enabled/disabled ingest modules settings for this context. By
|
* Get the enabled/disabled ingest modules settings for this context. By
|
||||||
* default, all loaded modules are enabled.
|
* default, all loaded modules are enabled.
|
||||||
*/
|
*/
|
||||||
HashSet<String> enabledModuleNames = getModulesNamesFromSetting(executionContext, IngestJobSettings.ENABLED_MODULES_KEY, makeCommaSeparatedValuesList(loadedModuleNames));
|
HashSet<String> enabledModuleNames = getModulesNames(executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(loadedModuleNames));
|
||||||
HashSet<String> disabledModuleNames = getModulesNamesFromSetting(executionContext, IngestJobSettings.DISABLED_MODULES_KEY, ""); //NON-NLS
|
HashSet<String> disabledModuleNames = getModulesNames(executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, ""); //NON-NLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for missing modules and create warnings if any are found.
|
* Check for missing modules and create warnings if any are found.
|
||||||
@ -338,7 +315,7 @@ public class IngestJobSettings {
|
|||||||
enabledModuleNames.remove(moduleName);
|
enabledModuleNames.remove(moduleName);
|
||||||
disabledModuleNames.remove(moduleName);
|
disabledModuleNames.remove(moduleName);
|
||||||
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.missingModule.warning", moduleName); //NON-NLS
|
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.missingModule.warning", moduleName); //NON-NLS
|
||||||
LOGGER.log(Level.WARNING, warning);
|
logger.log(Level.WARNING, warning);
|
||||||
this.warnings.add(warning);
|
this.warnings.add(warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,14 +344,14 @@ public class IngestJobSettings {
|
|||||||
* Update the enabled/disabled ingest module settings for this context
|
* Update the enabled/disabled ingest module settings for this context
|
||||||
* to reflect any missing modules or newly discovered modules.
|
* to reflect any missing modules or newly discovered modules.
|
||||||
*/
|
*/
|
||||||
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.ENABLED_MODULES_KEY, makeCommaSeparatedValuesList(enabledModuleNames));
|
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(enabledModuleNames));
|
||||||
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.DISABLED_MODULES_KEY, makeCommaSeparatedValuesList(disabledModuleNames));
|
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(disabledModuleNames));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore the last used File Ingest Filter
|
* Restore the last used File Ingest Filter
|
||||||
*/
|
*/
|
||||||
if (ModuleSettings.settingExists(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_KEY) == false) {
|
if (ModuleSettings.settingExists(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY) == false) {
|
||||||
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_KEY, FilesSetsManager.getDefaultFilter().getName());
|
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY, FilesSetsManager.getDefaultFilter().getName());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Map<String, FilesSet> fileIngestFilters = FilesSetsManager.getInstance()
|
Map<String, FilesSet> fileIngestFilters = FilesSetsManager.getInstance()
|
||||||
@ -382,35 +359,37 @@ public class IngestJobSettings {
|
|||||||
for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) {
|
for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) {
|
||||||
fileIngestFilters.put(fSet.getName(), fSet);
|
fileIngestFilters.put(fSet.getName(), fSet);
|
||||||
}
|
}
|
||||||
this.fileIngestFilter = fileIngestFilters.get(ModuleSettings.getConfigSetting(
|
this.fileIngestFilter = fileIngestFilters.get(ModuleSettings.getConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY));
|
||||||
this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_KEY));
|
|
||||||
} catch (FilesSetsManager.FilesSetsManagerException ex) {
|
} catch (FilesSetsManager.FilesSetsManagerException ex) {
|
||||||
this.fileIngestFilter = FilesSetsManager.getDefaultFilter();
|
this.fileIngestFilter = FilesSetsManager.getDefaultFilter();
|
||||||
LOGGER.log(Level.SEVERE, "Failed to get file ingest filter from .properties file, default filter being used", ex); //NON-NLS
|
logger.log(Level.SEVERE, "Failed to get file ingest filter from .properties file, default filter being used", ex); //NON-NLS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the module names for a given key within these ingest job settings.
|
* Gets a list of enabled module names from the properties file for the
|
||||||
|
* execution context of these ingest job settings.
|
||||||
*
|
*
|
||||||
* @param context The identifier for the context for which to get the
|
* @param executionContext The execution context identifier.
|
||||||
* module names, e.g., the Add Data Source wizard or
|
* @param propertyName The property name.
|
||||||
* Run Ingest Modules context.
|
* @param defaultSetting The default list of module names to se and return
|
||||||
* @param key The key string.
|
* if the property does not exist.
|
||||||
* @param defaultSetting The default list of module names.
|
|
||||||
*
|
*
|
||||||
* @return The list of module names associated with the key.
|
* @return
|
||||||
*/
|
*/
|
||||||
private static HashSet<String> getModulesNamesFromSetting(String context, String key, String defaultSetting) {
|
private static HashSet<String> getModulesNames(String executionContext, String propertyName, String defaultSetting) {
|
||||||
if (ModuleSettings.settingExists(context, key) == false) {
|
if (ModuleSettings.settingExists(executionContext, propertyName) == false) {
|
||||||
ModuleSettings.setConfigSetting(context, key, defaultSetting);
|
ModuleSettings.setConfigSetting(executionContext, propertyName, defaultSetting);
|
||||||
}
|
}
|
||||||
HashSet<String> moduleNames = new HashSet<>();
|
HashSet<String> moduleNames = new HashSet<>();
|
||||||
String modulesSetting = ModuleSettings.getConfigSetting(context, key);
|
String modulesSetting = ModuleSettings.getConfigSetting(executionContext, propertyName);
|
||||||
if (!modulesSetting.isEmpty()) {
|
if (!modulesSetting.isEmpty()) {
|
||||||
String[] settingNames = modulesSetting.split(", ");
|
String[] settingNames = modulesSetting.split(", ");
|
||||||
for (String name : settingNames) {
|
for (String name : settingNames) {
|
||||||
// Map some old core module names to the current core module names.
|
/*
|
||||||
|
* Map some obsolete core ingest module names to the current
|
||||||
|
* core ingest module names.
|
||||||
|
*/
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "Thunderbird Parser": //NON-NLS
|
case "Thunderbird Parser": //NON-NLS
|
||||||
case "MBox Parser": //NON-NLS
|
case "MBox Parser": //NON-NLS
|
||||||
@ -435,7 +414,7 @@ public class IngestJobSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a set which contains all the names of enabled modules for the
|
* Gets a set which contains all the names of enabled modules for the
|
||||||
* specified context.
|
* specified context.
|
||||||
*
|
*
|
||||||
* @param context -the execution context (profile name) to check
|
* @param context -the execution context (profile name) to check
|
||||||
@ -443,7 +422,7 @@ public class IngestJobSettings {
|
|||||||
* @return the names of the enabled modules
|
* @return the names of the enabled modules
|
||||||
*/
|
*/
|
||||||
static List<String> getEnabledModules(String context) {
|
static List<String> getEnabledModules(String context) {
|
||||||
return new ArrayList<>(getModulesNamesFromSetting(context, ENABLED_MODULES_KEY, ""));
|
return new ArrayList<>(getModulesNames(context, ENABLED_MODULES_PROPERTY, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -457,14 +436,13 @@ public class IngestJobSettings {
|
|||||||
* @return True or false
|
* @return True or false
|
||||||
*/
|
*/
|
||||||
private boolean isPythonModuleSettingsFile(String moduleSettingsFilePath) {
|
private boolean isPythonModuleSettingsFile(String moduleSettingsFilePath) {
|
||||||
return moduleSettingsFilePath.contains(pythonModuleSettingsPrefixCS);
|
return moduleSettingsFilePath.contains(PYTHON_CLASS_PROXY_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the saved or default ingest job settings for a given ingest module
|
* Gets the saved or default ingest job settings for a given ingest module.
|
||||||
* for these ingest job settings.
|
|
||||||
*
|
*
|
||||||
* @param factory The ingest module factory for an ingest module.
|
* @param factory The ingest module factory.
|
||||||
*
|
*
|
||||||
* @return The ingest module settings.
|
* @return The ingest module settings.
|
||||||
*/
|
*/
|
||||||
@ -478,7 +456,7 @@ public class IngestJobSettings {
|
|||||||
settings = (IngestModuleIngestJobSettings) in.readObject();
|
settings = (IngestModuleIngestJobSettings) in.readObject();
|
||||||
} catch (IOException | ClassNotFoundException ex) {
|
} catch (IOException | ClassNotFoundException ex) {
|
||||||
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsLoad.warning", factory.getModuleDisplayName(), this.executionContext); //NON-NLS
|
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsLoad.warning", factory.getModuleDisplayName(), this.executionContext); //NON-NLS
|
||||||
LOGGER.log(Level.WARNING, warning, ex);
|
logger.log(Level.WARNING, warning, ex);
|
||||||
this.warnings.add(warning);
|
this.warnings.add(warning);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -486,7 +464,7 @@ public class IngestJobSettings {
|
|||||||
settings = (IngestModuleIngestJobSettings) in.readObject();
|
settings = (IngestModuleIngestJobSettings) in.readObject();
|
||||||
} catch (IOException | ClassNotFoundException exception) {
|
} catch (IOException | ClassNotFoundException exception) {
|
||||||
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsLoad.warning", factory.getModuleDisplayName(), this.executionContext); //NON-NLS
|
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsLoad.warning", factory.getModuleDisplayName(), this.executionContext); //NON-NLS
|
||||||
LOGGER.log(Level.WARNING, warning, exception);
|
logger.log(Level.WARNING, warning, exception);
|
||||||
this.warnings.add(warning);
|
this.warnings.add(warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -529,18 +507,17 @@ public class IngestJobSettings {
|
|||||||
disabledModuleNames.add(moduleName);
|
disabledModuleNames.add(moduleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.ENABLED_MODULES_KEY, makeCommaSeparatedValuesList(enabledModuleNames));
|
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(enabledModuleNames));
|
||||||
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.DISABLED_MODULES_KEY, makeCommaSeparatedValuesList(disabledModuleNames));
|
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(disabledModuleNames));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the last used File Ingest Filter setting for this context.
|
* Save the last used File Ingest Filter setting for this context.
|
||||||
*/
|
*/
|
||||||
ModuleSettings.setConfigSetting(this.executionContext, LAST_FILE_INGEST_FILTER_KEY, fileIngestFilter.getName());
|
ModuleSettings.setConfigSetting(this.executionContext, LAST_FILE_INGEST_FILTER_PROPERTY, fileIngestFilter.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the ingest job settings for this context for a given ingest
|
* Serializes the ingest job settings for a given ingest module.
|
||||||
* module.
|
|
||||||
*
|
*
|
||||||
* @param factory The ingest module factory for the module.
|
* @param factory The ingest module factory for the module.
|
||||||
* @param settings The ingest job settings for the ingest module
|
* @param settings The ingest job settings for the ingest module
|
||||||
@ -551,32 +528,40 @@ public class IngestJobSettings {
|
|||||||
out.writeObject(settings);
|
out.writeObject(settings);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsSave.warning", factory.getModuleDisplayName(), this.executionContext); //NON-NLS
|
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsSave.warning", factory.getModuleDisplayName(), this.executionContext); //NON-NLS
|
||||||
LOGGER.log(Level.SEVERE, warning, ex);
|
logger.log(Level.SEVERE, warning, ex);
|
||||||
this.warnings.add(warning);
|
this.warnings.add(warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a comma-separated values list from a hash set of strings.
|
* Makes a comma-separated values list from a collection of strings.
|
||||||
*
|
*
|
||||||
* @param input A hash set of strings.
|
* @param collection A collection of strings.
|
||||||
*
|
*
|
||||||
* @return The contents of the hash set as a single string of
|
* @return The contents of the collection as a single string of
|
||||||
* comma-separated values.
|
* comma-separated values.
|
||||||
*/
|
*/
|
||||||
private static String makeCommaSeparatedValuesList(HashSet<String> input) {
|
private static String makeCsvList(Collection<String> collection) {
|
||||||
if (input == null || input.isEmpty()) {
|
return collection.stream().collect(Collectors.joining(","));
|
||||||
return "";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
/**
|
||||||
list.addAll(input);
|
* The type of ingest modules to run.
|
||||||
StringBuilder csvList = new StringBuilder();
|
*/
|
||||||
for (int i = 0; i < list.size() - 1; ++i) {
|
public enum IngestType {
|
||||||
csvList.append(list.get(i)).append(", ");
|
|
||||||
}
|
/**
|
||||||
csvList.append(list.get(list.size() - 1));
|
* Run both data source level and file-level ingest modules.
|
||||||
return csvList.toString();
|
*/
|
||||||
|
ALL_MODULES,
|
||||||
|
/**
|
||||||
|
* Run only data source level ingest modules.
|
||||||
|
*/
|
||||||
|
DATA_SOURCE_ONLY,
|
||||||
|
/**
|
||||||
|
* Run only file level ingest modules.
|
||||||
|
*/
|
||||||
|
FILES_ONLY
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user