Geolocation changes to address codacy issues

This commit is contained in:
Kelly Kelly 2020-01-15 11:08:59 -05:00
parent 544974f7e8
commit 0a006421e7
5 changed files with 117 additions and 84 deletions

View File

@ -38,7 +38,6 @@ import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import org.openide.filesystems.FileUtil; import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
import org.openide.windows.RetainLocation; import org.openide.windows.RetainLocation;
import org.openide.windows.TopComponent; import org.openide.windows.TopComponent;
@ -458,7 +457,7 @@ public final class GeolocationTopComponent extends TopComponent {
} catch (GeoLocationDataException ex) { } catch (GeoLocationDataException ex) {
logger.log(Level.WARNING, "Exception thrown while retrieving list of Tracks", ex); logger.log(Level.WARNING, "Exception thrown while retrieving list of Tracks", ex);
} }
final List<Waypoint> completeList = createWaypointList(waypoints, tracks); final List<Waypoint> completeList = createWaypointList(waypoints, tracks);
// Make sure that the waypoints are added to the map panel in // Make sure that the waypoints are added to the map panel in
@ -487,14 +486,14 @@ public final class GeolocationTopComponent extends TopComponent {
} }
/** /**
* Returns a complete list of waypoints including the tracks. Takes into * Returns a complete list of waypoints including the tracks. Takes into
* account the current filters and includes waypoints as approprate. * account the current filters and includes waypoints as approprate.
* *
* @param waypoints List of waypoints * @param waypoints List of waypoints
* @param tracks List of tracks * @param tracks List of tracks
* *
* @return A list of waypoints including the tracks based on the current * @return A list of waypoints including the tracks based on the current
* filters. * filters.
*/ */
private List<Waypoint> createWaypointList(List<Waypoint> waypoints, List<Track> tracks) { private List<Waypoint> createWaypointList(List<Waypoint> waypoints, List<Track> tracks) {
final List<Waypoint> completeList = new ArrayList<>(); final List<Waypoint> completeList = new ArrayList<>();
@ -508,31 +507,11 @@ public final class GeolocationTopComponent extends TopComponent {
timeRangeEnd = getMostRecent(waypoints, tracks); timeRangeEnd = getMostRecent(waypoints, tracks);
timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays()); timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays());
// Add all of the waypoints that fix into the time range. completeList.addAll(getWaypointsInRange(timeRangeStart, timeRangeEnd, waypoints));
for (Waypoint point : waypoints) { completeList.addAll(getTracksInRange(timeRangeStart, timeRangeEnd, tracks));
Long time = point.getTimestamp();
if ((time == null && filters.showWaypointsWithoutTimeStamp())
|| (time != null && (time >= timeRangeStart && time <= timeRangeEnd))) {
completeList.add(point);
}
}
// Add all of the tracks, using only the start timestamp
// of the track to determine if the track fixes into the
// range.
for (Track track : tracks) {
Long trackTime = track.getStartTime();
if ((trackTime == null && filters.showWaypointsWithoutTimeStamp())
|| (trackTime != null && (trackTime >= timeRangeStart && trackTime <= timeRangeEnd))) {
completeList.addAll(track.getPath());
}
}
} else { } else {
completeList.addAll(waypoints); completeList.addAll(waypoints);
for (Track track : tracks) { for (Track track : tracks) {
completeList.addAll(track.getPath()); completeList.addAll(track.getPath());
} }
@ -543,12 +522,69 @@ public final class GeolocationTopComponent extends TopComponent {
return completeList; return completeList;
} }
/**
* Return a list of waypoints that fall into the given time range.
*
* @param timeRangeStart start timestamp of range (seconds from java
* epoch)
* @param timeRangeEnd start timestamp of range (seconds from java
* epoch)
* @param waypoints List of waypoints to filter.
*
* @return A list of waypoints that fall into the time range.
*/
private List<Waypoint> getWaypointsInRange(Long timeRangeStart, Long timeRangeEnd, List<Waypoint> waypoints) {
List<Waypoint> completeList = new ArrayList<>();
// Add all of the waypoints that fix into the time range.
if (waypoints != null) {
for (Waypoint point : waypoints) {
Long time = point.getTimestamp();
if ((time == null && filters.showWaypointsWithoutTimeStamp())
|| (time != null && (time >= timeRangeStart && time <= timeRangeEnd))) {
completeList.add(point);
}
}
}
return completeList;
}
/**
* Return a list of waypoints from the given tracks that fall into for
* tracks that fall into the given time range. The track start time will
* used for determining if the whole track falls into the range.
*
* @param timeRangeStart start timestamp of range (seconds from java
* epoch)
* @param timeRangeEnd start timestamp of range (seconds from java
* epoch)
* @param tracks Track list.
*
* @return A list of waypoints that that belong to tracks that fall into
* the time range.
*/
private List<Waypoint> getTracksInRange(Long timeRangeStart, Long timeRangeEnd, List<Track> tracks) {
List<Waypoint> completeList = new ArrayList<>();
if (tracks != null) {
for (Track track : tracks) {
Long trackTime = track.getStartTime();
if ((trackTime == null && filters.showWaypointsWithoutTimeStamp())
|| (trackTime != null && (trackTime >= timeRangeStart && trackTime <= timeRangeEnd))) {
completeList.addAll(track.getPath());
}
}
}
return completeList;
}
/** /**
* Find the latest time stamp in the given list of waypoints. * Find the latest time stamp in the given list of waypoints.
* *
* @param points List of Waypoints, required. * @param points List of Waypoints, required.
* *
* @return The latest time stamp (seconds from java epoch) * @return The latest time stamp (seconds from java epoch)
*/ */
private Long findMostRecentTimestamp(List<Waypoint> points) { private Long findMostRecentTimestamp(List<Waypoint> points) {
@ -568,9 +604,9 @@ public final class GeolocationTopComponent extends TopComponent {
/** /**
* Find the latest time stamp in the given list of tracks. * Find the latest time stamp in the given list of tracks.
* *
* @param tracks List of Waypoints, required. * @param tracks List of Waypoints, required.
* *
* @return The latest time stamp (seconds from java epoch) * @return The latest time stamp (seconds from java epoch)
*/ */
private Long findMostRecentTracks(List<Track> tracks) { private Long findMostRecentTracks(List<Track> tracks) {
@ -588,12 +624,12 @@ public final class GeolocationTopComponent extends TopComponent {
} }
/** /**
* Returns the "most recent" timestamp amount the list of waypoints * Returns the "most recent" timestamp amount the list of waypoints and
* and track points. * track points.
* *
* @param points List of Waypoints * @param points List of Waypoints
* @param tracks List of Tracks * @param tracks List of Tracks
* *
* @return Latest time stamp (seconds from java epoch) * @return Latest time stamp (seconds from java epoch)
*/ */
private Long getMostRecent(List<Waypoint> points, List<Track> tracks) { private Long getMostRecent(List<Waypoint> points, List<Track> tracks) {

View File

@ -45,12 +45,7 @@ import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
import org.sleuthkit.autopsy.directorytree.ExternalViewerShortcutAction; import org.sleuthkit.autopsy.directorytree.ExternalViewerShortcutAction;
import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.actionhelpers.ExtractActionHelper; import org.sleuthkit.autopsy.directorytree.actionhelpers.ExtractActionHelper;
import org.sleuthkit.autopsy.geolocation.datamodel.GeoLocationDataException;
import org.sleuthkit.autopsy.geolocation.datamodel.Route;
import org.sleuthkit.autopsy.geolocation.datamodel.Track;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.autopsy.geolocation.datamodel.Waypoint; import org.sleuthkit.autopsy.geolocation.datamodel.Waypoint;
import org.sleuthkit.autopsy.geolocation.datamodel.WaypointBuilder;
import org.sleuthkit.autopsy.timeline.actions.ViewArtifactInTimelineAction; import org.sleuthkit.autopsy.timeline.actions.ViewArtifactInTimelineAction;
import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact;

View File

@ -31,8 +31,8 @@ import org.sleuthkit.datamodel.TskCoreException;
* Class representing a series of waypoints that form a path. * Class representing a series of waypoints that form a path.
*/ */
public class Path { public class Path {
private final List<Waypoint> path; private final List<Waypoint> waypointList;
private final String pathName; private final String pathName;
private final BlackboardArtifact artifact; private final BlackboardArtifact artifact;
@ -65,9 +65,9 @@ public class Path {
/** /**
* Gets the list of Routes from the TSK_GPS_TRACK artifacts. * Gets the list of Routes from the TSK_GPS_TRACK artifacts.
* *
* @param skCase Currently open SleuthkitCase * @param skCase Currently open SleuthkitCase
* @param sourceList List of source to return tracks from, maybe null to * @param sourceList List of source to return tracks from, maybe null to
* return tracks from all sources * return tracks from all sources
* *
* @return List of Route objects, empty list will be returned if no Routes * @return List of Route objects, empty list will be returned if no Routes
* were found * were found
@ -76,63 +76,63 @@ public class Path {
*/ */
static public List<Track> getTracks(SleuthkitCase skCase, List<? extends Content> sourceList) throws GeoLocationDataException { static public List<Track> getTracks(SleuthkitCase skCase, List<? extends Content> sourceList) throws GeoLocationDataException {
List<BlackboardArtifact> artifacts = null; List<BlackboardArtifact> artifacts = null;
List<Track> tracks = new ArrayList<>(); List<Track> tracks = new ArrayList<>();
try { try {
artifacts = skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACK); artifacts = skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACK);
for (BlackboardArtifact artifact : artifacts) { for (BlackboardArtifact artifact : artifacts) {
if(sourceList == null || sourceList.contains(artifact.getDataSource())){ if (sourceList == null || sourceList.contains(artifact.getDataSource())) {
Track route = new Track(artifact); Track route = new Track(artifact);
tracks.add(route); tracks.add(route);
}
} }
}
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
throw new GeoLocationDataException("Unable to get artifacts for type: TSK_GPS_BOOKMARK", ex); throw new GeoLocationDataException("Unable to get artifacts for type: TSK_GPS_BOOKMARK", ex);
} }
return tracks; return tracks;
} }
/** /**
* Path constructor. * Path constructor.
* *
* @param artifact BlackboardARtifact that this path represents, required * @param artifact BlackboardARtifact that this path represents, required
* @param pathName Name for this path, maybe null or empty string. * @param pathName Name for this path, maybe null or empty string.
*/ */
Path(BlackboardArtifact artifact, String pathName) { Path(BlackboardArtifact artifact, String pathName) {
this.path = new ArrayList<>(); this.waypointList = new ArrayList<>();
this.pathName = pathName; this.pathName = pathName;
this.artifact = artifact; this.artifact = artifact;
} }
/** /**
* Adds a Waypoint to the path. * Adds a Waypoint to the path.
* *
* @param point * @param point
*/ */
final void addToPath(Waypoint point) { final void addToPath(Waypoint point) {
path.add(point); waypointList.add(point);
} }
/** /**
* Get the list of way points for this route; * Get the list of way points for this route;
* *
* @return List an unmodifiableList of ArtifactWaypoints for this route * @return List an unmodifiableList of ArtifactWaypoints for this route
*/ */
final public List<Waypoint> getPath() { final public List<Waypoint> getPath() {
return Collections.unmodifiableList(path); return Collections.unmodifiableList(waypointList);
} }
/** /**
* Returns the BlackboardARtifact that this path represents. * Returns the BlackboardARtifact that this path represents.
* *
* @return * @return
*/ */
final BlackboardArtifact getArtifact() { final BlackboardArtifact getArtifact() {
return artifact; return artifact;
} }
/** /**
* Returns the label\display name for this path. * Returns the label\display name for this path.
* *
* @return Path label, empty string * @return Path label, empty string
*/ */
public String getLabel() { public String getLabel() {

View File

@ -133,7 +133,7 @@ public final class WaypointBuilder {
List<Route> routeList = new ArrayList<>(); List<Route> routeList = new ArrayList<>();
for (Waypoint point : waypoints) { for (Waypoint point : waypoints) {
Path path = point.getPath(); Path path = point.getPath();
if (path != null && path instanceof Route) { if (path instanceof Route) {
Route route = (Route) path; Route route = (Route) path;
if (!routeList.contains(route)) { if (!routeList.contains(route)) {
routeList.add(route); routeList.add(route);
@ -143,7 +143,7 @@ public final class WaypointBuilder {
return routeList; return routeList;
} }
/** /**
* Returns a list of tracks from the given list of waypoints. * Returns a list of tracks from the given list of waypoints.
* *
@ -155,7 +155,7 @@ public final class WaypointBuilder {
List<Track> trackList = new ArrayList<>(); List<Track> trackList = new ArrayList<>();
for (Waypoint point : waypoints) { for (Waypoint point : waypoints) {
Path path = point.getPath(); Path path = point.getPath();
if (path != null && path instanceof Track) { if (path instanceof Track) {
Track route = (Track) path; Track route = (Track) path;
if (!trackList.contains(route)) { if (!trackList.contains(route)) {
trackList.add(route); trackList.add(route);
@ -495,18 +495,16 @@ public final class WaypointBuilder {
* @return SQL SELECT statement * @return SQL SELECT statement
*/ */
static private String buildQueryForWaypointsWOTimeStamps(List<DataSource> dataSources) { static private String buildQueryForWaypointsWOTimeStamps(List<DataSource> dataSources) {
// SELECT_WO_TIMESTAMP // SELECT_WO_TIMESTAMP
// SELECT DISTINCT artifact_id, artifact_type_id // SELECT DISTINCT artifact_id, artifact_type_id
// FROM blackboard_attributes // FROM blackboard_attributes
// WHERE artifact_id NOT IN (%s) // WHERE artifact_id NOT IN (%s)
// AND artifact_id IN (%s) // AND artifact_id IN (%s)
// GEO_ARTIFACT_QUERY_ID_ONLY // GEO_ARTIFACT_QUERY_ID_ONLY
// SELECT artifact_id // SELECT artifact_id
// FROM blackboard_attributes // FROM blackboard_attributes
// WHERE attribute_type_id IN (%d, %d) // WHERE attribute_type_id IN (%d, %d)
return String.format(SELECT_WO_TIMESTAMP, return String.format(SELECT_WO_TIMESTAMP,
String.format(GEO_ARTIFACT_QUERY_ID_ONLY, String.format(GEO_ARTIFACT_QUERY_ID_ONLY,
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(),
@ -548,12 +546,12 @@ public final class WaypointBuilder {
// IN ( %s ) // IN ( %s )
// //
mostRecentQuery = String.format("AND value_int64 > (%s)", //NON-NLS mostRecentQuery = String.format("AND value_int64 > (%s)", //NON-NLS
String.format(MOST_RECENT_TIME, String.format(MOST_RECENT_TIME,
cntDaysFromRecent, cntDaysFromRecent,
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(),
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(), BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
getWaypointListQuery(dataSources) getWaypointListQuery(dataSources)
)); ));
} }
// GEO_ARTIFACT_QUERY // GEO_ARTIFACT_QUERY
@ -647,8 +645,12 @@ public final class WaypointBuilder {
case TSK_GPS_LAST_KNOWN_LOCATION: case TSK_GPS_LAST_KNOWN_LOCATION:
waypoints.add(new LastKnownWaypoint(artifact)); waypoints.add(new LastKnownWaypoint(artifact));
break; break;
case TSK_GPS_TRACK:
Track track = new Track(artifact);
waypoints.addAll(track.getPath());
break;
default: default:
waypoints.add(new CustomArtifactWaypoint(artifact)); waypoints.add(new CustomArtifactWaypoint(artifact));
} }
return waypoints; return waypoints;

View File

@ -424,7 +424,7 @@ public final class KMLReport implements GeneralReportModule {
/** /**
* Add the given route to the KML report. * Add the given route to the KML report.
* *
* @param route * @param route
*/ */
private void addRouteToReport(Route route) { private void addRouteToReport(Route route) {
@ -495,7 +495,7 @@ public final class KMLReport implements GeneralReportModule {
/** /**
* Add a track to the KML report. * Add a track to the KML report.
* *
* @param track * @param track
*/ */
private void addTrackToReport(Track track) { private void addTrackToReport(Track track) {