Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestJobExcelExport.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.datasourcesummary.ui;
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;
41 import org.sleuthkit.datamodel.DataSource;
42 import org.sleuthkit.datamodel.IngestJobInfo;
43 import org.sleuthkit.datamodel.IngestModuleInfo;
44 import org.sleuthkit.datamodel.TskCoreException;
45 
49 @Messages({
50  "IngestJobExcelExport_startTimeColumn=Start Time",
51  "IngestJobExcelExport_endTimeColumn=End Time",
52  "IngestJobExcelExport_ingestStatusTimeColumn=Ingest Status",
53  "IngestJobExcelExport_moduleNameTimeColumn=Module Name",
54  "IngestJobExcelExport_versionColumn=Module Version",
55  "IngestJobExcelExport_sheetName=Ingest History"
56 })
57 class IngestJobExcelExport {
58 
62  private static class IngestJobEntry {
63 
64  private final Date startTime;
65  private final Date endTime;
66  private final String status;
67  private final String ingestModule;
68  private final String ingestModuleVersion;
69 
79  IngestJobEntry(Date startTime, Date endTime, String status, String ingestModule, String ingestModuleVersion) {
80  this.startTime = startTime;
81  this.endTime = endTime;
82  this.status = status;
83  this.ingestModule = ingestModule;
84  this.ingestModuleVersion = ingestModuleVersion;
85  }
86 
90  Date getStartTime() {
91  return startTime;
92  }
93 
97  Date getEndTime() {
98  return endTime;
99  }
100 
104  String getStatus() {
105  return status;
106  }
107 
111  String getIngestModule() {
112  return ingestModule;
113  }
114 
118  String getIngestModuleVersion() {
119  return ingestModuleVersion;
120  }
121  }
122 
123  private static final Logger logger = Logger.getLogger(IngestJobExcelExport.class.getName());
124  private static final String DATETIME_FORMAT_STR = "yyyy/MM/dd HH:mm:ss";
125  private static final DateFormat DATETIME_FORMAT = new SimpleDateFormat(DATETIME_FORMAT_STR, Locale.getDefault());
126 
127  // columns in the excel export table to be created.
128  private static final List<ColumnModel<IngestJobEntry, DefaultCellModel<?>>> COLUMNS = Arrays.asList(
129  new ColumnModel<>(
130  Bundle.IngestJobExcelExport_startTimeColumn(),
131  (entry) -> getDateCell(entry.getStartTime())),
132  new ColumnModel<>(
133  Bundle.IngestJobExcelExport_endTimeColumn(),
134  (entry) -> getDateCell(entry.getEndTime())),
135  new ColumnModel<>(
136  Bundle.IngestJobExcelExport_ingestStatusTimeColumn(),
137  (entry) -> new DefaultCellModel<>(entry.getStatus())),
138  new ColumnModel<>(
139  Bundle.IngestJobExcelExport_moduleNameTimeColumn(),
140  (entry) -> new DefaultCellModel<>(entry.getIngestModule())),
141  new ColumnModel<>(
142  Bundle.IngestJobExcelExport_versionColumn(),
143  (entry) -> new DefaultCellModel<>(entry.getIngestModuleVersion()))
144  );
145 
152  private static DefaultCellModel<?> getDateCell(Date date) {
153  Function<Date, String> dateParser = (dt) -> dt == null ? "" : DATETIME_FORMAT.format(dt);
154  return new DefaultCellModel<>(date, dateParser, DATETIME_FORMAT_STR);
155  }
156 
163  private static List<IngestJobEntry> getEntries(IngestJobInfo job) {
164  List<IngestModuleInfo> infoList = job.getIngestModuleInfo();
165  if (infoList == null) {
166  return Collections.emptyList();
167  } else {
168  Date startTime = job.getStartDateTime();
169  Date endTime = job.getEndDateTime();
170  String status = job.getStatus().getDisplayName();
171 
172  return infoList.stream()
173  .filter(info -> info != null)
174  .map(info -> new IngestJobEntry(startTime, endTime, status, info.getDisplayName(), info.getVersion()))
175  .sorted((a, b) -> {
176  boolean aIsNull = a == null || a.getIngestModule() == null;
177  boolean bIsNull = b == null || b.getIngestModule() == null;
178  if (aIsNull || bIsNull) {
179  return Boolean.compare(aIsNull, bIsNull);
180  } else {
181  return a.getIngestModule().compareTo(b.getIngestModule());
182  }
183  })
184  .collect(Collectors.toList());
185  }
186  }
187 
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 
214  static List<ExcelSheetExport> getExports(DataSource dataSource) {
215  if (dataSource == null) {
216  return Collections.emptyList();
217  }
218 
219  List<IngestJobInfo> info = null;
220  try {
221  info = Case.getCurrentCaseThrows().getSleuthkitCase().getIngestJobs();
222  } catch (NoCurrentCaseException | TskCoreException ex) {
223  logger.log(Level.WARNING, "There was an error fetching ingest jobs", ex);
224  }
225 
226  if (info == null) {
227  info = Collections.emptyList();
228  }
229 
230  List<IngestJobEntry> toDisplay = info.stream()
231  .filter(job -> job != null && dataSource.getId() == job.getObjectId())
232  .sorted((a, b) -> {
233  // sort ingest jobs by time.
234  boolean aIsNull = a.getStartDateTime() == null;
235  boolean bIsNull = b.getStartDateTime() == null;
236  if (aIsNull || bIsNull) {
237  return Boolean.compare(aIsNull, bIsNull);
238  } else {
239  return a.getStartDateTime().compareTo(b.getStartDateTime());
240  }
241  })
242  .map((job) -> getEntries(job))
243  .filter(lst -> lst != null)
244  .flatMap((lst) -> showFirstRowOnly(lst))
245  .filter(item -> item != null)
246  .collect(Collectors.toList());
247 
248  return Arrays.asList(new ExcelTableExport<>(Bundle.IngestJobExcelExport_sheetName(), COLUMNS, toDisplay));
249  }
250 
251  private IngestJobExcelExport() {
252  }
253 }
final String ingestModuleVersion
final String status
final Date endTime
final Date startTime
final String ingestModule

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.