Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExportIngestHistory.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.report.modules.datasourcesummaryexport;
20 
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.function.Function;
29 import java.util.logging.Level;
30 import java.util.stream.Collectors;
31 import java.util.stream.IntStream;
32 import java.util.stream.Stream;
33 import org.openide.util.NbBundle.Messages;
38 import org.sleuthkit.datamodel.DataSource;
39 import org.sleuthkit.datamodel.IngestJobInfo;
40 import org.sleuthkit.datamodel.IngestModuleInfo;
41 import org.sleuthkit.datamodel.TskCoreException;
42 
46 @Messages({
47  "ExportIngestHistory_startTimeColumn=Start Time",
48  "ExportIngestHistory_endTimeColumn=End Time",
49  "ExportIngestHistory_ingestStatusTimeColumn=Ingest Status",
50  "ExportIngestHistory_moduleNameTimeColumn=Module Name",
51  "ExportIngestHistory_versionColumn=Module Version",
52  "ExportIngestHistory_sheetName=Ingest History"
53 })
54 class ExportIngestHistory {
55 
59  private static class IngestJobEntry {
60 
61  private final Date startTime;
62  private final Date endTime;
63  private final String status;
64  private final String ingestModule;
65  private final String ingestModuleVersion;
66 
76  IngestJobEntry(Date startTime, Date endTime, String status, String ingestModule, String ingestModuleVersion) {
77  this.startTime = startTime;
78  this.endTime = endTime;
79  this.status = status;
80  this.ingestModule = ingestModule;
81  this.ingestModuleVersion = ingestModuleVersion;
82  }
83 
87  Date getStartTime() {
88  return startTime;
89  }
90 
94  Date getEndTime() {
95  return endTime;
96  }
97 
101  String getStatus() {
102  return status;
103  }
104 
108  String getIngestModule() {
109  return ingestModule;
110  }
111 
115  String getIngestModuleVersion() {
116  return ingestModuleVersion;
117  }
118  }
119 
120  private static final Logger logger = Logger.getLogger(ExportIngestHistory.class.getName());
121  private static final String DATETIME_FORMAT_STR = "yyyy/MM/dd HH:mm:ss";
122  private static final DateFormat DATETIME_FORMAT = new SimpleDateFormat(DATETIME_FORMAT_STR, Locale.getDefault());
123 
124  // columns in the excel export table to be created.
125  private static final List<ColumnModel<IngestJobEntry, DefaultCellModel<?>>> COLUMNS = Arrays.asList(
126  new ColumnModel<>(
127  Bundle.ExportIngestHistory_startTimeColumn(),
128  (entry) -> getDateCell(entry.getStartTime())),
129  new ColumnModel<>(
130  Bundle.ExportIngestHistory_endTimeColumn(),
131  (entry) -> getDateCell(entry.getEndTime())),
132  new ColumnModel<>(
133  Bundle.ExportIngestHistory_ingestStatusTimeColumn(),
134  (entry) -> new DefaultCellModel<>(entry.getStatus())),
135  new ColumnModel<>(
136  Bundle.ExportIngestHistory_moduleNameTimeColumn(),
137  (entry) -> new DefaultCellModel<>(entry.getIngestModule())),
138  new ColumnModel<>(
139  Bundle.ExportIngestHistory_versionColumn(),
140  (entry) -> new DefaultCellModel<>(entry.getIngestModuleVersion()))
141  );
142 
150  private static DefaultCellModel<?> getDateCell(Date date) {
151  Function<Date, String> dateParser = (dt) -> dt == null ? "" : DATETIME_FORMAT.format(dt);
152  return new DefaultCellModel<>(date, dateParser, DATETIME_FORMAT_STR);
153  }
154 
162  private static List<IngestJobEntry> getEntries(IngestJobInfo job) {
163  List<IngestModuleInfo> infoList = job.getIngestModuleInfo();
164  if (infoList == null) {
165  return Collections.emptyList();
166  } else {
167  Date startTime = job.getStartDateTime();
168  Date endTime = job.getEndDateTime();
169  String status = job.getStatus().getDisplayName();
170 
171  return infoList.stream()
172  .filter(info -> info != null)
173  .map(info -> new IngestJobEntry(startTime, endTime, status, info.getDisplayName(), info.getVersion()))
174  .sorted((a, b) -> {
175  boolean aIsNull = a == null || a.getIngestModule() == null;
176  boolean bIsNull = b == null || b.getIngestModule() == null;
177  if (aIsNull || bIsNull) {
178  return Boolean.compare(aIsNull, bIsNull);
179  } else {
180  return a.getIngestModule().compareTo(b.getIngestModule());
181  }
182  })
183  .collect(Collectors.toList());
184  }
185  }
186 
195  private static Stream<IngestJobEntry> showFirstRowOnly(List<IngestJobEntry> list) {
196  return IntStream.range(0, list.size())
197  .mapToObj(idx -> {
198  IngestJobEntry entry = list.get(idx);
199  if (entry == null || idx == 0) {
200  return entry;
201  } else {
202  return new IngestJobEntry(null, null, null, entry.getIngestModule(), entry.getIngestModuleVersion());
203  }
204  });
205 
206  }
207 
215  static List<ExcelSheetExport> getExports(DataSource dataSource) {
216  if (dataSource == null) {
217  return Collections.emptyList();
218  }
219 
220  List<IngestJobInfo> info = null;
221  try {
222  info = Case.getCurrentCaseThrows().getSleuthkitCase().getIngestJobs();
223  } catch (NoCurrentCaseException | TskCoreException ex) {
224  logger.log(Level.WARNING, "There was an error fetching ingest jobs", ex);
225  }
226 
227  if (info == null) {
228  info = Collections.emptyList();
229  }
230 
231  List<IngestJobEntry> toDisplay = info.stream()
232  .filter(job -> job != null && dataSource.getId() == job.getObjectId())
233  .sorted((a, b) -> {
234  // sort ingest jobs by time.
235  boolean aIsNull = a.getStartDateTime() == null;
236  boolean bIsNull = b.getStartDateTime() == null;
237  if (aIsNull || bIsNull) {
238  return Boolean.compare(aIsNull, bIsNull);
239  } else {
240  return a.getStartDateTime().compareTo(b.getStartDateTime());
241  }
242  })
243  .map((job) -> getEntries(job))
244  .filter(lst -> lst != null)
245  .flatMap((lst) -> showFirstRowOnly(lst))
246  .filter(item -> item != null)
247  .collect(Collectors.toList());
248 
249  return Arrays.asList(new ExcelTableExport<>(Bundle.ExportIngestHistory_sheetName(), COLUMNS, toDisplay));
250  }
251 
252  private ExportIngestHistory() {
253  }
254 }
final String status
final String ingestModule
final Date startTime
final String ingestModuleVersion
final Date endTime

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