Autopsy  4.19.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;
33 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
34 
38 public abstract class AbstractWaypointFetcher implements WaypointBuilder.WaypointFilterQueryCallBack {
39 
40  private static final Logger logger = Logger.getLogger(AbstractWaypointFetcher.class.getName());
41 
42  private final GeoFilter filters;
43 
49  protected AbstractWaypointFetcher(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 
83  protected abstract void handleFilteredWaypointSet(Set<MapWaypoint> mapWaypoints, List<Set<MapWaypoint>> tracks,
84  List<Set<MapWaypoint>> areas, 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  GeoLocationParseResult<Area> areaResults = null;
98  if (filters.getArtifactTypes().contains(ARTIFACT_TYPE.TSK_GPS_AREA)) {
99  try {
100  areaResults = Area.getAreas(Case.getCurrentCase().getSleuthkitCase(), filters.getDataSources());
101  } catch (GeoLocationDataException ex) {
102  logger.log(Level.WARNING, "Exception thrown while retrieving list of Areas", ex);
103  }
104  }
105 
106  GeoDataSet geoDataSet = createWaypointList(
107  waypointResults.getItems(),
108  (trackResults == null) ? new ArrayList<>() : trackResults.getItems(),
109  (areaResults == null) ? new ArrayList<>() : areaResults.getItems());
110 
111 
112  final Set<MapWaypoint> pointSet = MapWaypoint.getWaypoints(geoDataSet.getWaypoints());
113  final List<Set<MapWaypoint>> trackSets = new ArrayList<>();
114  for (List<Waypoint> t : geoDataSet.getTracks()) {
115  trackSets.add(MapWaypoint.getWaypoints(t));
116  }
117  final List<Set<MapWaypoint>> areaSets = new ArrayList<>();
118  for (List<Waypoint> t : geoDataSet.getAreas()) {
119  areaSets.add(MapWaypoint.getWaypoints(t));
120  }
121 
123  pointSet, trackSets, areaSets,
124  (trackResults == null || trackResults.isSuccessfullyParsed())
125  && (areaResults == null || areaResults.isSuccessfullyParsed())
126  && waypointResults.isSuccessfullyParsed());
127  }
128 
140  private GeoDataSet createWaypointList(List<Waypoint> waypoints, List<Track> tracks, List<Area> areas) {
141  final List<Waypoint> completeList = new ArrayList<>();
142  List<List<Waypoint>> filteredTracks = new ArrayList<>();
143  List<List<Waypoint>> filteredAreas = new ArrayList<>();
144 
145  if (tracks != null) {
146  Long timeRangeEnd;
147  Long timeRangeStart;
148  if (!filters.showAllWaypoints()) {
149  // Figure out what the most recent time is given the filtered
150  // waypoints and the tracks.
151  timeRangeEnd = getMostRecent(waypoints, tracks);
152  timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays());
153 
154  completeList.addAll(getWaypointsInRange(timeRangeStart, timeRangeEnd, waypoints));
155 
156  filteredTracks = getTracksInRange(timeRangeStart, timeRangeEnd, tracks);
157  for (List<Waypoint> filteredTrack : filteredTracks) {
158  completeList.addAll(filteredTrack);
159  }
160  } else {
161  completeList.addAll(waypoints);
162  for (Track track : tracks) {
163  completeList.addAll(track.getPath());
164  filteredTracks.add(track.getPath());
165  }
166  }
167  } else {
168  completeList.addAll(waypoints);
169  }
170 
171  // Areas don't have timestamps so add all of them
172  for (Area area : areas) {
173  completeList.addAll(area.getPath());
174  filteredAreas.add(area.getPath());
175  }
176 
177  return new GeoDataSet(completeList, filteredTracks, filteredAreas);
178  }
179 
189  private List<Waypoint> getWaypointsInRange(Long timeRangeStart, Long timeRangeEnd, List<Waypoint> waypoints) {
190  List<Waypoint> completeList = new ArrayList<>();
191  // Add all of the waypoints that fix into the time range.
192  if (waypoints != null) {
193  for (Waypoint point : waypoints) {
194  Long time = point.getTimestamp();
195  if ((time == null && filters.showWaypointsWithoutTimeStamp())
196  || (time != null && (time >= timeRangeStart && time <= timeRangeEnd))) {
197 
198  completeList.add(point);
199  }
200  }
201  }
202  return completeList;
203  }
204 
217  private List<List<Waypoint>> getTracksInRange(Long timeRangeStart, Long timeRangeEnd, List<Track> tracks) {
218  List<List<Waypoint>> ret = new ArrayList<>();
219  if (tracks != null) {
220  for (Track track : tracks) {
221  Long trackTime = track.getStartTime();
222 
223  if ((trackTime == null && filters.showWaypointsWithoutTimeStamp())
224  || (trackTime != null && (trackTime >= timeRangeStart && trackTime <= timeRangeEnd))) {
225  ret.add(track.getPath());
226  }
227  }
228  }
229  return ret;
230  }
231 
239  private Long findMostRecentTimestamp(List<Waypoint> points) {
240 
241  Long mostRecent = null;
242 
243  for (Waypoint point : points) {
244  if (mostRecent == null) {
245  mostRecent = point.getTimestamp();
246  } else {
247  mostRecent = Math.max(mostRecent, point.getTimestamp());
248  }
249  }
250 
251  return mostRecent;
252  }
253 
261  private Long findMostRecentTracks(List<Track> tracks) {
262  Long mostRecent = null;
263 
264  for (Track track : tracks) {
265  if (mostRecent == null) {
266  mostRecent = track.getStartTime();
267  } else if (track.getStartTime() != null) {
268  mostRecent = Math.max(mostRecent, track.getStartTime());
269  }
270  }
271 
272  return mostRecent;
273  }
274 
284  private Long getMostRecent(List<Waypoint> points, List<Track> tracks) {
285  Long waypointMostRecent = findMostRecentTimestamp(points);
286  Long trackMostRecent = findMostRecentTracks(tracks);
287 
288  if (waypointMostRecent != null && trackMostRecent != null) {
289  return Math.max(waypointMostRecent, trackMostRecent);
290  } else if (waypointMostRecent == null && trackMostRecent != null) {
291  return trackMostRecent;
292  } else if (waypointMostRecent != null && trackMostRecent == null) {
293  return waypointMostRecent;
294  }
295 
296  return -1L;
297  }
298 
302  static class GeoDataSet {
303  private final List<Waypoint> waypoints;
304  private final List<List<Waypoint>> tracks;
305  private final List<List<Waypoint>> areas;
306 
307  GeoDataSet(List<Waypoint> waypoints, List<List<Waypoint>> tracks, List<List<Waypoint>> areas) {
308  this.waypoints = waypoints;
309  this.tracks = tracks;
310  this.areas = areas;
311  }
312 
313  List<Waypoint> getWaypoints() {
314  return waypoints;
315  }
316 
317  List<List<Waypoint>> getTracks() {
318  return tracks;
319  }
320 
321  List<List<Waypoint>> getAreas() {
322  return areas;
323  }
324  }
325 }
GeoDataSet createWaypointList(List< Waypoint > waypoints, List< Track > tracks, List< Area > areas)
static GeoLocationParseResult< Track > getTracks(SleuthkitCase skCase, List<?extends Content > sourceList)
Definition: GeoPath.java:80
void process(GeoLocationParseResult< Waypoint > waypointResults)
Long getMostRecent(List< Waypoint > points, List< Track > tracks)
static List< Waypoint > getAllWaypoints(SleuthkitCase skCase)
abstract void handleFilteredWaypointSet(Set< MapWaypoint > mapWaypoints, List< Set< MapWaypoint >> tracks, List< Set< MapWaypoint >> areas, boolean wasEntirelySuccessful)
List< List< Waypoint > > getTracksInRange(Long timeRangeStart, Long timeRangeEnd, List< Track > tracks)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static GeoLocationParseResult< Area > getAreas(SleuthkitCase skCase, List<?extends Content > sourceList)
Definition: GeoPath.java:115
List< Waypoint > getWaypointsInRange(Long timeRangeStart, Long timeRangeEnd, List< Waypoint > waypoints)

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