19 package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
 
   21 import java.util.Arrays;
 
   22 import java.util.Collections;
 
   23 import java.util.List;
 
   24 import java.util.stream.Collectors;
 
   25 import java.util.stream.Stream;
 
   26 import org.apache.commons.lang.StringUtils;
 
   27 import org.openide.util.NbBundle.Messages;
 
   42 class ExportContainerInfo {
 
   44     private final ContainerSummary containerSummary;
 
   49     ExportContainerInfo() {
 
   50         containerSummary = 
new ContainerSummary();
 
   62     private static List<? extends ExcelItemExportable> getAcquisitionDetails(String acquisitionDetails) {
 
   63         if (StringUtils.isBlank(acquisitionDetails)) {
 
   64             return Collections.emptyList();
 
   66             return Stream.of(acquisitionDetails.split(
"\\r?\\n"))
 
   67                     .map((line) -> (StringUtils.isBlank(line)) ? null : 
new SingleCellExportable(line))
 
   68                     .filter(item -> item != null)
 
   69                     .collect(Collectors.toList());
 
   74         "ExportContainerInfo_setFieldsForNonImageDataSource_na=N/A",
 
   75         "ExportContainerInfo_tabName=Container",
 
   76         "ExportContainerInfo_export_displayName=Display Name:",
 
   77         "ExportContainerInfo_export_originalName=Name:",
 
   78         "ExportContainerInfo_export_deviceId=Device ID:",
 
   79         "ExportContainerInfo_export_timeZone=Time Zone:",
 
   80         "ExportContainerInfo_export_acquisitionDetails=Acquisition Details:",
 
   81         "ExportContainerInfo_export_imageType=Image Type:",
 
   82         "ExportContainerInfo_export_size=Size:",
 
   83         "ExportContainerInfo_export_sectorSize=Sector Size:",
 
   84         "ExportContainerInfo_export_md5=MD5:",
 
   85         "ExportContainerInfo_export_sha1=SHA1:",
 
   86         "ExportContainerInfo_export_sha256=SHA256:",
 
   87         "ExportContainerInfo_export_unallocatedSize=Unallocated Space:",
 
   88         "ExportContainerInfo_export_filePaths=File Paths:",})
 
   89     List<ExcelSheetExport> getExports(DataSource ds) {
 
   90         DataFetcher<DataSource, ContainerDetails> containerDataFetcher = (dataSource) -> containerSummary.getContainerDetails(dataSource);
 
   91         ContainerDetails containerDetails = ExcelExportAction.getFetchResult(containerDataFetcher, 
"Container sheets", ds);
 
   92         if (ds == null || containerDetails == null) {
 
   93             return Collections.emptyList();
 
   96         String NA = Bundle.ExportContainerInfo_setFieldsForNonImageDataSource_na();
 
   97         DefaultCellModel<?> NACell = 
new DefaultCellModel<>(NA);
 
   99         ImageDetails imageDetails = containerDetails.getImageDetails();
 
  100         boolean hasImage = imageDetails != null;
 
  102         DefaultCellModel<?> timeZone = hasImage ? 
new DefaultCellModel<>(imageDetails.getTimeZone()) : NACell;
 
  103         DefaultCellModel<?> imageType = hasImage ? 
new DefaultCellModel<>(imageDetails.getImageType()) : NACell;
 
  104         DefaultCellModel<?> size = hasImage ? SizeRepresentationUtil.getBytesCell(imageDetails.getSize()) : NACell;
 
  105         DefaultCellModel<?> sectorSize = hasImage ? SizeRepresentationUtil.getBytesCell(imageDetails.getSectorSize()) : NACell;
 
  106         DefaultCellModel<?> md5 = hasImage ? 
new DefaultCellModel<>(imageDetails.getMd5Hash()) : NACell;
 
  107         DefaultCellModel<?> sha1 = hasImage ? 
new DefaultCellModel<>(imageDetails.getSha1Hash()) : NACell;
 
  108         DefaultCellModel<?> sha256 = hasImage ? 
new DefaultCellModel<>(imageDetails.getSha256Hash()) : NACell;
 
  110         DefaultCellModel<?> unallocatedSize;
 
  112             Long unallocatedSizeVal = imageDetails.getUnallocatedSize();
 
  113             if (unallocatedSizeVal != null) {
 
  114                 unallocatedSize = SizeRepresentationUtil.getBytesCell(unallocatedSizeVal);
 
  116                 unallocatedSize = NACell;
 
  119             unallocatedSize = NACell;
 
  122         List<String> paths = containerDetails.getImageDetails() == null ? Collections.singletonList(NA) : containerDetails.getImageDetails().getPaths();
 
  123         List<SingleCellExportable> cellPaths = paths.stream()
 
  124                 .map(SingleCellExportable::new)
 
  125                 .collect(Collectors.toList());
 
  127         return Arrays.asList(
new ExcelSpecialFormatExport(Bundle.ExportContainerInfo_tabName(), Arrays.asList(
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_displayName(), 
new DefaultCellModel<>(containerDetails.getDisplayName())),
 
  128                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_originalName(), 
new DefaultCellModel<>(containerDetails.getOriginalName())),
 
  129                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_deviceId(), 
new DefaultCellModel<>(containerDetails.getDeviceId())),
 
  130                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_timeZone(), timeZone),
 
  131                 new TitledExportable(Bundle.ExportContainerInfo_export_acquisitionDetails(), getAcquisitionDetails(containerDetails.getAcquisitionDetails())),
 
  132                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_imageType(), imageType),
 
  133                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_size(), size),
 
  134                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sectorSize(), sectorSize),
 
  135                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_md5(), md5),
 
  136                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha1(), sha1),
 
  137                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha256(), sha256),
 
  138                 new KeyValueItemExportable(Bundle.ExportContainerInfo_export_unallocatedSize(), unallocatedSize),
 
  139                 new TitledExportable(Bundle.ExportContainerInfo_export_filePaths(), cellPaths)