19 package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
22 import java.io.IOException;
23 import java.nio.file.Paths;
24 import java.text.DateFormat;
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.List;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
47 "ExcelExportAction_moduleName=Data Source Summary",})
48 class ExcelExportAction {
50 private static final Logger logger = Logger.getLogger(ExcelExportAction.class.getName());
69 "ExcelExportAction_getXLSXPath_directory=DataSourceSummary",})
70 File getXLSXPath(String dataSourceName, String baseReportDir) {
73 DateFormat dateFormat =
new SimpleDateFormat(
"MM-dd-yyyy-HH-mm-ss");
74 String fileName = String.format(
"%s-%s.xlsx", dataSourceName == null ?
"" : FileUtil.escapeFileName(dataSourceName), dateFormat.format(
new Date()));
75 File reportsDirFile = Paths.get(baseReportDir, Bundle.ExcelExportAction_getXLSXPath_directory()).toFile();
76 if (!reportsDirFile.exists()) {
77 reportsDirFile.mkdirs();
80 return Paths.get(reportsDirFile.getAbsolutePath(), fileName).toFile();
95 "ExcelExportAction_exportToXLSX_beginExport=Beginning Export...",
96 "ExcelExportAction_exportToXLSX_gatheringRecentActivityData=Fetching Recent Activity Data",
97 "ExcelExportAction_exportToXLSX_gatheringContainerData=Fetching Container & Image Data",
98 "ExcelExportAction_exportToXLSX_gatheringTimelineData=Fetching Timeline Data",
99 "ExcelExportAction_exportToXLSX_gatheringFileData=Fetching File and MIME Type Data",
100 "ExcelExportAction_exportToXLSX_gatheringAnalysisData=Fetching Analysis Data",
101 "ExcelExportAction_exportToXLSX_gatheringPastData=Fetching Historical Data",
102 "ExcelExportAction_exportToXLSX_gatheringUserData=Fetching User Activity Data",
103 "ExcelExportAction_exportToXLSX_gatheringGeoData=Fetching Geolocation Data",
104 "ExcelExportAction_exportToXLSX_gatheringIngestData=Fetching Ingest History Data",
105 "ExcelExportAction_exportToXLSX_writingToFile=Writing to File...",})
107 void exportToXLSX(ReportProgressPanel progressPanel, DataSource dataSource, String baseReportDir)
108 throws IOException, ExcelExport.ExcelExportException {
110 File reportFile = getXLSXPath(dataSource.getName(), baseReportDir);
111 int totalWeight = 11;
113 progressPanel.setIndeterminate(
false);
114 progressPanel.setLabels(dataSource.getName(), reportFile.getPath());
115 progressPanel.setMaximumProgress(totalWeight);
116 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_beginExport());
117 List<ExcelExport.ExcelSheetExport> sheetExports =
new ArrayList<>();
120 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringFileData());
121 progressPanel.setProgress(step);
122 List<ExcelExport.ExcelSheetExport> exports =
new ExportTypes().getExports(dataSource);
123 if (exports != null) {
124 sheetExports.addAll(exports);
128 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringUserData());
129 progressPanel.setProgress(++step);
130 exports =
new ExportUserActivity().getExports(dataSource);
131 if (exports != null) {
132 sheetExports.addAll(exports);
136 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringRecentActivityData());
137 progressPanel.setProgress(++step);
138 exports =
new ExportRecentFiles().getExports(dataSource);
139 if (exports != null) {
140 sheetExports.addAll(exports);
144 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringAnalysisData());
145 progressPanel.setProgress(++step);
146 exports =
new ExportAnalysisResults().getExports(dataSource);
147 if (exports != null) {
148 sheetExports.addAll(exports);
152 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringPastData());
153 progressPanel.setProgress(++step);
154 exports =
new ExportPastCases().getExports(dataSource);
155 if (exports != null) {
156 sheetExports.addAll(exports);
160 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringGeoData());
161 progressPanel.setProgress(++step);
162 exports =
new ExportGeolocation().getExports(dataSource);
163 if (exports != null) {
164 sheetExports.addAll(exports);
168 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringTimelineData());
169 progressPanel.setProgress(++step);
170 exports =
new ExportTimeline().getExports(dataSource);
171 if (exports != null) {
172 sheetExports.addAll(exports);
176 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringIngestData());
177 progressPanel.setProgress(++step);
178 exports = ExportIngestHistory.getExports(dataSource);
179 if (exports != null) {
180 sheetExports.addAll(exports);
184 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_gatheringContainerData());
185 progressPanel.setProgress(++step);
186 exports =
new ExportContainerInfo().getExports(dataSource);
187 if (exports != null) {
188 sheetExports.addAll(exports);
191 progressPanel.updateStatusLabel(Bundle.ExcelExportAction_exportToXLSX_writingToFile());
192 progressPanel.setProgress(++step);
193 ExcelExport.writeExcel(sheetExports, reportFile);
197 Case curCase = Case.getCurrentCaseThrows();
198 curCase.addReport(reportFile.getParent(),
199 Bundle.ExcelExportAction_moduleName(),
200 reportFile.getName(),
202 }
catch (NoCurrentCaseException | TskCoreException ex) {
203 logger.log(Level.WARNING,
"There was an error attaching report to case.", ex);
221 ExcelSheetExport convert(T data)
throws ExcelExportException;
234 protected static <T> T getFetchResult(
236 String sheetName, DataSource ds) {
240 }
catch (Exception ex) {
241 logger.log(Level.WARNING,
242 String.format(
"There was an error while acquiring data for exporting worksheet(s): '%s' for dataSource: %s",
243 sheetName == null ?
"<null>" : sheetName,
244 ds == null || ds.getName() == null ?
"<null>" : ds.getName()), ex);
260 protected static <T> ExcelSheetExport convertToExcel(ExcelExportFunction<T> excelConverter, T data, String sheetName) {
266 return excelConverter.convert(data);
267 }
catch (ExcelExportException ex) {
268 logger.log(Level.WARNING,
269 String.format(
"There was an error while preparing export of worksheet(s): '%s'",
270 sheetName == null ?
"<null>" : sheetName), ex);
287 protected static <T> ExcelSheetExport getExport(
288 DataFetcher<DataSource, T> dataFetcher, ExcelExportFunction<T> excelConverter,
289 String sheetName, DataSource ds) {
291 T data = getFetchResult(dataFetcher, sheetName, ds);
292 return convertToExcel(excelConverter, data, sheetName);
304 protected static <T, C extends CellModel> ExcelSheetExport getTableExport(List<ColumnModel<T, C>> columnsModel,
305 String sheetName, List<T> data) {
307 return convertToExcel((dataList) ->
new ExcelTableExport<>(sheetName, columnsModel, dataList),
323 protected static <T, C extends CellModel> ExcelSheetExport getTableExport(
324 DataFetcher<DataSource, List<T>> dataFetcher, List<ColumnModel<T, C>> columnsModel,
325 String sheetName, DataSource ds) {
327 return getExport(dataFetcher,
328 (dataList) ->
new ExcelTableExport<>(sheetName, columnsModel, dataList),