Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TestingConfig.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.config;
20 
21 import com.fasterxml.jackson.annotation.JsonCreator;
22 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.stream.Collectors;
31 import org.apache.commons.collections4.CollectionUtils;
32 import org.apache.commons.collections4.MapUtils;
33 
37 @JsonIgnoreProperties(ignoreUnknown = true)
38 public class TestingConfig {
39 
40  private final Map<String, ParameterizedResourceConfig> excludeAllExcept;
41  private final Set<String> includeAllExcept;
42 
50  @JsonCreator
51  public TestingConfig(
52  @JsonProperty("excludeAllExcept") List<ParameterizedResourceConfig> excludeAllExcept,
53  @JsonProperty("includeAllExcept") List<String> includeAllExcept) {
54 
55  // if exclude all except is null, treat as empty list.
56  List<ParameterizedResourceConfig> safeExcludeAllExcept = ((excludeAllExcept == null) ? Collections.emptyList() : excludeAllExcept);
57 
58  // create a map of canonical paths to their parameterized resource config merging configurations if doubled.
59  this.excludeAllExcept = safeExcludeAllExcept
60  .stream()
61  .collect(Collectors.toMap(
62  (res) -> res.getResource() == null ? "" : res.getResource().toUpperCase(),
63  (res) -> res,
64  (res1, res2) -> {
65  Map<String, Object> mergedArgs = new HashMap<>();
66  mergedArgs.putAll(res1.getParameters());
67  mergedArgs.putAll(res2.getParameters());
68  return new ParameterizedResourceConfig(res1.getResource(), mergedArgs);
69  })
70  );
71 
72  List<String> safeIncludeAllExcept = ((includeAllExcept == null) ? Collections.emptyList() : includeAllExcept);
73  this.includeAllExcept = safeIncludeAllExcept
74  .stream()
75  .map(String::toUpperCase)
76  .collect(Collectors.toSet());
77  }
78 
83  public Set<ParameterizedResourceConfig> getExcludeAllExcept() {
84  return excludeAllExcept == null ? Collections.emptySet() : new HashSet<>(excludeAllExcept.values());
85  }
86 
92  public Set<String> getIncludeAllExcept() {
93  return includeAllExcept == null ? Collections.emptySet() : Collections.unmodifiableSet(includeAllExcept);
94  }
95 
103  public Map<String, Object> getParameters(String itemType) {
104  ParameterizedResourceConfig resource = (itemType == null) ? null : excludeAllExcept.get(itemType.toUpperCase());
105  return resource == null ? Collections.emptyMap() : new HashMap<>(resource.getParameters());
106  }
107 
114  public boolean hasIncludedTest(String itemType) {
115  if (itemType == null) {
116  return false;
117  }
118 
119  // if there are items to exclude and this item is excluded
120  if (!CollectionUtils.isEmpty(includeAllExcept) && includeAllExcept.contains(itemType.toUpperCase())) {
121  return false;
122  }
123 
124  // otherwise, if there are items that should specifically be included, ensure that this item is in that list.
125  if (!MapUtils.isEmpty(excludeAllExcept)) {
126  return excludeAllExcept.containsKey(itemType.toUpperCase());
127  }
128 
129  return true;
130  }
131 }
Set< ParameterizedResourceConfig > getExcludeAllExcept()
final Map< String, ParameterizedResourceConfig > excludeAllExcept
TestingConfig(@JsonProperty("excludeAllExcept") List< ParameterizedResourceConfig > excludeAllExcept,@JsonProperty("includeAllExcept") List< String > includeAllExcept)

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