Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestModuleSetupManager.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.integrationtesting;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.stream.Collectors;
25 import org.apache.commons.collections.CollectionUtils;
26 import org.apache.commons.lang.StringUtils;
30 
34 public class IngestModuleSetupManager implements ConfigurationModule<IngestModuleSetupManager.ConfigArgs> {
35 
39  public static class ConfigArgs {
40 
41  private final List<String> modules;
42 
48  public ConfigArgs(List<String> modules) {
49  this.modules = modules;
50  }
51 
55  public List<String> getModules() {
56  return modules;
57  }
58  }
59 
61 
62  @Override
64 
65  // get the profile from the IngestJobSettings
66  String context = curSettings.getExecutionContext();
67  if (StringUtils.isNotBlank(context) && context.indexOf('.') > 0) {
68  context = context.substring(0, context.indexOf('.'));
69  }
70 
71  // get current templates in job settings
72  Map<String, IngestModuleTemplate> curTemplates = curSettings.getEnabledIngestModuleTemplates().stream()
73  .collect(Collectors.toMap(t -> t.getModuleFactory().getClass().getCanonicalName(), t -> t, (t1, t2) -> t1));
74 
75  // get all the factories determined by canonical name
76  Map<String, IngestModuleFactory> allFactories = ingestModuleFactories.getFactories().stream()
77  .collect(Collectors.toMap(f -> f.getClass().getCanonicalName(), f -> f, (f1, f2) -> f1));
78 
79  // add current templates to the list of templates to return.
80  List<IngestModuleTemplate> newTemplates = new ArrayList<>(curTemplates.values());
81 
82  // if there are parameters, add any relevant ingest module factories
83  if (parameters != null && !CollectionUtils.isEmpty(parameters.getModules())) {
84  List<IngestModuleTemplate> templatesToAdd = parameters.getModules().stream()
85  // ensure only one of each type of factory is added
86  .distinct()
87  // if the factory to be added is already contained in curTemplates or allFactories does not contain item, null is returned
88  .map((className) -> curTemplates.containsKey(className) ? null : allFactories.get(className))
89  // filter out any null items
90  .filter((factory) -> factory != null)
91  // create a template for any remaining items
92  .map((factory) -> new IngestModuleTemplate(factory, factory.getDefaultIngestJobSettings()))
93  .collect(Collectors.toList());
94 
95  newTemplates.addAll(templatesToAdd);
96  }
97 
98  return new IngestJobSettings(
99  context,
101  newTemplates
102  );
103  }
104 }
IngestJobSettings configure(IngestJobSettings curSettings, IngestModuleSetupManager.ConfigArgs parameters)
List< IngestModuleTemplate > getEnabledIngestModuleTemplates()

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.