Autopsy  4.19.0
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  */
19 package org.sleuthkit.autopsy.testutils;
20 
21 import java.nio.file.Path;
22 import java.util.List;
23 import java.util.UUID;
24 import org.apache.commons.collections.CollectionUtils;
34 import org.sleuthkit.datamodel.Content;
35 
40 public 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();
66  DataSourceProcessorCallback.DataSourceProcessorResult result = callBack.getResult();
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 }
static ProcessorCallback runDataSourceProcessor(AutoIngestDataSourceProcessor processor, Path dataSourcePath)
static List< IngestModuleError > runIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
static void addDataSource(AutoIngestDataSourceProcessor dataSourceProcessor, Path dataSourcePath)
static IngestModuleTemplate getIngestModuleTemplate(IngestModuleFactory factory)
void notifyDataSourceAdded(Content dataSource, UUID addingDataSourceEventId)
Definition: Case.java:1798
default IngestModuleIngestJobSettings getDefaultIngestJobSettings()
static void runIngestJob(List< Content > datasources, IngestJobSettings ingestJobSettings)
void notifyAddingDataSource(UUID eventId)
Definition: Case.java:1767

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.