aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-01 21:22:35 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-01 21:22:35 +1200
commitf6d9014c9a05cce42678515d941af52c1c2584a5 (patch)
treec8e8366d73832a72523ba7454cfcfc53a5cdaf58
parent49c0907a74cb1dc7dd0351dfbb1c16e7822e696f (diff)
downloadtrackermap-server-f6d9014c9a05cce42678515d941af52c1c2584a5.tar.gz
trackermap-server-f6d9014c9a05cce42678515d941af52c1c2584a5.tar.bz2
trackermap-server-f6d9014c9a05cce42678515d941af52c1c2584a5.zip
Add device update and remove
-rw-r--r--src/org/traccar/http/DeviceServlet.java42
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());
}
}