diff options
author | nativbarak <nativ@globekeeper.com> | 2018-02-05 10:59:55 +0200 |
---|---|---|
committer | nativbarak <nativ@globekeeper.com> | 2018-02-05 10:59:55 +0200 |
commit | 00b1715aa854f62b2cc90753c05d558cea9dd6ea (patch) | |
tree | b3a241bd154915af8ede4db9067ae892e157e5a4 /src/org/traccar | |
parent | 6ae8a397c29a3d7a16d9cf481e2141e3e70921fd (diff) | |
download | trackermap-server-00b1715aa854f62b2cc90753c05d558cea9dd6ea.tar.gz trackermap-server-00b1715aa854f62b2cc90753c05d558cea9dd6ea.tar.bz2 trackermap-server-00b1715aa854f62b2cc90753c05d558cea9dd6ea.zip |
changed POST to use full object
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/WebDataHandler.java | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java index a30a41208..e45a47835 100644 --- a/src/org/traccar/WebDataHandler.java +++ b/src/org/traccar/WebDataHandler.java @@ -37,6 +37,8 @@ public class WebDataHandler extends BaseDataHandler { private final String url; private final Boolean json; + private static final String KEY_POSITION = "position"; + private static final String KEY_DEVICE = "device"; public WebDataHandler(String url, Boolean json) { this.url = url; @@ -153,39 +155,20 @@ public class WebDataHandler extends BaseDataHandler { protected String prepareJsonPayload(Position position) { Map<String, Object> data = new HashMap<>(); - Device device = Context.getIdentityManager().getById(position.getDeviceId()); - - data.put("name", device.getName()); - data.put("uniqueId", device.getUniqueId()); - data.put("status", device.getStatus()); - data.put("deviceId", String.valueOf(position.getDeviceId())); - data.put("protocol", String.valueOf(position.getProtocol())); - data.put("deviceTime", String.valueOf(position.getDeviceTime().getTime())); - data.put("fixTime", String.valueOf(position.getFixTime().getTime())); - data.put("valid", String.valueOf(position.getValid())); - data.put("latitude", String.valueOf(position.getLatitude())); - data.put("longitude", String.valueOf(position.getLongitude())); - data.put("speed", String.valueOf(position.getSpeed())); - data.put("course", String.valueOf(position.getCourse())); - data.put("statusCode", calculateStatus(position)); - if (position.getAddress() != null) { - try { - data.put("address", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name())); - } catch (UnsupportedEncodingException error) { - Log.warning(error); - } + if (position != null) { + data.put(KEY_POSITION, position); } - try { - String attributes = Context.getObjectMapper().writeValueAsString(position.getAttributes()); - - data.put("attributes", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name())); - } catch (UnsupportedEncodingException | JsonProcessingException error) { - Log.warning(error); + if (position.getDeviceId() != 0) { + Device device = Context.getIdentityManager().getById(position.getDeviceId()); + if (device != null) { + data.put(KEY_DEVICE, device); + } } try { + System.out.println(Context.getObjectMapper().writeValueAsString(data).toString()); return Context.getObjectMapper().writeValueAsString(data); } catch (JsonProcessingException e) { Log.warning(e); |