Skip to content
Snippets Groups Projects
Commit 5dcf4a94 authored by Kelly Kelly's avatar Kelly Kelly
Browse files

Updated with format changes

parent 9629dcd6
No related branches found
No related tags found
No related merge requests found
...@@ -19,19 +19,20 @@ ...@@ -19,19 +19,20 @@
package org.sleuthkit.datamodel.blackboardutils; package org.sleuthkit.datamodel.blackboardutils;
import org.sleuthkit.datamodel.blackboardutils.attributes.GeoTrackPoints; import org.sleuthkit.datamodel.blackboardutils.attributes.GeoTrackPoints;
import com.google.gson.Gson;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import org.sleuthkit.datamodel.Blackboard.BlackboardException; import org.sleuthkit.datamodel.Blackboard.BlackboardException;
import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.blackboardutils.attributes.GeoWaypoint.GeoTrackPoint;
/** /**
* Class to help ingest modules create Geolocation artifacts. * Class to help ingest modules create Geolocation artifacts.
* *
*/ */
public final class GeoArtifactsHelper extends ArtifactHelperBase { public final class GeoArtifactsHelper extends ArtifactHelperBase {
...@@ -59,7 +60,7 @@ public GeoArtifactsHelper(SleuthkitCase caseDb, String moduleName, Content srcFi ...@@ -59,7 +60,7 @@ public GeoArtifactsHelper(SleuthkitCase caseDb, String moduleName, Content srcFi
* @throws TskCoreException If there is an error creating the artifact. * @throws TskCoreException If there is an error creating the artifact.
* @throws BlackboardException If there is a problem posting the artifact * @throws BlackboardException If there is a problem posting the artifact
*/ */
public BlackboardArtifact addTrack(String trackName, GeoTrackPoints points) throws TskCoreException, BlackboardException { public BlackboardArtifact addTrack(String trackName, List<GeoTrackPoint> points) throws TskCoreException, BlackboardException {
if (points == null) { if (points == null) {
throw new IllegalArgumentException("GeoTrackPoint instance must be valid"); throw new IllegalArgumentException("GeoTrackPoint instance must be valid");
} }
...@@ -69,33 +70,17 @@ public BlackboardArtifact addTrack(String trackName, GeoTrackPoints points) thro ...@@ -69,33 +70,17 @@ public BlackboardArtifact addTrack(String trackName, GeoTrackPoints points) thro
artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), trackName)); artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), trackName));
} }
addPathToArtifact(artifact, points); artifact.addAttribute(
new BlackboardAttribute(
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_TRACKPOINTS,
getModuleName(),
GeoTrackPoints.serializePoints(points)));
getSleuthkitCase().getBlackboard().postArtifact(artifact, getModuleName()); getSleuthkitCase().getBlackboard().postArtifact(artifact, getModuleName());
return artifact; return artifact;
} }
/**
* Creates the json for GeoTrackPoints and adds as attribute to the given
* artifact.
*
* @param artifact
* @param points
*
* @throws TskCoreException
*/
private void addPathToArtifact(BlackboardArtifact artifact, GeoTrackPoints points) throws TskCoreException {
Gson gson = new Gson();
String jsonString = gson.toJson(points);
artifact.addAttribute(
new BlackboardAttribute(
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_TRACKPOINTS,
getModuleName(),
jsonString));
}
/** /**
* Adds a TSK_GPS_TRACKPOINT artifact. * Adds a TSK_GPS_TRACKPOINT artifact.
* *
...@@ -109,7 +94,7 @@ private void addPathToArtifact(BlackboardArtifact artifact, GeoTrackPoints point ...@@ -109,7 +94,7 @@ private void addPathToArtifact(BlackboardArtifact artifact, GeoTrackPoints point
* *
* @return GPS trackpoint artifact added * @return GPS trackpoint artifact added
* *
* @throws TskCoreException If there is an error creating the artifact. * @throws TskCoreException If there is an error creating the artifact.
* @throws BlackboardException If there is a problem posting the artifact. * @throws BlackboardException If there is a problem posting the artifact.
*/ */
public BlackboardArtifact addGPSTrackpoint(double latitude, double longitude, public BlackboardArtifact addGPSTrackpoint(double latitude, double longitude,
...@@ -135,7 +120,7 @@ public BlackboardArtifact addGPSTrackpoint(double latitude, double longitude, ...@@ -135,7 +120,7 @@ public BlackboardArtifact addGPSTrackpoint(double latitude, double longitude,
* *
* @return GPS trackpoint artifact added * @return GPS trackpoint artifact added
* *
* @throws TskCoreException If there is an error creating the artifact. * @throws TskCoreException If there is an error creating the artifact.
* @throws BlackboardException If there is a problem posting the artifact. * @throws BlackboardException If there is a problem posting the artifact.
*/ */
public BlackboardArtifact addGPSTrackpoint(double latitude, double longitude, long timeStamp, String name, String programName, public BlackboardArtifact addGPSTrackpoint(double latitude, double longitude, long timeStamp, String name, String programName,
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
*/ */
package org.sleuthkit.datamodel.blackboardutils.attributes; package org.sleuthkit.datamodel.blackboardutils.attributes;
import java.util.Collection; import com.google.gson.Gson;
import java.util.Collections; import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.sleuthkit.datamodel.blackboardutils.attributes.GeoWaypoint.GeoTrackPoint; import org.sleuthkit.datamodel.blackboardutils.attributes.GeoWaypoint.GeoTrackPoint;
/** /**
...@@ -29,35 +31,60 @@ ...@@ -29,35 +31,60 @@
*/ */
public final class GeoTrackPoints { public final class GeoTrackPoints {
private final Collection<GeoTrackPoint> points; private final List<GeoTrackPoint> points;
/** /**
* Constructs a new instance with the give list of GeoTrackPoints. * Deserialize the given list of GeoTrackPoints.
* *
* @param points * @param jsonString JSon string of track points.
*
* @return Timestamp ordered list of GeoTrackPoints, empty list will be
* returned if jsonString is null or empty.
*/
public static List<GeoTrackPoint> deserializePoints(String jsonString) {
if (jsonString == null || jsonString.isEmpty()) {
return new ArrayList<>();
}
return (new Gson()).fromJson(jsonString, GeoTrackPoints.class).getTimeOrderedPoints();
}
/**
* Serialize the given list of GeoTrackPoints.
*
* @param points List of GeoTrackPoints
*
* @return JSon formatted string is returned or empty string if points was
* null
*/ */
public GeoTrackPoints(Collection<GeoTrackPoint> points) { public static String serializePoints(List<GeoTrackPoint> points) {
if (points == null) { if (points == null) {
throw new IllegalArgumentException("Invalid list of track points passed to constructor"); return "";
} }
this.points = points;
Gson gson = new Gson();
return gson.toJson(new GeoTrackPoints(points));
} }
/** /**
* Return whether or not the points list is empty * Constructs a new instance with the give list of GeoTrackPoints.
* *
* @return True if list is empty. * @param points
*/ */
public boolean isEmpty() { private GeoTrackPoints(List<GeoTrackPoint> points) {
return points.isEmpty(); if (points == null) {
throw new IllegalArgumentException("Invalid list of track points passed to constructor");
}
this.points = points;
} }
/** /**
* Returns the list of track points. * Returns a timestamp ordered copy of the points list.
* *
* @return Unmodifiable collection of trackpoints. * @return timestamp
*/ */
public Collection<GeoTrackPoint> getPoints() { private List<GeoTrackPoint> getTimeOrderedPoints() {
return Collections.unmodifiableCollection(points); return points.stream().sorted().collect(Collectors.toCollection(ArrayList::new));
} }
} }
...@@ -82,7 +82,7 @@ public Double getAltitude() { ...@@ -82,7 +82,7 @@ public Double getAltitude() {
* point. * point.
* *
*/ */
public final static class GeoTrackPoint extends GeoWaypoint { public final static class GeoTrackPoint extends GeoWaypoint implements Comparable<GeoTrackPoint> {
@SerializedName("TSK_GEO_VELOCITY") @SerializedName("TSK_GEO_VELOCITY")
private final Double velocity; private final Double velocity;
...@@ -161,6 +161,19 @@ public Double getDistanceTraveled() { ...@@ -161,6 +161,19 @@ public Double getDistanceTraveled() {
public Long getTimeStamp() { public Long getTimeStamp() {
return timestamp; return timestamp;
} }
@Override
public int compareTo(GeoTrackPoint otherTP) {
Long otherTimeStamp = otherTP.getTimeStamp();
if (timestamp == null && otherTimeStamp != null) {
return -1;
} else if (timestamp != null && otherTimeStamp == null) {
return 1;
} else {
return timestamp.compareTo(otherTP.getTimeStamp());
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment