Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractWaypointFetcher.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2020 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  */
19 package org.sleuthkit.autopsy.geolocation;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Set;
24 import java.util.logging.Level;
25 import javafx.util.Pair;
33 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
34 
38 abstract class AbstractWaypointFetcher implements WaypointBuilder.WaypointFilterQueryCallBack {
39 
40  private static final Logger logger = Logger.getLogger(AbstractWaypointFetcher.class.getName());
41 
42  private final GeoFilterPanel.GeoFilter filters;
43 
49  AbstractWaypointFetcher(GeoFilterPanel.GeoFilter filters) {
50  this.filters = filters;
51  }
52 
62  void getWaypoints() throws GeoLocationDataException {
63  Case currentCase = Case.getCurrentCase();
65  filters.getDataSources(),
66  filters.getArtifactTypes(),
67  filters.showAllWaypoints(),
68  filters.getMostRecentNumDays(),
69  filters.showWaypointsWithoutTimeStamp(),
70  this);
71 
72  }
73 
74 
83  abstract void handleFilteredWaypointSet(Set<MapWaypoint> mapWaypoints, List<Set<MapWaypoint>> tracks,
84  boolean wasEntirelySuccessful);
85 
86  @Override
87  public void process(GeoLocationParseResult<Waypoint> waypointResults) {
88  GeoLocationParseResult<Track> trackResults = null;
89  if (filters.getArtifactTypes().contains(ARTIFACT_TYPE.TSK_GPS_TRACK)) {
90  try {
91  trackResults = Track.getTracks(Case.getCurrentCase().getSleuthkitCase(), filters.getDataSources());
92  } catch (GeoLocationDataException ex) {
93  logger.log(Level.WARNING, "Exception thrown while retrieving list of Tracks", ex);
94  }
95  }
96 
97  Pair<List<Waypoint>, List<List<Waypoint>>> waypointsAndTracks = createWaypointList(
98  waypointResults.getItems(),
99  (trackResults == null) ? new ArrayList<Track>() : trackResults.getItems());
100 
101 
102  final Set<MapWaypoint> pointSet = MapWaypoint.getWaypoints(waypointsAndTracks.getKey());
103  final List<Set<MapWaypoint>> trackSets = new ArrayList<>();
104  for (List<Waypoint> t : waypointsAndTracks.getValue()) {
105  trackSets.add(MapWaypoint.getWaypoints(t));
106  }
107 
108  handleFilteredWaypointSet(
109  pointSet, trackSets,
110  (trackResults == null || trackResults.isSuccessfullyParsed()) && waypointResults.isSuccessfullyParsed());
111  }
112 
123  private Pair<List<Waypoint>, List<List<Waypoint>>> createWaypointList(List<Waypoint> waypoints, List<Track> tracks) {
124  final List<Waypoint> completeList = new ArrayList<>();
125  List<List<Waypoint>> filteredTracks = new ArrayList<>();
126 
127  if (tracks != null) {
128  Long timeRangeEnd;
129  Long timeRangeStart;
130  if (!filters.showAllWaypoints()) {
131  // Figure out what the most recent time is given the filtered
132  // waypoints and the tracks.
133  timeRangeEnd = getMostRecent(waypoints, tracks);
134  timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays());
135 
136  completeList.addAll(getWaypointsInRange(timeRangeStart, timeRangeEnd, waypoints));
137 
138  filteredTracks = getTracksInRange(timeRangeStart, timeRangeEnd, tracks);
139  for (List<Waypoint> filteredTrack : filteredTracks) {
140  completeList.addAll(filteredTrack);
141  }
142  } else {
143  completeList.addAll(waypoints);
144  for (Track track : tracks) {
145  completeList.addAll(track.getPath());
146  filteredTracks.add(track.getPath());
147  }
148  }
149  } else {
150  completeList.addAll(waypoints);
151  }
152  return new Pair<>(completeList, filteredTracks);
153  }
154 
164  private List<Waypoint> getWaypointsInRange(Long timeRangeStart, Long timeRangeEnd, List<Waypoint> waypoints) {
165  List<Waypoint> completeList = new ArrayList<>();
166  // Add all of the waypoints that fix into the time range.
167  if (waypoints != null) {
168  for (Waypoint point : waypoints) {
169  Long time = point.getTimestamp();
170  if ((time == null && filters.showWaypointsWithoutTimeStamp())
171  || (time != null && (time >= timeRangeStart && time <= timeRangeEnd))) {
172 
173  completeList.add(point);
174  }
175  }
176  }
177  return completeList;
178  }
179 
192  private List<List<Waypoint>> getTracksInRange(Long timeRangeStart, Long timeRangeEnd, List<Track> tracks) {
193  List<List<Waypoint>> ret = new ArrayList<>();
194  if (tracks != null) {
195  for (Track track : tracks) {
196  Long trackTime = track.getStartTime();
197 
198  if ((trackTime == null && filters.showWaypointsWithoutTimeStamp())
199  || (trackTime != null && (trackTime >= timeRangeStart && trackTime <= timeRangeEnd))) {
200  ret.add(track.getPath());
201  }
202  }
203  }
204  return ret;
205  }
206 
214  private Long findMostRecentTimestamp(List<Waypoint> points) {
215 
216  Long mostRecent = null;
217 
218  for (Waypoint point : points) {
219  if (mostRecent == null) {
220  mostRecent = point.getTimestamp();
221  } else {
222  mostRecent = Math.max(mostRecent, point.getTimestamp());
223  }
224  }
225 
226  return mostRecent;
227  }
228 
236  private Long findMostRecentTracks(List<Track> tracks) {
237  Long mostRecent = null;
238 
239  for (Track track : tracks) {
240  if (mostRecent == null) {
241  mostRecent = track.getStartTime();
242  } else if (track.getStartTime() != null) {
243  mostRecent = Math.max(mostRecent, track.getStartTime());
244  }
245  }
246 
247  return mostRecent;
248  }
249 
259  private Long getMostRecent(List<Waypoint> points, List<Track> tracks) {
260  Long waypointMostRecent = findMostRecentTimestamp(points);
261  Long trackMostRecent = findMostRecentTracks(tracks);
262 
263  if (waypointMostRecent != null && trackMostRecent != null) {
264  return Math.max(waypointMostRecent, trackMostRecent);
265  } else if (waypointMostRecent == null && trackMostRecent != null) {
266  return trackMostRecent;
267  } else if (waypointMostRecent != null && trackMostRecent == null) {
268  return waypointMostRecent;
269  }
270 
271  return -1L;
272  }
273 }
static GeoLocationParseResult< Track > getTracks(SleuthkitCase skCase, List<?extends Content > sourceList)
Definition: GeoPath.java:76
static List< Waypoint > getAllWaypoints(SleuthkitCase skCase)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.