Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceSummaryReport.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 */
19package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
20
21import java.io.IOException;
22import java.util.ArrayList;
23import java.util.List;
24import java.util.logging.Level;
25import java.util.stream.Collectors;
26import javax.swing.JPanel;
27import org.openide.util.NbBundle;
28import org.openide.util.lookup.ServiceProvider;
29import org.sleuthkit.autopsy.casemodule.Case;
30import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
31import org.sleuthkit.autopsy.coreutils.Logger;
32import org.sleuthkit.autopsy.report.GeneralReportModule;
33import org.sleuthkit.autopsy.report.GeneralReportSettings;
34import org.sleuthkit.autopsy.report.ReportProgressPanel;
35import org.sleuthkit.datamodel.Content;
36import org.sleuthkit.datamodel.DataSource;
37import org.sleuthkit.datamodel.TskCoreException;
38
43@ServiceProvider(service = GeneralReportModule.class)
45
46 private static final Logger logger = Logger.getLogger(DataSourceSummaryReport.class.getName());
48
49 // Get the default instance of this report
50 public static synchronized DataSourceSummaryReport getDefault() {
51 if (instance == null) {
53 }
54 return instance;
55 }
56
58 }
59
60
61 @Override
62 public String getName() {
63 String name = NbBundle.getMessage(this.getClass(), "DataSourceSummaryReport.getName.text");
64 return name;
65 }
66
67 @Override
68 public String getRelativeFilePath() {
69 return "";
70 }
71
72 @Override
73 public String getDescription() {
74 String desc = NbBundle.getMessage(this.getClass(), "DataSourceSummaryReport.getDesc.text");
75 return desc;
76 }
77
78 @Override
79 public JPanel getConfigurationPanel() {
80 return null;
81 }
82
83 @Override
84 public boolean supportsDataSourceSelection() {
85 return true;
86 }
87
88 @NbBundle.Messages({
89 "DataSourceSummaryReport.error.noOpenCase=No currently open case.",
90 "DataSourceSummaryReport.error.noDataSources=No data sources selected for report.",
91 "DataSourceSummaryReport.failedToCompleteReport=Failed to complete report.",
92 "DataSourceSummaryReport.excelFileWriteError=Could not write the xlsx file.",})
93 @Override
94 public void generateReport(GeneralReportSettings settings, ReportProgressPanel progressPanel) {
95 progressPanel.start();
96 Case currentCase;
97 try {
98 currentCase = Case.getCurrentCaseThrows();
99 } catch (NoCurrentCaseException ex) {
100 progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR, Bundle.DataSourceSummaryReport_error_noOpenCase());
101 logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
102 return;
103 }
104
105 String errorMessage = "";
107 List<Content> selectedDataSources = new ArrayList<>();
108 if(settings.getSelectedDataSources() == null) {
109 // Process all data sources if the list is null.
110 try {
111 selectedDataSources = currentCase.getDataSources();
112 List<Long> dsIDs = selectedDataSources
113 .stream()
114 .map(Content::getId)
115 .collect(Collectors.toList());
116 settings.setSelectedDataSources(dsIDs);
117 } catch (TskCoreException ex) {
119 errorMessage = Bundle.DataSourceSummaryReport_failedToCompleteReport();
120 logger.log(Level.SEVERE, "Could not get the datasources from the case", ex);
121 progressPanel.complete(result, errorMessage);
122 return;
123 }
124 } else {
125 for (Long dsID : settings.getSelectedDataSources()) {
126 try {
127 selectedDataSources.add(currentCase.getSleuthkitCase().getContentById(dsID));
128 } catch (TskCoreException ex) {
130 errorMessage = Bundle.DataSourceSummaryReport_failedToCompleteReport();
131 logger.log(Level.SEVERE, "Could not get the datasources from the case", ex);
132 progressPanel.complete(result, errorMessage);
133 return;
134 }
135 }
136 }
137
138 if (selectedDataSources.isEmpty()) {
140 progressPanel.complete(result, Bundle.DataSourceSummaryReport_error_noDataSources());
141 logger.log(Level.SEVERE, "No data sources selected for report."); //NON-NLS
142 return;
143 }
144
145 // looop over all selected data sources
146 for (Content dataSource : selectedDataSources){
147 if (dataSource instanceof DataSource) {
148 try {
149 new ExcelExportAction().exportToXLSX(progressPanel, (DataSource) dataSource, settings.getReportDirectoryPath());
150 } catch (IOException | ExcelExport.ExcelExportException ex) {
151 errorMessage = Bundle.DataSourceSummaryReport_excelFileWriteError();
152 logger.log(Level.SEVERE, errorMessage, ex); //NON-NLS
153 progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR, errorMessage);
154 return;
155 }
156 }
157 }
158
159 progressPanel.complete(result, errorMessage);
160 }
161
162}
synchronized static Logger getLogger(String name)
Definition Logger.java:124
void setSelectedDataSources(List< Long > selectedDataSources)
void generateReport(GeneralReportSettings settings, ReportProgressPanel progressPanel)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.