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;
@ -508,7 +507,37 @@ public final class GeolocationTopComponent extends TopComponent {
timeRangeEnd = getMostRecent(waypoints, tracks); timeRangeEnd = getMostRecent(waypoints, tracks);
timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays()); timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays());
completeList.addAll(getWaypointsInRange(timeRangeStart, timeRangeEnd, waypoints));
completeList.addAll(getTracksInRange(timeRangeStart, timeRangeEnd, tracks));
} else {
completeList.addAll(waypoints);
for (Track track : tracks) {
completeList.addAll(track.getPath());
}
}
} else {
completeList.addAll(waypoints);
}
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. // Add all of the waypoints that fix into the time range.
if (waypoints != null) {
for (Waypoint point : waypoints) { for (Waypoint point : waypoints) {
Long time = point.getTimestamp(); Long time = point.getTimestamp();
if ((time == null && filters.showWaypointsWithoutTimeStamp()) if ((time == null && filters.showWaypointsWithoutTimeStamp())
@ -517,10 +546,27 @@ public final class GeolocationTopComponent extends TopComponent {
completeList.add(point); completeList.add(point);
} }
} }
}
return completeList;
}
// Add all of the tracks, using only the start timestamp /**
// of the track to determine if the track fixes into the * Return a list of waypoints from the given tracks that fall into for
// range. * 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) { for (Track track : tracks) {
Long trackTime = track.getStartTime(); Long trackTime = track.getStartTime();
@ -530,17 +576,7 @@ public final class GeolocationTopComponent extends TopComponent {
completeList.addAll(track.getPath()); completeList.addAll(track.getPath());
} }
} }
} else {
completeList.addAll(waypoints);
for (Track track : tracks) {
completeList.addAll(track.getPath());
} }
}
} else {
completeList.addAll(waypoints);
}
return completeList; return completeList;
} }
@ -588,8 +624,8 @@ 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

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

@ -32,7 +32,7 @@ import org.sleuthkit.datamodel.TskCoreException;
*/ */
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;
@ -80,7 +80,7 @@ public class Path {
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);
} }
@ -98,7 +98,7 @@ public class Path {
* @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;
} }
@ -109,7 +109,7 @@ public class Path {
* @param point * @param point
*/ */
final void addToPath(Waypoint point) { final void addToPath(Waypoint point) {
path.add(point); waypointList.add(point);
} }
/** /**
@ -118,7 +118,7 @@ public class Path {
* @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);
} }
/** /**

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);
@ -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);
@ -501,12 +501,10 @@ public final class WaypointBuilder {
// 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(),
@ -647,6 +645,10 @@ 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));
} }