mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Refactored AddDataSourceCallback and DataSource out of AIM
This commit is contained in:
parent
49850bfd98
commit
3ac0792922
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.sleuthkit.autopsy.experimental.autoingest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import org.sleuthkit.autopsy.casemodule.Case;
|
||||
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
|
||||
import org.sleuthkit.datamodel.Content;
|
||||
|
||||
|
||||
/**
|
||||
* A "callback" that collects the results of running a data source processor on
|
||||
* a data source and unblocks the job processing thread when the data source
|
||||
* processor finishes running in its own thread.
|
||||
*/
|
||||
@Immutable
|
||||
class AddDataSourceCallback extends DataSourceProcessorCallback {
|
||||
|
||||
private final Case caseForJob;
|
||||
private final DataSource dataSourceInfo;
|
||||
private final UUID taskId;
|
||||
private final Object lock;
|
||||
|
||||
/**
|
||||
* Constructs a "callback" that collects the results of running a data
|
||||
* source processor on a data source and unblocks the job processing thread
|
||||
* when the data source processor finishes running in its own thread.
|
||||
*
|
||||
* @param caseForJob The case for the current job.
|
||||
* @param dataSourceInfo The data source
|
||||
* @param taskId The task id to associate with ingest job events.
|
||||
*/
|
||||
AddDataSourceCallback(Case caseForJob, DataSource dataSourceInfo, UUID taskId, Object lock) {
|
||||
this.caseForJob = caseForJob;
|
||||
this.dataSourceInfo = dataSourceInfo;
|
||||
this.taskId = taskId;
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the data source processor when it finishes running in its own
|
||||
* thread.
|
||||
*
|
||||
* @param result The result code for the processing of the data source.
|
||||
* @param errorMessages Any error messages generated during the processing
|
||||
* of the data source.
|
||||
* @param dataSourceContent The content produced by processing the data
|
||||
* source.
|
||||
*/
|
||||
@Override
|
||||
public void done(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errorMessages, List<Content> dataSourceContent) {
|
||||
if (!dataSourceContent.isEmpty()) {
|
||||
caseForJob.notifyDataSourceAdded(dataSourceContent.get(0), taskId);
|
||||
} else {
|
||||
caseForJob.notifyFailedAddingDataSource(taskId);
|
||||
}
|
||||
dataSourceInfo.setDataSourceProcessorOutput(result, errorMessages, dataSourceContent);
|
||||
dataSourceContent.addAll(dataSourceContent);
|
||||
synchronized (lock) {
|
||||
lock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the data source processor when it finishes running in its own
|
||||
* thread, if that thread is the AWT (Abstract Window Toolkit) event
|
||||
* dispatch thread (EDT).
|
||||
*
|
||||
* @param result The result code for the processing of the data source.
|
||||
* @param errorMessages Any error messages generated during the processing
|
||||
* of the data source.
|
||||
* @param dataSourceContent The content produced by processing the data
|
||||
* source.
|
||||
*/
|
||||
@Override
|
||||
public void doneEDT(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errorMessages, List<Content> dataSources) {
|
||||
done(result, errorMessages, dataSources);
|
||||
}
|
||||
|
||||
}
|
@ -93,7 +93,6 @@ import org.sleuthkit.autopsy.experimental.configuration.SharedConfiguration;
|
||||
import org.sleuthkit.autopsy.experimental.configuration.SharedConfiguration.SharedConfigurationException;
|
||||
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
|
||||
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException;
|
||||
import org.sleuthkit.autopsy.datasourceprocessors.IdentifyDataSourceProcessors;
|
||||
import org.sleuthkit.autopsy.ingest.IngestJob;
|
||||
import org.sleuthkit.autopsy.ingest.IngestJob.CancellationReason;
|
||||
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
|
||||
@ -2277,7 +2276,7 @@ public final class AutoIngestManager extends Observable implements PropertyChang
|
||||
String deviceId = manifest.getDeviceId();
|
||||
return new DataSource(deviceId, dataSourcePath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Passes the data source for the current job through a data source
|
||||
* processor that adds it to the case database.
|
||||
@ -2300,7 +2299,7 @@ public final class AutoIngestManager extends Observable implements PropertyChang
|
||||
SYS_LOGGER.log(Level.INFO, "Adding data source for {0} ", manifestPath);
|
||||
currentJob.setProcessingStage(AutoIngestJob.Stage.ADDING_DATA_SOURCE, Date.from(Instant.now()));
|
||||
UUID taskId = UUID.randomUUID();
|
||||
DataSourceProcessorCallback callBack = new AddDataSourceCallback(caseForJob, dataSource, taskId);
|
||||
DataSourceProcessorCallback callBack = new AddDataSourceCallback(caseForJob, dataSource, taskId, ingestLock);
|
||||
DataSourceProcessorProgressMonitor progressMonitor = new DoNothingDSPProgressMonitor();
|
||||
Path caseDirectoryPath = currentJob.getCaseDirectoryPath();
|
||||
AutoIngestJobLogger jobLogger = new AutoIngestJobLogger(manifestPath, manifest.getDataSourceFileName(), caseDirectoryPath);
|
||||
@ -2571,79 +2570,6 @@ public final class AutoIngestManager extends Observable implements PropertyChang
|
||||
jobLogger.logFileExportError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A "callback" that collects the results of running a data source
|
||||
* processor on a data source and unblocks the job processing thread
|
||||
* when the data source processor finishes running in its own thread.
|
||||
*/
|
||||
@Immutable
|
||||
class AddDataSourceCallback extends DataSourceProcessorCallback {
|
||||
|
||||
private final Case caseForJob;
|
||||
private final DataSource dataSourceInfo;
|
||||
private final UUID taskId;
|
||||
|
||||
/**
|
||||
* Constructs a "callback" that collects the results of running a
|
||||
* data source processor on a data source and unblocks the job
|
||||
* processing thread when the data source processor finishes running
|
||||
* in its own thread.
|
||||
*
|
||||
* @param caseForJob The case for the current job.
|
||||
* @param dataSourceInfo The data source
|
||||
* @param taskId The task id to associate with ingest job
|
||||
* events.
|
||||
*/
|
||||
AddDataSourceCallback(Case caseForJob, DataSource dataSourceInfo, UUID taskId) {
|
||||
this.caseForJob = caseForJob;
|
||||
this.dataSourceInfo = dataSourceInfo;
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the data source processor when it finishes running in
|
||||
* its own thread.
|
||||
*
|
||||
* @param result The result code for the processing of
|
||||
* the data source.
|
||||
* @param errorMessages Any error messages generated during the
|
||||
* processing of the data source.
|
||||
* @param dataSourceContent The content produced by processing the
|
||||
* data source.
|
||||
*/
|
||||
@Override
|
||||
public void done(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errorMessages, List<Content> dataSourceContent) {
|
||||
if (!dataSourceContent.isEmpty()) {
|
||||
caseForJob.notifyDataSourceAdded(dataSourceContent.get(0), taskId);
|
||||
} else {
|
||||
caseForJob.notifyFailedAddingDataSource(taskId);
|
||||
}
|
||||
dataSourceInfo.setDataSourceProcessorOutput(result, errorMessages, dataSourceContent);
|
||||
dataSourceContent.addAll(dataSourceContent);
|
||||
synchronized (ingestLock) {
|
||||
ingestLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the data source processor when it finishes running in
|
||||
* its own thread, if that thread is the AWT (Abstract Window
|
||||
* Toolkit) event dispatch thread (EDT).
|
||||
*
|
||||
* @param result The result code for the processing of
|
||||
* the data source.
|
||||
* @param errorMessages Any error messages generated during the
|
||||
* processing of the data source.
|
||||
* @param dataSourceContent The content produced by processing the
|
||||
* data source.
|
||||
*/
|
||||
@Override
|
||||
public void doneEDT(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errorMessages, List<Content> dataSources) {
|
||||
done(result, errorMessages, dataSources);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A data source processor progress monitor does nothing. There is
|
||||
@ -2984,48 +2910,6 @@ public final class AutoIngestManager extends Observable implements PropertyChang
|
||||
PARTIALLY_DELETED,
|
||||
FULLY_DELETED
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
private static final class DataSource {
|
||||
|
||||
private final String deviceId;
|
||||
private final Path path;
|
||||
private DataSourceProcessorResult resultCode;
|
||||
private List<String> errorMessages;
|
||||
private List<Content> content;
|
||||
|
||||
DataSource(String deviceId, Path path) {
|
||||
this.deviceId = deviceId;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
Path getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
synchronized void setDataSourceProcessorOutput(DataSourceProcessorResult result, List<String> errorMessages, List<Content> content) {
|
||||
this.resultCode = result;
|
||||
this.errorMessages = new ArrayList<>(errorMessages);
|
||||
this.content = new ArrayList<>(content);
|
||||
}
|
||||
|
||||
synchronized DataSourceProcessorResult getResultDataSourceProcessorResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
synchronized List<String> getDataSourceProcessorErrorMessages() {
|
||||
return new ArrayList<>(errorMessages);
|
||||
}
|
||||
|
||||
synchronized List<Content> getContent() {
|
||||
return new ArrayList<>(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final class AutoIngestManagerException extends Exception {
|
||||
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.sleuthkit.autopsy.experimental.autoingest;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback.DataSourceProcessorResult;
|
||||
import org.sleuthkit.datamodel.Content;
|
||||
|
||||
@ThreadSafe
|
||||
class DataSource {
|
||||
|
||||
private final String deviceId;
|
||||
private final Path path;
|
||||
private DataSourceProcessorResult resultCode;
|
||||
private List<String> errorMessages;
|
||||
private List<Content> content;
|
||||
|
||||
DataSource(String deviceId, Path path) {
|
||||
this.deviceId = deviceId;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
Path getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
synchronized void setDataSourceProcessorOutput(DataSourceProcessorResult result, List<String> errorMessages, List<Content> content) {
|
||||
this.resultCode = result;
|
||||
this.errorMessages = new ArrayList<>(errorMessages);
|
||||
this.content = new ArrayList<>(content);
|
||||
}
|
||||
|
||||
synchronized DataSourceProcessorResult getResultDataSourceProcessorResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
synchronized List<String> getDataSourceProcessorErrorMessages() {
|
||||
return new ArrayList<>(errorMessages);
|
||||
}
|
||||
|
||||
synchronized List<Content> getContent() {
|
||||
return new ArrayList<>(content);
|
||||
}
|
||||
|
||||
}
|
@ -3,19 +3,20 @@
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.sleuthkit.autopsy.datasourceprocessors;
|
||||
package org.sleuthkit.autopsy.experimental.autoingest;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.openide.util.Lookup;
|
||||
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
|
||||
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException;
|
||||
|
||||
/**
|
||||
* A utility class to find Data Source Processors
|
||||
*/
|
||||
public class IdentifyDataSourceProcessors {
|
||||
class IdentifyDataSourceProcessors {
|
||||
|
||||
/**
|
||||
* A utility method to find all Data Source Processors (DSP) that are able
|
||||
@ -28,7 +29,7 @@ public class IdentifyDataSourceProcessors {
|
||||
* @throws
|
||||
* org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException
|
||||
*/
|
||||
public static Map<AutoIngestDataSourceProcessor, Integer> getDataSourceProcessor(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
|
||||
static Map<AutoIngestDataSourceProcessor, Integer> getDataSourceProcessor(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
|
||||
|
||||
// lookup all AutomatedIngestDataSourceProcessors
|
||||
Collection<? extends AutoIngestDataSourceProcessor> processorCandidates = Lookup.getDefault().lookupAll(AutoIngestDataSourceProcessor.class);
|
Loading…
x
Reference in New Issue
Block a user