19 package org.sleuthkit.autopsy.datasourcesummary.ui;
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;
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"
57 class IngestJobExcelExport {
79 IngestJobEntry(Date startTime, Date endTime, String status, String ingestModule, String ingestModuleVersion) {
80 this.startTime = startTime;
81 this.endTime = endTime;
83 this.ingestModule = ingestModule;
84 this.ingestModuleVersion = ingestModuleVersion;
111 String getIngestModule() {
118 String getIngestModuleVersion() {
119 return ingestModuleVersion;
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());
128 private static final List<ColumnModel<IngestJobEntry, DefaultCellModel<?>>> COLUMNS = Arrays.asList(
130 Bundle.IngestJobExcelExport_startTimeColumn(),
131 (entry) -> getDateCell(entry.getStartTime())),
133 Bundle.IngestJobExcelExport_endTimeColumn(),
134 (entry) -> getDateCell(entry.getEndTime())),
136 Bundle.IngestJobExcelExport_ingestStatusTimeColumn(),
137 (entry) ->
new DefaultCellModel<>(entry.getStatus())),
139 Bundle.IngestJobExcelExport_moduleNameTimeColumn(),
140 (entry) ->
new DefaultCellModel<>(entry.getIngestModule())),
142 Bundle.IngestJobExcelExport_versionColumn(),
143 (entry) ->
new DefaultCellModel<>(entry.getIngestModuleVersion()))
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);
163 private static List<IngestJobEntry> getEntries(IngestJobInfo job) {
164 List<IngestModuleInfo> infoList = job.getIngestModuleInfo();
165 if (infoList == null) {
166 return Collections.emptyList();
168 Date startTime = job.getStartDateTime();
169 Date endTime = job.getEndDateTime();
170 String status = job.getStatus().getDisplayName();
172 return infoList.stream()
173 .filter(info -> info != null)
174 .map(info ->
new IngestJobEntry(startTime, endTime, status, info.getDisplayName(), info.getVersion()))
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);
181 return a.getIngestModule().compareTo(b.getIngestModule());
184 .collect(Collectors.toList());
195 private static Stream<IngestJobEntry> showFirstRowOnly(List<IngestJobEntry> list) {
196 return IntStream.range(0, list.size())
198 IngestJobEntry entry = list.get(idx);
199 if (entry == null || idx == 0) {
202 return new IngestJobEntry(null, null, null, entry.getIngestModule(), entry.getIngestModuleVersion());
214 static List<ExcelSheetExport> getExports(DataSource dataSource) {
215 if (dataSource == null) {
216 return Collections.emptyList();
219 List<IngestJobInfo> info = null;
221 info = Case.getCurrentCaseThrows().getSleuthkitCase().getIngestJobs();
222 }
catch (NoCurrentCaseException | TskCoreException ex) {
223 logger.log(Level.WARNING,
"There was an error fetching ingest jobs", ex);
227 info = Collections.emptyList();
230 List<IngestJobEntry> toDisplay = info.stream()
231 .filter(job -> job != null && dataSource.getId() == job.getObjectId())
234 boolean aIsNull = a.getStartDateTime() == null;
235 boolean bIsNull = b.getStartDateTime() == null;
236 if (aIsNull || bIsNull) {
237 return Boolean.compare(aIsNull, bIsNull);
239 return a.getStartDateTime().compareTo(b.getStartDateTime());
242 .map((job) -> getEntries(job))
243 .filter(lst -> lst != null)
244 .flatMap((lst) -> showFirstRowOnly(lst))
245 .filter(item -> item != null)
246 .collect(Collectors.toList());
248 return Arrays.asList(
new ExcelTableExport<>(Bundle.IngestJobExcelExport_sheetName(), COLUMNS, toDisplay));
251 private IngestJobExcelExport() {
final String ingestModuleVersion
final String ingestModule