19 package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
 
   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;
 
   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" 
   54 class ExportIngestHistory {
 
   76         IngestJobEntry(Date startTime, Date endTime, String status, String ingestModule, String ingestModuleVersion) {
 
   77             this.startTime = startTime;
 
   78             this.endTime = endTime;
 
   80             this.ingestModule = ingestModule;
 
   81             this.ingestModuleVersion = ingestModuleVersion;
 
  108         String getIngestModule() {
 
  115         String getIngestModuleVersion() {
 
  116             return ingestModuleVersion;
 
  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());
 
  125     private static final List<ColumnModel<IngestJobEntry, DefaultCellModel<?>>> COLUMNS = Arrays.asList(
 
  127                     Bundle.ExportIngestHistory_startTimeColumn(),
 
  128                     (entry) -> getDateCell(entry.getStartTime())),
 
  130                     Bundle.ExportIngestHistory_endTimeColumn(),
 
  131                     (entry) -> getDateCell(entry.getEndTime())),
 
  133                     Bundle.ExportIngestHistory_ingestStatusTimeColumn(),
 
  134                     (entry) -> 
new DefaultCellModel<>(entry.getStatus())),
 
  136                     Bundle.ExportIngestHistory_moduleNameTimeColumn(),
 
  137                     (entry) -> 
new DefaultCellModel<>(entry.getIngestModule())),
 
  139                     Bundle.ExportIngestHistory_versionColumn(),
 
  140                     (entry) -> 
new DefaultCellModel<>(entry.getIngestModuleVersion()))
 
  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);
 
  162     private static List<IngestJobEntry> getEntries(IngestJobInfo job) {
 
  163         List<IngestModuleInfo> infoList = job.getIngestModuleInfo();
 
  164         if (infoList == null) {
 
  165             return Collections.emptyList();
 
  167             Date startTime = job.getStartDateTime();
 
  168             Date endTime = job.getEndDateTime();
 
  169             String status = job.getStatus().getDisplayName();
 
  171             return infoList.stream()
 
  172                     .filter(info -> info != null)
 
  173                     .map(info -> 
new IngestJobEntry(startTime, endTime, status, info.getDisplayName(), info.getVersion()))
 
  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);
 
  180                             return a.getIngestModule().compareTo(b.getIngestModule());
 
  183                     .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());
 
  215     static List<ExcelSheetExport> getExports(DataSource dataSource) {
 
  216         if (dataSource == null) {
 
  217             return Collections.emptyList();
 
  220         List<IngestJobInfo> info = null;
 
  222             info = Case.getCurrentCaseThrows().getSleuthkitCase().getIngestJobs();
 
  223         } 
catch (NoCurrentCaseException | TskCoreException ex) {
 
  224             logger.log(Level.WARNING, 
"There was an error fetching ingest jobs", ex);
 
  228             info = Collections.emptyList();
 
  231         List<IngestJobEntry> toDisplay = info.stream()
 
  232                 .filter(job -> job != null && dataSource.getId() == job.getObjectId())
 
  235                     boolean aIsNull = a.getStartDateTime() == null;
 
  236                     boolean bIsNull = b.getStartDateTime() == null;
 
  237                     if (aIsNull || bIsNull) {
 
  238                         return Boolean.compare(aIsNull, bIsNull);
 
  240                         return a.getStartDateTime().compareTo(b.getStartDateTime());
 
  243                 .map((job) -> getEntries(job))
 
  244                 .filter(lst -> lst != null)
 
  245                 .flatMap((lst) -> showFirstRowOnly(lst))
 
  246                 .filter(item -> item != null)
 
  247                 .collect(Collectors.toList());
 
  249         return Arrays.asList(
new ExcelTableExport<>(Bundle.ExportIngestHistory_sheetName(), COLUMNS, toDisplay));
 
  252     private ExportIngestHistory() {
 
final String ingestModule
 
final String ingestModuleVersion