Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestUtils.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2018 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.testutils;
20
21import java.nio.file.Path;
22import java.util.List;
23import java.util.UUID;
24import org.apache.commons.collections.CollectionUtils;
25import org.sleuthkit.autopsy.casemodule.Case;
26import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
27import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
28import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
29import org.sleuthkit.autopsy.ingest.IngestJobSettings;
30import org.sleuthkit.autopsy.ingest.IngestModuleError;
31import org.sleuthkit.autopsy.ingest.IngestModuleFactory;
32import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings;
33import org.sleuthkit.autopsy.ingest.IngestModuleTemplate;
34import org.sleuthkit.datamodel.Content;
35
40public final class IngestUtils {
41
46 private IngestUtils() {
47 }
48
58 public static void addDataSource(AutoIngestDataSourceProcessor dataSourceProcessor, Path dataSourcePath) throws TestUtilsException {
59 try {
60 if (!dataSourcePath.toFile().exists()) {
61 throw new TestUtilsException("IngestUtils.addDataSource: Data source not found: " + dataSourcePath.toString());
62 }
63 UUID taskId = UUID.randomUUID();
68 String joinedErrors = String.join(System.lineSeparator(), callBack.getErrorMessages());
69 throw new TestUtilsException(String.format("IngestUtils.addDataSource: Error(s) occurred while running the data source processor: %s", joinedErrors));
70 }
71 for (Content c:callBack.getDataSourceContent()) {
73 }
75 throw new TestUtilsException("IngestUtils.addDataSource encountered an error on adding a datasource: " + ex.getMessage(), ex);
76 }
77 }
78
87 public static void runIngestJob(List<Content> datasources, IngestJobSettings ingestJobSettings) throws TestUtilsException {
88 try {
89 List<IngestModuleError> errs = IngestJobRunner.runIngestJob(datasources, ingestJobSettings);
90 StringBuilder joinedErrors = new StringBuilder("");
91 errs.forEach((err) -> {
92 joinedErrors.append(String.format("Error: %s: %s.", err.getModuleDisplayName(), err.toString())).append(System.lineSeparator());
93 });
94
95 if (CollectionUtils.isNotEmpty(errs)) {
96 throw new TestUtilsException("An error occurred while running an ingest job: " + joinedErrors);
97 }
98
99 } catch (InterruptedException ex) {
100 throw new TestUtilsException("An interrupted exception occurred.", ex);
101 }
102 }
103
115 IngestModuleTemplate template = new IngestModuleTemplate(factory, settings);
116 template.setEnabled(true);
117 return template;
118 }
119}
void notifyAddingDataSource(UUID eventId)
Definition Case.java:1770
void notifyDataSourceAdded(Content dataSource, UUID addingDataSourceEventId)
Definition Case.java:1801
static ProcessorCallback runDataSourceProcessor(AutoIngestDataSourceProcessor processor, Path dataSourcePath)
static List< IngestModuleError > runIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
static void addDataSource(AutoIngestDataSourceProcessor dataSourceProcessor, Path dataSourcePath)
static void runIngestJob(List< Content > datasources, IngestJobSettings ingestJobSettings)
static IngestModuleTemplate getIngestModuleTemplate(IngestModuleFactory factory)
default IngestModuleIngestJobSettings getDefaultIngestJobSettings()

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