19 package org.sleuthkit.autopsy.datasourcesummary.datamodel;
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.time.Instant;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.Date;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Locale;
34 import java.util.TimeZone;
35 import org.joda.time.Interval;
39 import org.
sleuthkit.datamodel.TimelineFilter.RootFilter;
43 import java.util.function.Supplier;
68 private static final long DAY_SECS = 24 * 60 * 60;
70 =
new HashSet<>(Arrays.asList(
71 TimelineEventType.FILE_MODIFIED,
72 TimelineEventType.FILE_ACCESSED,
73 TimelineEventType.FILE_CREATED,
74 TimelineEventType.FILE_CHANGED));
116 TimeZone timeZone = this.timeZoneProvider.get();
117 TimelineManager timelineManager = this.caseProvider.
get().getTimelineManager();
120 Map<Long, DailyActivityAmount> dateCounts =
getTimelineEventsByDay(dataSource, timelineManager, timeZone);
125 for (
long daysFromEpoch : dateCounts.keySet()) {
126 minDay = (minDay == null) ? daysFromEpoch : Math.min(minDay, daysFromEpoch);
127 maxDay = (maxDay == null) ? daysFromEpoch : Math.max(maxDay, daysFromEpoch);
131 if (minDay == null || maxDay == null) {
135 Date minDate =
new Date(minDay * 1000 * DAY_SECS);
136 Date maxDate =
new Date(maxDay * 1000 * DAY_SECS);
140 long minRecentDay = Math.max(maxDay - recentDaysNum + 1, minDay);
160 List<DailyActivityAmount> mostRecentActivityAmt =
new ArrayList<>();
162 for (
long curRecentDay = minRecentDay; curRecentDay <= maxDay; curRecentDay++) {
168 mostRecentActivityAmt.add(countsHandleNotFound);
170 return mostRecentActivityAmt;
186 private Map<Long, DailyActivityAmount>
getTimelineEventsByDay(DataSource dataSource, TimelineManager timelineManager, TimeZone timeZone)
187 throws TskCoreException, SleuthkitCaseProviderException {
188 RootFilter rootFilter = this.filterFunction.
apply(dataSource);
191 long curRunTime = System.currentTimeMillis();
192 List<TimelineEvent> events = timelineManager.getEvents(
new Interval(1, curRunTime), rootFilter);
195 Map<Long, DailyActivityAmount> dateCounts =
new HashMap<>();
196 for (TimelineEvent evt : events) {
197 long curSecondsFromEpoch = evt.getTime();
198 long curDaysFromEpoch = Instant.ofEpochMilli(curSecondsFromEpoch * 1000)
199 .atZone(timeZone.toZoneId())
206 Date thisDay = prevAmt == null ?
new Date(curDaysFromEpoch * 1000 * DAY_SECS) : prevAmt.
getDay();
209 long curFileEvtCount = prevFileEvtCount + (isFileEvt ? 1 : 0);
210 long curArtifactEvtCount = prevArtifactEvtCount + (isFileEvt ? 0 : 1);
212 dateCounts.put(curDaysFromEpoch,
new DailyActivityAmount(thisDay, curFileEvtCount, curArtifactEvtCount));
240 TimelineSummaryData(Date minDate, Date maxDate, List<DailyActivityAmount> recentDaysActivity, DataSource dataSource) {
243 this.histogramActivity = (recentDaysActivity == null) ? Collections.emptyList() : Collections.unmodifiableList(recentDaysActivity);
330 return new SimpleDateFormat(formatString, Locale.getDefault());
343 public static String
formatDate(Date date, DateFormat formatter) {
344 return date == null ? null : formatter.format(date);
final Supplier< TimeZone > timeZoneProvider
SleuthkitCaseProvider DEFAULT
final DataSourceFilterFunction filterFunction
DataSource getDataSource()
static DateFormat getUtcFormat(String formatString)
long getArtifactActivityCount()
RootFilter getDataSourceFilter(DataSource dataSource)
TimelineSummaryData getTimelineSummaryData(DataSource dataSource, int recentDaysNum)
final List< DailyActivityAmount > histogramActivity
List< DailyActivityAmount > getMostRecentDaysActivity()
final SleuthkitCaseProvider caseProvider
TimelineSummary(SleuthkitCaseProvider caseProvider, Supplier< TimeZone > timeZoneProvider, DataSourceFilterFunction filterFunction)
static final long DAY_SECS
RootFilter apply(DataSource dataSource)
static TimelineDataSourceUtils getInstance()
List< DailyActivityAmount > getMostRecentActivityAmounts(Map< Long, DailyActivityAmount > dateCounts, long minRecentDay, long maxDay)
static String getTimeZoneForDisplays()
final long fileActivityCount
final long artifactActivityCount
long getFileActivityCount()
Map< Long, DailyActivityAmount > getTimelineEventsByDay(DataSource dataSource, TimelineManager timelineManager, TimeZone timeZone)
static final Set< TimelineEventType > FILE_SYSTEM_EVENTS
final DataSource dataSource
static String formatDate(Date date, DateFormat formatter)