Cleanup comments, logging, javadocs etc.

This commit is contained in:
raman-bt 2013-10-18 10:11:47 -04:00
parent f67cd305fc
commit aa01261c9a
6 changed files with 115 additions and 194 deletions

View File

@ -180,10 +180,11 @@ class AddImageWizardChooseDataSourcePanel implements WizardDescriptor.Panel<Wiza
// Prepopulate the image directory from the properties file // Prepopulate the image directory from the properties file
try { try {
/******* RAMAN TBD: all settings read/store needs to be moved into the DSP panel
String lastDataSourceDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_PATH); String lastDataSourceDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_PATH);
String lastDataSourceType = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_TYPE); String lastDataSourceType = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_TYPE);
/******* RAMAN TBD: all settings read/store needs to be moved into the DSP
//set the last path for the content panel for which it was saved //set the last path for the content panel for which it was saved
if (component.getContentType().toString().equals(lastDataSourceType)) { if (component.getContentType().toString().equals(lastDataSourceType)) {
component.setContentPath(lastDataSourceDirectory); component.setContentPath(lastDataSourceDirectory);
@ -226,15 +227,9 @@ class AddImageWizardChooseDataSourcePanel implements WizardDescriptor.Panel<Wiza
@Override @Override
public void storeSettings(WizardDescriptor settings) { public void storeSettings(WizardDescriptor settings) {
/******* RAMAN TBD: all settings read/store needs to be moved into the DSP /******* RAMAN TBD: all settings read/store needs to be moved into the DSP
settings.putProperty(AddImageAction.DATASOURCEPATH_PROP, getComponent().getContentPaths());
settings.putProperty(AddImageAction.DATASOURCETYPE_PROP, getComponent().getContentType());
settings.putProperty(AddImageAction.TIMEZONE_PROP, getComponent().getSelectedTimezone()); // store the timezone
settings.putProperty(AddImageAction.NOFATORPHANS_PROP, Boolean.valueOf(getComponent().getNoFatOrphans()));
//settings.putProperty(AddImageAction.LOOKUPFILES_PROP, getComponent().getLookupFilesCheckboxChecked()); //settings.putProperty(AddImageAction.LOOKUPFILES_PROP, getComponent().getLookupFilesCheckboxChecked());
//settings.putProperty(AddImageAction.SOLR_PROP, getComponent().getIndexImageCheckboxChecked()); //settings.putProperty(AddImageAction.SOLR_PROP, getComponent().getIndexImageCheckboxChecked());
******************/
/******* RAMAN TBD: all settings read/store needs to be moved into the DSP
// Store the path to the first image selected into the properties file // Store the path to the first image selected into the properties file
String firstImage = getComponent().getContentPaths(); String firstImage = getComponent().getContentPaths();
String firstImagePath = firstImage.substring(0, firstImage.lastIndexOf(File.separator) + 1); String firstImagePath = firstImage.substring(0, firstImage.lastIndexOf(File.separator) + 1);

View File

@ -104,12 +104,8 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel {
} }
private void discoverDataSourceProcessors() { private void discoverDataSourceProcessors() {
logger.log(Level.INFO, "RAMAN discoverDataSourceProcessors()...");
for (DataSourceProcessor dsProcessor: Lookup.getDefault().lookupAll(DataSourceProcessor.class)) { for (DataSourceProcessor dsProcessor: Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
logger.log(Level.INFO, "RAMAN discoverDataSourceProcessors()L found a DSP for type = " + dsProcessor.getType() );
if (!datasourceProcessorsMap.containsKey(dsProcessor.getType()) ) { if (!datasourceProcessorsMap.containsKey(dsProcessor.getType()) ) {
if (!datasourceProcessorsMap.containsKey(dsProcessor.getType()) ) { if (!datasourceProcessorsMap.containsKey(dsProcessor.getType()) ) {
@ -117,7 +113,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel {
datasourceProcessorsMap.put(dsProcessor.getType(), dsProcessor); datasourceProcessorsMap.put(dsProcessor.getType(), dsProcessor);
} }
else { else {
logger.log(Level.SEVERE, "RAMAN discoverDataSourceProcessors(): A DataSourceProcessor already exisits for type = " + dsProcessor.getType() ); logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = " + dsProcessor.getType() );
} }
} }
} }

View File

@ -226,18 +226,13 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.Panel<WizardDe
} }
/** /**
* Start the Data source handling by kicking of the selected DataSourceProcessor * Starts the Data source processing by kicking off the selected DataSourceProcessor
*/ */
private void startDataSourceProcessing(WizardDescriptor settings) { private void startDataSourceProcessing(WizardDescriptor settings) {
logger.log(Level.INFO, "RAMAN startDataSourceProcessing()...");
// get the selected DSProcessor
dsProcessor = dataSourcePanel.getComponent().GetCurrentDSProcessor();
// Add a cleanup task to interrupt the background process if the
// Add a cleanup task to interrupt the backgroud process if the
// wizard exits while the background process is running. // wizard exits while the background process is running.
cleanupTask = addImageAction.new CleanupTask() { cleanupTask = addImageAction.new CleanupTask() {
@Override @Override
@ -245,10 +240,12 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.Panel<WizardDe
cancelDataSourceProcessing(); cancelDataSourceProcessing();
} }
}; };
// RAMAN TBD: this cleanup task needs to be cancelled, if dsProcessor runs successfully
cleanupTask.enable(); cleanupTask.enable();
// get the selected DSProcessor
dsProcessor = dataSourcePanel.getComponent().GetCurrentDSProcessor();
DSPCallback cbObj = new DSPCallback () { DSPCallback cbObj = new DSPCallback () {
@Override @Override
public void doneEDT(DSPCallback.DSP_Result result, List<String> errList, List<Content> contents) { public void doneEDT(DSPCallback.DSP_Result result, List<String> errList, List<Content> contents) {
@ -264,18 +261,22 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.Panel<WizardDe
} }
/*
* Cancels the data source processing - in case the users presses 'Cancel'
*/
private void cancelDataSourceProcessing() { private void cancelDataSourceProcessing() {
logger.log(Level.INFO, "RAMAN cancelDataSourceProcessing().");
dsProcessor.cancel(); dsProcessor.cancel();
} }
/*
* Callback for the data source processor.
* Invoked by the DSP on the EDT thread, when it finishes processing the data source.
*/
private void dataSourceProcessorDone(DSPCallback.DSP_Result result, List<String> errList, List<Content> contents) { private void dataSourceProcessorDone(DSPCallback.DSP_Result result, List<String> errList, List<Content> contents) {
logger.log(Level.INFO, "RAMAN dataSourceProcessorDone().");
// disable the cleanup task // disable the cleanup task
cleanupTask.disable(); cleanupTask.disable();
// Get attention for the process finish // Get attention for the process finish
java.awt.Toolkit.getDefaultToolkit().beep(); //BEEP! java.awt.Toolkit.getDefaultToolkit().beep(); //BEEP!
AddImageWizardAddingProgressVisual panel = progressPanel.getComponent(); AddImageWizardAddingProgressVisual panel = progressPanel.getComponent();
@ -295,8 +296,8 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.Panel<WizardDe
//if errors, display them on the progress panel //if errors, display them on the progress panel
for ( String err: errList ) { for ( String err: errList ) {
// RAMAN TBD: there should be an error level for each error // RAMANM TBD: there probably should be an error level for each error
progressPanel.addErrors(err, false); progressPanel.addErrors(err, false);
} }
newContents.clear(); newContents.clear();

View File

@ -1,96 +0,0 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2012 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.casemodule;
import java.beans.PropertyChangeListener;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.util.List;
/************
abstract class ContentTypePanel extends JPanel {
// Collection of panels that are dynamically discovered and registered
private static List<ContentTypePanel> registeredPanels = new ArrayList<ContentTypePanel>();;
public static void RegisterPanel(ContentTypePanel panel)
{
// RAMAN TBD: check if this panel is already regsitered...
registeredPanels.add(panel);
}
//public enum ContentType{IMAGE, DISK, LOCAL};
private String contentType;
//
// * Returns a list off all the panels extending ImageTypePanel.
// * @return list of all ImageTypePanels
//
public static ContentTypePanel[] getPanels() {
//return new ContentTypePanel[] {ImageFilePanel.getDefault(), LocalDiskPanel.getDefault(), LocalFilesPanel.getDefault() };
return registeredPanels.toArray(new ContentTypePanel[registeredPanels.size()]);
}
//
// * Return the path of the selected content in this panel.
// * @return paths to selected content (one or more if multiselect supported)
//
abstract public String getContentPaths();
//
// * Set the selected content in this panel to the provided path.
// * This function is optional.
// * @param s path to selected content
//
abstract public void setContentPath(String s);
//
// * Get content type (image, disk, local file) of the source this wizard panel is for
// * @return ContentType of the source panel
//
abstract public String getContentType();
//
// * Returns if the next button should be enabled in the current wizard.
// * @return true if the next button should be enabled, false otherwise
//
abstract public boolean enableNext();
//
// * Tells this panel to reset itself
//
abstract public void reset();
//
// * Tells this panel it has been selected.
//
abstract public void select();
}
***************/

View File

@ -34,81 +34,101 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DSPCallback;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
/** /**
* * Image data source processor.
* @author raman * Handles the addition of "disk images" to Autopsy.
*
* An instance of this class is created via the Netbeans Lookup() method.
*
*/ */
@ServiceProvider(service = DataSourceProcessor.class) @ServiceProvider(service = DataSourceProcessor.class)
public class ImageDSProcessor implements DataSourceProcessor { public class ImageDSProcessor implements DataSourceProcessor {
static final Logger logger = Logger.getLogger(ImageDSProcessor.class.getName()); static final Logger logger = Logger.getLogger(ImageDSProcessor.class.getName());
// The Config UI panel that plugins into the Choose Data Source Wizard
private ImageFilePanel imageFilePanel; private ImageFilePanel imageFilePanel;
// The Background task that does the actual work of adding the image
private AddImageTask addImageTask; private AddImageTask addImageTask;
// true of cancelled by the caller
private boolean cancelled = false; private boolean cancelled = false;
DSPCallback callbackObj = null; DSPCallback callbackObj = null;
// set to TRUE if the image options have been set via API and config Jpanel should be ignored // set to TRUE if the image options have been set via API and config Jpanel should be ignored
private boolean imageOptionsSet = false; private boolean imageOptionsSet = false;
// image options
private String imagePath; private String imagePath;
private String timeZone; private String timeZone;
private boolean noFatOrphans; private boolean noFatOrphans;
/*
* A no argument constructor is required for the NM lookup() method to create an object
*/
public ImageDSProcessor() { public ImageDSProcessor() {
logger.log(Level.INFO, "RAMAN ImageDSProcessor()...");
// Create the config panel // Create the config panel
imageFilePanel = ImageFilePanel.getDefault(); imageFilePanel = ImageFilePanel.getDefault();
} }
/**
* Returns the Data source type (string) handled by this DSP
*
* @return String the data source type
**/
@Override @Override
public String getType() { public String getType() {
logger.log(Level.INFO, "RAMAN getName()...");
return imageFilePanel.getContentType(); return imageFilePanel.getContentType();
} }
/**
* Returns the JPanel for collecting the Data source information
*
* @return JPanel the config panel
**/
@Override @Override
public JPanel getPanel() { public JPanel getPanel() {
logger.log(Level.INFO, "RAMAN getPanel()...");
// RAMAN TBD: we should ask the panel to preload with any saved settings // RAMAN TBD: we should ask the panel to preload with any saved settings
imageFilePanel.select(); imageFilePanel.select();
return imageFilePanel; return imageFilePanel;
} }
/**
* Validates the data collected by the JPanel
*
* @return String returns NULL if success, error string if there is any errors
**/
@Override @Override
public String validatePanel() { public String validatePanel() {
logger.log(Level.INFO, "RAMAN validatePanel()...");
if (imageFilePanel.validatePanel() ) if (imageFilePanel.validatePanel() )
return null; return null;
else else
return "Error in panel"; return "Error in panel";
} }
/**
* Runs the data source processor.
* This must kick off processing the data source in background
*
* @param progressMonitor Progress monitor to report progress during processing
* @param cbObj callback to call when processing is done.
**/
@Override @Override
public void run(DSPProgressMonitor progressMonitor, DSPCallback cbObj) { public void run(DSPProgressMonitor progressMonitor, DSPCallback cbObj) {
logger.log(Level.INFO, "RAMAN run()...");
callbackObj = cbObj; callbackObj = cbObj;
cancelled = false; cancelled = false;
if (!imageOptionsSet) if (!imageOptionsSet)
{ {
// RAMAN TBD: we should ask the panel to save the current settings now
// get the image options from the panel // get the image options from the panel
imagePath = imageFilePanel.getContentPaths(); imagePath = imageFilePanel.getContentPaths();
timeZone = imageFilePanel.getTimeZone(); timeZone = imageFilePanel.getTimeZone();
@ -124,24 +144,25 @@ public class ImageDSProcessor implements DataSourceProcessor {
return; return;
} }
/**
* Cancel the data source processing
**/
@Override @Override
public void cancel() { public void cancel() {
logger.log(Level.INFO, "RAMAN cancelProcessing()...");
cancelled = true; cancelled = true;
addImageTask.cancelTask(); addImageTask.cancelTask();
return; return;
} }
/**
* Reset the data source processor
**/
@Override @Override
public void reset() { public void reset() {
logger.log(Level.INFO, "RAMAN reset()...");
// reset the config panel // reset the config panel
imageFilePanel.reset(); imageFilePanel.reset();
@ -154,6 +175,15 @@ public class ImageDSProcessor implements DataSourceProcessor {
return; return;
} }
/**
* Sets the data source options externally.
* To be used by a client that does not have a UI and does not use the JPanel to
* collect this information from a user.
*
* @param imgPath path to thew image or first image
* @param String timeZone
* @param noFat whether to parse FAT orphans
**/
public void SetDataSourceOptions(String imgPath, String tz, boolean noFat) { public void SetDataSourceOptions(String imgPath, String tz, boolean noFat) {
this.imagePath = imgPath; this.imagePath = imgPath;
@ -164,7 +194,9 @@ public class ImageDSProcessor implements DataSourceProcessor {
} }
/*
* Background task that actualy adds the image
*/
private class AddImageTask extends SwingWorker<Integer, Integer> { private class AddImageTask extends SwingWorker<Integer, Integer> {
private Logger logger = Logger.getLogger(AddImageTask.class.getName()); private Logger logger = Logger.getLogger(AddImageTask.class.getName());
@ -193,14 +225,19 @@ public class ImageDSProcessor implements DataSourceProcessor {
boolean noFatOrphans; boolean noFatOrphans;
/*
* Sets the name/path and other options for the iimage to be processed
*/
public void SetImageOptions(String imgPath, String tz, boolean noOrphans) { public void SetImageOptions(String imgPath, String tz, boolean noOrphans) {
this.imagePath = imgPath; this.imagePath = imgPath;
this.timeZone = tz; this.timeZone = tz;
this.noFatOrphans = noOrphans; this.noFatOrphans = noOrphans;
} }
/*
* A Swingworker that updates the progressMonitor with the name of the
* directory currently being processed by the AddImageTask
*/
private class CurrentDirectoryFetcher extends SwingWorker<Integer, Integer> { private class CurrentDirectoryFetcher extends SwingWorker<Integer, Integer> {
DSPProgressMonitor progressMonitor; DSPProgressMonitor progressMonitor;
@ -209,7 +246,6 @@ public class ImageDSProcessor implements DataSourceProcessor {
CurrentDirectoryFetcher(DSPProgressMonitor aProgressMonitor, SleuthkitJNI.CaseDbHandle.AddImageProcess proc) { CurrentDirectoryFetcher(DSPProgressMonitor aProgressMonitor, SleuthkitJNI.CaseDbHandle.AddImageProcess proc) {
this.progressMonitor = aProgressMonitor; this.progressMonitor = aProgressMonitor;
this.process = proc; this.process = proc;
// this.progressBar = aProgressBar;
} }
/** /**
@ -252,15 +288,10 @@ public class ImageDSProcessor implements DataSourceProcessor {
*/ */
@Override @Override
protected Integer doInBackground() { protected Integer doInBackground() {
logger.log(Level.INFO, "RAMAN: doInBackground()");
this.setProgress(0); this.setProgress(0);
errorList.clear(); errorList.clear();
try { try {
//lock DB for writes in EWT thread //lock DB for writes in EWT thread
//wait until lock acquired in EWT //wait until lock acquired in EWT
@ -315,8 +346,6 @@ public class ImageDSProcessor implements DataSourceProcessor {
*/ */
private void commitImage() throws Exception { private void commitImage() throws Exception {
logger.log(Level.INFO, "RAMAN: commitImage()...");
long imageId = 0; long imageId = 0;
try { try {
imageId = addImageProcess.commit(); imageId = addImageProcess.commit();
@ -352,43 +381,33 @@ public class ImageDSProcessor implements DataSourceProcessor {
* *
* (called by EventDispatch Thread after doInBackground finishes) * (called by EventDispatch Thread after doInBackground finishes)
* *
* Must Not return without invoking the callBack. * Must Not return without invoking the callBack, unless the caller canceled
*/ */
@Override @Override
protected void done() { protected void done() {
logger.log(Level.INFO, "RAMAN: done()...");
setProgress(100); setProgress(100);
// cancel // cancel the directory fetcher
fetcher.cancel(true); fetcher.cancel(true);
addImageDone = true; addImageDone = true;
// attempt actions that might fail and force the process to stop // attempt actions that might fail and force the process to stop
if (cancelled || hasCritError) { if (cancelled || hasCritError) {
logger.log(Level.INFO, "Handling errors or interruption that occured in add image process"); logger.log(Level.INFO, "Handling errors or interruption that occured in add image process");
revert(); revert();
// Do not return yet. Callback must be called
} }
if (!errorList.isEmpty()) { if (!errorList.isEmpty()) {
logger.log(Level.INFO, "Handling non-critical errors that occured in add image process"); logger.log(Level.INFO, "Handling non-critical errors that occured in add image process");
// error are returned back to the caller
} }
// When everything happens without an error: // When everything happens without an error:
if (!(cancelled || hasCritError)) { if (!(cancelled || hasCritError)) {
try { try {
// Tell the progress monitor we're done
// Tell the panel we're done
progressMonitor.setProgress(100); progressMonitor.setProgress(100);
if (newContents.isEmpty()) { if (newContents.isEmpty()) {
if (addImageProcess != null) { // and if we're done configuring ingest if (addImageProcess != null) { // and if we're done configuring ingest
// commit anything // commit anything
@ -408,8 +427,6 @@ public class ImageDSProcessor implements DataSourceProcessor {
logger.log(Level.INFO, "Assuming image already committed, will not commit."); logger.log(Level.INFO, "Assuming image already committed, will not commit.");
} }
} catch (Exception ex) { } catch (Exception ex) {
//handle unchecked exceptions post image add //handle unchecked exceptions post image add
@ -428,13 +445,14 @@ public class ImageDSProcessor implements DataSourceProcessor {
if (!cancelled) if (!cancelled)
doCallBack(); doCallBack();
return;
} }
/*
void doCallBack() * Call the callback with proper parameters
{ */
logger.log(Level.INFO, "RAMAN In doCallback()"); private void doCallBack()
{
DSPCallback.DSP_Result result; DSPCallback.DSP_Result result;
if (hasCritError) { if (hasCritError) {
@ -446,14 +464,15 @@ public class ImageDSProcessor implements DataSourceProcessor {
else { else {
result = DSPCallback.DSP_Result.NO_ERRORS; result = DSPCallback.DSP_Result.NO_ERRORS;
} }
// invoke the callcak, passing it the result, list of new contents, and list of errors
callbackObj.done(result, errorList, newContents); callbackObj.done(result, errorList, newContents);
} }
/*
void cancelTask() { * cancel the image addition, if possible
*/
logger.log(Level.INFO, "RAMAN: cancelTask()..."); public void cancelTask() {
cancelled = true; cancelled = true;
@ -474,11 +493,11 @@ public class ImageDSProcessor implements DataSourceProcessor {
} }
} }
} }
void interrupt() throws Exception { /*
* Interrurp the add image process if it is still running
*/
private void interrupt() throws Exception {
logger.log(Level.INFO, "RAMAN: interrupt()...");
//interrupted = true;
try { try {
logger.log(Level.INFO, "interrupt() add image process"); logger.log(Level.INFO, "interrupt() add image process");
addImageProcess.stop(); //it might take time to truly stop processing and writing to db addImageProcess.stop(); //it might take time to truly stop processing and writing to db
@ -487,10 +506,11 @@ public class ImageDSProcessor implements DataSourceProcessor {
} }
} }
//runs in EWT /*
* Revert - if image has already been added but not committed yet
*/
void revert() { void revert() {
logger.log(Level.INFO, "RAMAN: revert()...");
if (!reverted) { if (!reverted) {
try { try {

View File

@ -9,8 +9,7 @@ import java.util.List;
import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Content;
/** /**
* * Abstract class for a callback
* @author raman
*/ */
public abstract class DSPCallback { public abstract class DSPCallback {
@ -21,6 +20,9 @@ public abstract class DSPCallback {
NONCRITICAL_ERRORS, NONCRITICAL_ERRORS,
}; };
/*
* Invoke the caller supplied callback function on the EDT thread
*/
public void done(DSP_Result result, List<String> errList, List<Content> newContents) public void done(DSP_Result result, List<String> errList, List<Content> newContents)
{ {
@ -38,5 +40,8 @@ public abstract class DSPCallback {
}); });
} }
/*
* calling code overrides to provide its own calllback
*/
public abstract void doneEDT(DSP_Result result, List<String> errList, List<Content> newContents); public abstract void doneEDT(DSP_Result result, List<String> errList, List<Content> newContents);
}; };