Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Route.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2019-2020 Basis Technology Corp.
6  * contact: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.geolocation.datamodel;
21 
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import org.openide.util.NbBundle.Messages;
27 import org.sleuthkit.datamodel.BlackboardArtifact;
28 import org.sleuthkit.datamodel.BlackboardAttribute;
29 import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil;
30 import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil.InvalidJsonException;
31 import org.sleuthkit.datamodel.blackboardutils.attributes.GeoWaypoints;
32 
39 public class Route extends GeoPath {
40 
41  private final Long timestamp;
42 
43  // This list is not expected to change after construction so the
44  // constructor will take care of creating an unmodifiable List
45  private final List<Waypoint.Property> propertiesList;
46 
52  @Messages({
53  // This is the original static hardcoded label from the
54  // original kml-report code
55  "Route_Label=As-the-crow-flies Route"
56  })
57  Route(BlackboardArtifact artifact) throws GeoLocationDataException {
58  super(artifact, Bundle.Route_Label());
59 
60  Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap = Waypoint.getAttributesFromArtifactAsMap(artifact);
61 
62  BlackboardAttribute attribute = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
63  timestamp = attribute != null ? attribute.getValueLong() : null;
64 
65  propertiesList = Waypoint.createGeolocationProperties(attributeMap);
66 
67  createRoute(artifact, attributeMap);
68  }
69 
75  public List<Waypoint> getRoute() {
76  return getPath();
77  }
78 
86  return Collections.unmodifiableList(propertiesList);
87  }
88 
94  public Long getTimestamp() {
95  return timestamp;
96  }
97 
107  @Messages({
108  "Route_point_label=Waypoints for route"
109  })
110  private void createRoute(BlackboardArtifact artifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap) throws GeoLocationDataException {
111  BlackboardAttribute attribute = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_WAYPOINTS);
112 
113  String label = getLabel();
114  if (label == null || label.isEmpty()) {
115  label = Bundle.Route_point_label();
116  } else {
117  label = String.format("%s: %s", Bundle.Route_point_label(), label);
118  }
119 
120  if (attribute != null) {
121  GeoWaypoints waypoints;
122  try {
123  waypoints = BlackboardJsonAttrUtil.fromAttribute(attribute, GeoWaypoints.class);
124  } catch (InvalidJsonException ex) {
125  throw new GeoLocationDataException(String.format("Unable to parse waypoints in TSK_GEO_WAYPOINTS attribute (artifact object ID =%d)", artifact.getId()), ex);
126  }
127  for (GeoWaypoints.Waypoint waypoint : waypoints) {
128  String name = waypoint.getName();
129  Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> map = attributeMap;
130  if(name != null && !name.isEmpty()) {
131  BlackboardAttribute pointNameAtt = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, "", name);
132  map = new HashMap<>(attributeMap);
133  map.put(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, pointNameAtt);
134  }
135  addToPath(new Waypoint(artifact, label, timestamp, waypoint.getLatitude(), waypoint.getLongitude(), waypoint.getAltitude(), null, map, this));
136  }
137  } else {
138  Waypoint start = getRouteStartPoint(artifact, attributeMap);
139  Waypoint end = getRouteEndPoint(artifact, attributeMap);
140 
141  addToPath(start);
142  addToPath(end);
143  }
144  }
145 
158  @Messages({
159  "Route_Start_Label=Start"
160  })
161 
162  private Waypoint getRouteStartPoint(BlackboardArtifact artifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap) throws GeoLocationDataException {
163  BlackboardAttribute latitude = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START);
164  BlackboardAttribute longitude = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START);
165  BlackboardAttribute altitude = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_ALTITUDE);
166 
167  if (latitude != null && longitude != null) {
168  return new Waypoint(artifact,
169  Bundle.Route_Start_Label(),
170  timestamp,
171  latitude.getValueDouble(),
172  longitude.getValueDouble(),
173  altitude != null ? altitude.getValueDouble() : null,
174  null,
175  attributeMap, this);
176  } else {
177  throw new GeoLocationDataException("Unable to create route start point, invalid longitude and/or latitude");
178  }
179  }
180 
193  @Messages({
194  "Route_End_Label=End"
195  })
196  private Waypoint getRouteEndPoint(BlackboardArtifact artifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap) throws GeoLocationDataException {
197  BlackboardAttribute latitude = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END);
198  BlackboardAttribute longitude = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END);
199  BlackboardAttribute altitude = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_ALTITUDE);
200 
201  if (latitude != null && longitude != null) {
202 
203  return new Waypoint(artifact,
204  Bundle.Route_End_Label(),
205  timestamp,
206  latitude.getValueDouble(),
207  longitude.getValueDouble(),
208  altitude != null ? altitude.getValueDouble() : null,
209  null,
210  attributeMap,
211  this);
212  } else {
213  throw new GeoLocationDataException("Unable to create route end point, invalid longitude and/or latitude");
214  }
215  }
216 }
Waypoint getRouteEndPoint(BlackboardArtifact artifact, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attributeMap)
Definition: Route.java:196
final List< Waypoint.Property > propertiesList
Definition: Route.java:45
List< Waypoint.Property > getOtherProperties()
Definition: Route.java:85
void createRoute(BlackboardArtifact artifact, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attributeMap)
Definition: Route.java:110
Waypoint getRouteStartPoint(BlackboardArtifact artifact, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attributeMap)
Definition: Route.java:162

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