Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestModuleCheckUtil.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.datasourcesummary.datamodel;
20 
21 import java.util.Map;
22 import java.util.stream.Collectors;
23 import org.apache.commons.lang3.StringUtils;
24 import org.openide.util.NbBundle.Messages;
26 import org.sleuthkit.datamodel.DataSource;
27 import org.sleuthkit.datamodel.IngestJobInfo;
28 import org.sleuthkit.datamodel.IngestModuleInfo;
29 import org.sleuthkit.datamodel.SleuthkitCase;
30 import org.sleuthkit.datamodel.TskCoreException;
31 
35 @Messages({
36  "IngestModuleCheckUtil_recentActivityModuleName=Recent Activity",
37 
38 })
39 public class IngestModuleCheckUtil {
40  public static final String RECENT_ACTIVITY_FACTORY = "org.sleuthkit.autopsy.recentactivity.RecentActivityExtracterModuleFactory";
41  public static final String RECENT_ACTIVITY_MODULE_NAME = Bundle.IngestModuleCheckUtil_recentActivityModuleName();
42 
43  // IngestModuleInfo separator for unique_name
44  private static final String UNIQUE_NAME_SEPARATOR = "-";
45 
47 
53 
54  }
55 
65 
66  this.caseProvider = provider;
67  }
68 
69 
75  private static String getFullyQualifiedFactory(IngestModuleInfo info) {
76  if (info == null) {
77  return null;
78  }
79 
80  String qualifiedName = info.getUniqueName();
81  if (StringUtils.isBlank(qualifiedName)) {
82  return null;
83  }
84 
85  return qualifiedName.split(UNIQUE_NAME_SEPARATOR)[0];
86  }
87 
88 
95  private static boolean hasIngestModule(IngestJobInfo info, String fullyQualifiedFactory) {
96  if (info == null || info.getIngestModuleInfo() == null || StringUtils.isBlank(fullyQualifiedFactory)) {
97  return false;
98  }
99 
100  return info.getIngestModuleInfo().stream()
101  .anyMatch((moduleInfo) -> {
102  String thisQualifiedFactory = getFullyQualifiedFactory(moduleInfo);
103  return fullyQualifiedFactory.equalsIgnoreCase(thisQualifiedFactory);
104  });
105  }
106 
115  public boolean isModuleIngested(DataSource dataSource, String fullyQualifiedFactory)
116  throws TskCoreException, SleuthkitCaseProviderException {
117  if (dataSource == null) {
118  return false;
119  }
120 
121  long dataSourceId = dataSource.getId();
122 
123  return caseProvider.get().getIngestJobs().stream()
124  .anyMatch((ingestJob) -> {
125  return ingestJob != null
126  && ingestJob.getObjectId() == dataSourceId
127  && hasIngestModule(ingestJob, fullyQualifiedFactory);
128  });
129 
130  }
131 
138  public static Map<String, String> getFactoryDisplayNames(SleuthkitCase skCase) throws TskCoreException {
139  return skCase.getIngestJobs().stream()
140  .flatMap(ingestJob -> ingestJob.getIngestModuleInfo().stream())
141  .collect(Collectors.toMap(
142  (moduleInfo) -> getFullyQualifiedFactory(moduleInfo),
143  (moduleInfo) -> moduleInfo.getDisplayName(),
144  (a,b) -> a));
145  }
146 }
static Map< String, String > getFactoryDisplayNames(SleuthkitCase skCase)
boolean isModuleIngested(DataSource dataSource, String fullyQualifiedFactory)
static boolean hasIngestModule(IngestJobInfo info, String fullyQualifiedFactory)

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.