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.SwingWorker;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.RetainLocation;
import org.openide.windows.TopComponent;
@ -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.
*
* @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
* filters.
* @return A list of waypoints including the tracks based on the current
* filters.
*/
private List<Waypoint> createWaypointList(List<Waypoint> waypoints, List<Track> tracks) {
final List<Waypoint> completeList = new ArrayList<>();
@ -508,31 +507,11 @@ public final class GeolocationTopComponent extends TopComponent {
timeRangeEnd = getMostRecent(waypoints, tracks);
timeRangeStart = timeRangeEnd - (86400 * filters.getMostRecentNumDays());
// Add all of the waypoints that fix into the time range.
for (Waypoint point : waypoints) {
Long time = point.getTimestamp();
if ((time == null && filters.showWaypointsWithoutTimeStamp())
|| (time != null && (time >= timeRangeStart && time <= timeRangeEnd))) {
completeList.addAll(getWaypointsInRange(timeRangeStart, timeRangeEnd, waypoints));
completeList.addAll(getTracksInRange(timeRangeStart, timeRangeEnd, tracks));
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 {
completeList.addAll(waypoints);
for (Track track : tracks) {
completeList.addAll(track.getPath());
}
@ -544,6 +523,63 @@ public final class GeolocationTopComponent extends TopComponent {
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.
*
@ -588,8 +624,8 @@ public final class GeolocationTopComponent extends TopComponent {
}
/**
* Returns the "most recent" timestamp amount the list of waypoints
* and track points.
* Returns the "most recent" timestamp amount the list of waypoints and
* track points.
*
* @param points List of Waypoints
* @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.ExtractAction;
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.WaypointBuilder;
import org.sleuthkit.autopsy.timeline.actions.ViewArtifactInTimelineAction;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.BlackboardArtifact;

View File

@ -32,7 +32,7 @@ import org.sleuthkit.datamodel.TskCoreException;
*/
public class Path {
private final List<Waypoint> path;
private final List<Waypoint> waypointList;
private final String pathName;
private final BlackboardArtifact artifact;
@ -65,9 +65,9 @@ public class Path {
/**
* Gets the list of Routes from the TSK_GPS_TRACK artifacts.
*
* @param skCase Currently open SleuthkitCase
* @param sourceList List of source to return tracks from, maybe null to
* return tracks from all sources
* @param skCase Currently open SleuthkitCase
* @param sourceList List of source to return tracks from, maybe null to
* return tracks from all sources
*
* @return List of Route objects, empty list will be returned if no Routes
* were found
@ -76,15 +76,15 @@ public class Path {
*/
static public List<Track> getTracks(SleuthkitCase skCase, List<? extends Content> sourceList) throws GeoLocationDataException {
List<BlackboardArtifact> artifacts = null;
List<Track> tracks = new ArrayList<>();
List<Track> tracks = new ArrayList<>();
try {
artifacts = skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACK);
for (BlackboardArtifact artifact : artifacts) {
if(sourceList == null || sourceList.contains(artifact.getDataSource())){
Track route = new Track(artifact);
tracks.add(route);
for (BlackboardArtifact artifact : artifacts) {
if (sourceList == null || sourceList.contains(artifact.getDataSource())) {
Track route = new Track(artifact);
tracks.add(route);
}
}
}
} catch (TskCoreException ex) {
throw new GeoLocationDataException("Unable to get artifacts for type: TSK_GPS_BOOKMARK", ex);
}
@ -98,7 +98,7 @@ public class Path {
* @param pathName Name for this path, maybe null or empty string.
*/
Path(BlackboardArtifact artifact, String pathName) {
this.path = new ArrayList<>();
this.waypointList = new ArrayList<>();
this.pathName = pathName;
this.artifact = artifact;
}
@ -109,7 +109,7 @@ public class Path {
* @param 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
*/
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<>();
for (Waypoint point : waypoints) {
Path path = point.getPath();
if (path != null && path instanceof Route) {
if (path instanceof Route) {
Route route = (Route) path;
if (!routeList.contains(route)) {
routeList.add(route);
@ -155,7 +155,7 @@ public final class WaypointBuilder {
List<Track> trackList = new ArrayList<>();
for (Waypoint point : waypoints) {
Path path = point.getPath();
if (path != null && path instanceof Track) {
if (path instanceof Track) {
Track route = (Track) path;
if (!trackList.contains(route)) {
trackList.add(route);
@ -501,12 +501,10 @@ public final class WaypointBuilder {
// FROM blackboard_attributes
// WHERE artifact_id NOT IN (%s)
// AND artifact_id IN (%s)
// GEO_ARTIFACT_QUERY_ID_ONLY
// SELECT artifact_id
// FROM blackboard_attributes
// WHERE attribute_type_id IN (%d, %d)
return String.format(SELECT_WO_TIMESTAMP,
String.format(GEO_ARTIFACT_QUERY_ID_ONLY,
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(),
@ -548,12 +546,12 @@ public final class WaypointBuilder {
// IN ( %s )
//
mostRecentQuery = String.format("AND value_int64 > (%s)", //NON-NLS
String.format(MOST_RECENT_TIME,
cntDaysFromRecent,
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(),
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
getWaypointListQuery(dataSources)
));
String.format(MOST_RECENT_TIME,
cntDaysFromRecent,
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(),
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(),
getWaypointListQuery(dataSources)
));
}
// GEO_ARTIFACT_QUERY
@ -647,8 +645,12 @@ public final class WaypointBuilder {
case TSK_GPS_LAST_KNOWN_LOCATION:
waypoints.add(new LastKnownWaypoint(artifact));
break;
case TSK_GPS_TRACK:
Track track = new Track(artifact);
waypoints.addAll(track.getPath());
break;
default:
waypoints.add(new CustomArtifactWaypoint(artifact));
waypoints.add(new CustomArtifactWaypoint(artifact));
}
return waypoints;