diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-01 21:22:35 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-01 21:22:35 +1200 |
commit | f6d9014c9a05cce42678515d941af52c1c2584a5 (patch) | |
tree | c8e8366d73832a72523ba7454cfcfc53a5cdaf58 /src/org/traccar/http | |
parent | 49c0907a74cb1dc7dd0351dfbb1c16e7822e696f (diff) | |
download | trackermap-server-f6d9014c9a05cce42678515d941af52c1c2584a5.tar.gz trackermap-server-f6d9014c9a05cce42678515d941af52c1c2584a5.tar.bz2 trackermap-server-f6d9014c9a05cce42678515d941af52c1c2584a5.zip |
Add device update and remove
Diffstat (limited to 'src/org/traccar/http')
-rw-r--r-- | src/org/traccar/http/DeviceServlet.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/org/traccar/http/DeviceServlet.java b/src/org/traccar/http/DeviceServlet.java index 5cda5708e..64f7836a4 100644 --- a/src/org/traccar/http/DeviceServlet.java +++ b/src/org/traccar/http/DeviceServlet.java @@ -97,9 +97,51 @@ public class DeviceServlet extends HttpServlet { } private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException { + + JsonReader jsonReader = Json.createReader(req.getReader()); + JsonObject jsonObject = jsonReader.readObject(); + Device device = new Device(); + try { + device.fromJson(jsonObject); + } catch (ParseException error) { + Log.warning(error); + } + + JsonObjectBuilder result = Json.createObjectBuilder(); + + try { + result.add("success", true); + Context.getDataManager().updateDevice(device); + } catch(SQLException error) { + result.add("success", false); + result.add("error", error.getMessage()); + } + + resp.getWriter().println(result.build().toString()); } private void remove(HttpServletRequest req, HttpServletResponse resp) throws IOException { + + JsonReader jsonReader = Json.createReader(req.getReader()); + JsonObject jsonObject = jsonReader.readObject(); + Device device = new Device(); + try { + device.fromJson(jsonObject); + } catch (ParseException error) { + Log.warning(error); + } + + JsonObjectBuilder result = Json.createObjectBuilder(); + + try { + result.add("success", true); + Context.getDataManager().removeDevice(device); + } catch(SQLException error) { + result.add("success", false); + result.add("error", error.getMessage()); + } + + resp.getWriter().println(result.build().toString()); } } |