From f6d9014c9a05cce42678515d941af52c1c2584a5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 1 May 2015 21:22:35 +1200 Subject: Add device update and remove --- src/org/traccar/http/DeviceServlet.java | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/org/traccar/http') 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()); } } -- cgit v1.2.3