Skip to content

Commit

Permalink
Set up latest position of device after import
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalidze committed Feb 16, 2015
1 parent 4e18b74 commit ee82e49
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/traccar/web/server/model/ImportServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void gpx(Device device, InputStream inputStream, HttpServletResponse response) t

List<Position> parsedPositions = new LinkedList<Position>();
Position position = null;
Position latestPosition = null;

response.getWriter().println("<pre>");

Expand Down Expand Up @@ -155,6 +156,9 @@ void gpx(Device device, InputStream inputStream, HttpServletResponse response) t
xsr.getLocalName().equalsIgnoreCase("trkpt")) {

parsedPositions.add(position);
if (latestPosition == null || position.getTime().compareTo(position.getTime()) < 0) {
latestPosition = position;
}
position = null;
}
}
Expand Down Expand Up @@ -196,6 +200,10 @@ void gpx(Device device, InputStream inputStream, HttpServletResponse response) t
}
}

if (latestPosition != null && device.getLatestPosition() == null || device.getLatestPosition().getTime().compareTo(latestPosition.getTime()) < 0) {
device.setLatestPosition(latestPosition);
}

response.getWriter().println("Already exist: " + (parsedPositions.size() - imported));
response.getWriter().println("Imported: " + imported);

Expand Down

0 comments on commit ee82e49

Please sign in to comment.