Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExportTimeline.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.awt.Color;
22import java.text.DateFormat;
23import java.util.ArrayList;
24import java.util.Arrays;
25import java.util.Collections;
26import java.util.Date;
27import java.util.List;
28import org.apache.commons.collections.CollectionUtils;
29import org.openide.util.NbBundle.Messages;
30import org.sleuthkit.autopsy.datasourcesummary.uiutils.BarChartSeries;
31import org.sleuthkit.autopsy.datasourcesummary.uiutils.BarChartSeries.BarChartItem;
32import org.sleuthkit.autopsy.datasourcesummary.uiutils.BarChartSeries.OrderedKey;
33import org.sleuthkit.autopsy.datasourcesummary.datamodel.DataFetcher;
34import org.sleuthkit.autopsy.datasourcesummary.datamodel.TimelineSummary;
35import org.sleuthkit.autopsy.datasourcesummary.datamodel.TimelineSummary.DailyActivityAmount;
36import org.sleuthkit.autopsy.datasourcesummary.datamodel.TimelineSummary.TimelineSummaryData;
37import org.sleuthkit.autopsy.report.modules.datasourcesummaryexport.ExcelSpecialFormatExport.KeyValueItemExportable;
38import org.sleuthkit.autopsy.report.modules.datasourcesummaryexport.ExcelSpecialFormatExport.TitledExportable;
39import org.sleuthkit.datamodel.DataSource;
40
44@Messages({
45 "TimelinePanel_earliestLabel_title=Earliest",
46 "TimelinePanel_latestLabel_title=Latest",
47 "TimlinePanel_last30DaysChart_title=Last 30 Days",
48 "TimlinePanel_last30DaysChart_fileEvts_title=File Events",
49 "TimlinePanel_last30DaysChart_artifactEvts_title=Result Events",})
50class ExportTimeline {
51
52 private final TimelineSummary timelineSummary;
53
54 private static final String EARLIEST_LATEST_FORMAT_STR = "MMM d, yyyy";
55 private static final DateFormat EARLIEST_LATEST_FORMAT = TimelineSummary.getUtcFormat(EARLIEST_LATEST_FORMAT_STR);
56 private static final DateFormat CHART_FORMAT = TimelineSummary.getUtcFormat("MMM d, yyyy");
57 private static final int MOST_RECENT_DAYS_COUNT = 30;
58
59 private static final Color FILE_EVT_COLOR = new Color(228, 22, 28);
60 private static final Color ARTIFACT_EVT_COLOR = new Color(21, 227, 100);
61
65 ExportTimeline() {
66 timelineSummary = new TimelineSummary();
67 }
68
80 private static List<BarChartSeries> parseChartData(List<DailyActivityAmount> recentDaysActivity, boolean showIntermediateDates) {
81 // if no data, return null indicating no result.
82 if (CollectionUtils.isEmpty(recentDaysActivity)) {
83 return null;
84 }
85
86 // Create a bar chart item for each recent days activity item
87 List<BarChartItem> fileEvtCounts = new ArrayList<>();
88 List<BarChartItem> artifactEvtCounts = new ArrayList<>();
89
90 for (int i = 0; i < recentDaysActivity.size(); i++) {
91 DailyActivityAmount curItem = recentDaysActivity.get(i);
92
93 long fileAmt = curItem.getFileActivityCount();
94 long artifactAmt = curItem.getArtifactActivityCount() * 100;
95 String formattedDate = (showIntermediateDates || i == 0 || i == recentDaysActivity.size() - 1)
96 ? TimelineSummary.formatDate(curItem.getDay(), CHART_FORMAT) : "";
97
98 OrderedKey thisKey = new OrderedKey(formattedDate, i);
99 fileEvtCounts.add(new BarChartItem(thisKey, fileAmt));
100 artifactEvtCounts.add(new BarChartItem(thisKey, artifactAmt));
101 }
102
103 return Arrays.asList(
104 new BarChartSeries(Bundle.TimlinePanel_last30DaysChart_fileEvts_title(), FILE_EVT_COLOR, fileEvtCounts),
105 new BarChartSeries(Bundle.TimlinePanel_last30DaysChart_artifactEvts_title(), ARTIFACT_EVT_COLOR, artifactEvtCounts));
106 }
107
115 private static DefaultCellModel<?> getEarliestLatestCell(Date date) {
116 return new DefaultCellModel<>(date, (dt) -> dt == null ? "" : EARLIEST_LATEST_FORMAT.format(dt), EARLIEST_LATEST_FORMAT_STR);
117 }
118
119 @Messages({
120 "TimelinePanel_getExports_sheetName=Timeline",
121 "TimelinePanel_getExports_activityRange=Activity Range",
122 "TimelinePanel_getExports_earliest=Earliest:",
123 "TimelinePanel_getExports_latest=Latest:",
124 "TimelinePanel_getExports_dateColumnHeader=Date",
125 "TimelinePanel_getExports_chartName=Last 30 Days",})
126 List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
127 DataFetcher<DataSource, TimelineSummaryData> dataFetcher = (ds) -> timelineSummary.getTimelineSummaryData(ds, MOST_RECENT_DAYS_COUNT);
128 TimelineSummaryData summaryData = ExcelExportAction.getFetchResult(dataFetcher, "Timeline", dataSource);
129 if (summaryData == null) {
130 return Collections.emptyList();
131 }
132
133 return Arrays.asList(
134 new ExcelSpecialFormatExport(Bundle.TimelinePanel_getExports_sheetName(),
135 Arrays.asList(
136 new TitledExportable(Bundle.TimelinePanel_getExports_activityRange(), Collections.emptyList()),
137 new KeyValueItemExportable(Bundle.TimelinePanel_getExports_earliest(), getEarliestLatestCell(summaryData.getMinDate())),
138 new KeyValueItemExportable(Bundle.TimelinePanel_getExports_latest(), getEarliestLatestCell(summaryData.getMaxDate())),
139 new BarChartExport(Bundle.TimelinePanel_getExports_dateColumnHeader(),
140 "#,###",
141 Bundle.TimelinePanel_getExports_chartName(),
142 parseChartData(summaryData.getMostRecentDaysActivity(), true)))));
143 }
144}
static String formatDate(Date date, DateFormat formatter)

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