aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-08-03 10:05:40 +0500
committerAbyss777 <abyss@fox5.ru>2016-08-04 16:33:34 +0500
commita5c431069ca0dfe8240f0c8b43f0508189f8fc86 (patch)
treed3de1b83fbb8ec487a1e6cbef5cb13f2941c2868 /src/org/traccar/web
parent41668cae9763a523c775a8a998620fe286176c9e (diff)
downloadtraccar-server-a5c431069ca0dfe8240f0c8b43f0508189f8fc86.tar.gz
traccar-server-a5c431069ca0dfe8240f0c8b43f0508189f8fc86.tar.bz2
traccar-server-a5c431069ca0dfe8240f0c8b43f0508189f8fc86.zip
- Added getGroupDevices to PermissionsManager
- Implemented Route Report
Diffstat (limited to 'src/org/traccar/web')
-rw-r--r--src/org/traccar/web/CsvBuilder.java150
-rw-r--r--src/org/traccar/web/WebServer.java3
2 files changed, 152 insertions, 1 deletions
diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java
new file mode 100644
index 000000000..cfebec3b4
--- /dev/null
+++ b/src/org/traccar/web/CsvBuilder.java
@@ -0,0 +1,150 @@
+package org.traccar.web;
+
+import java.beans.Introspector;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+import org.traccar.helper.Log;
+import org.traccar.model.MiscFormatter;
+
+public class CsvBuilder {
+
+ private static final String LINE_ENDING = "\r\n";
+ private static final String SEPARATOR = ";";
+ private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime();
+
+ private StringBuilder builder = new StringBuilder();
+
+ private void addLineEnding() {
+ builder.append(LINE_ENDING);
+ }
+ private void addSeparator() {
+ builder.append(SEPARATOR);
+ }
+ public void addLine(String value) {
+ if (value != null) {
+ builder.append(value);
+ }
+ addLineEnding();
+ }
+
+ public void addLine(long value) {
+ builder.append(value);
+ addLineEnding();
+ }
+
+ public void addLine(double value) {
+ builder.append(value);
+ addLineEnding();
+ }
+
+ public void addLine(boolean value) {
+ builder.append(value);
+ addLineEnding();
+ }
+
+ public void addField(String value) {
+ builder.append(value);
+ addSeparator();
+ }
+
+ public void addField(long value) {
+ builder.append(value);
+ addSeparator();
+ }
+
+ public void addField(int value) {
+ builder.append(value);
+ addSeparator();
+ }
+
+ public void addField(double value) {
+ builder.append(value);
+ addSeparator();
+ }
+
+ public void addField(boolean value) {
+ builder.append(value);
+ addSeparator();
+ }
+
+ public void addLine(Object object) {
+
+ Method[] methods = object.getClass().getMethods();
+
+ for (Method method : methods) {
+ if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
+ try {
+ if (method.getReturnType().equals(boolean.class)) {
+ addField((Boolean) method.invoke(object));
+ } else if (method.getReturnType().equals(int.class)) {
+ addField((Integer) method.invoke(object));
+ } else if (method.getReturnType().equals(long.class)) {
+ addField((Long) method.invoke(object));
+ } else if (method.getReturnType().equals(double.class)) {
+ addField((Double) method.invoke(object));
+ } else if (method.getReturnType().equals(String.class)) {
+ addField((String) method.invoke(object));
+ } else if (method.getReturnType().equals(Date.class)) {
+ Date value = (Date) method.invoke(object);
+ addField(DATE_FORMAT.print(new DateTime(value)));
+ } else if (method.getReturnType().equals(Map.class)) {
+ Map value = (Map) method.invoke(object);
+ if (value != null) {
+ addField(MiscFormatter.toJson(value).toString());
+ }
+ }
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ Log.warning(error);
+ }
+ }
+ }
+ addLineEnding();
+ }
+
+ public void addHeaderLine(Object object) {
+ Method[] methods = object.getClass().getMethods();
+
+ for (Method method : methods) {
+ if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
+ String name = Introspector.decapitalize(method.getName().substring(3));
+ if (!name.equals("class")) {
+ addField(name);
+ }
+ }
+ }
+ addLineEnding();
+ }
+
+ public void addArray(Collection<?> array) {
+ for (Object object : array) {
+ switch (object.getClass().getSimpleName().toLowerCase()) {
+ case "string":
+ addLine(object.toString());
+ break;
+ case "long":
+ addLine((long) object);
+ break;
+ case "double":
+ addLine((double) object);
+ break;
+ case "boolean":
+ addLine((boolean) object);
+ break;
+ default:
+ addLine(object);
+ break;
+ }
+ }
+ }
+
+ public byte[] get() {
+ return String.valueOf(builder).getBytes();
+ }
+}
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index 4ef31b1df..e022a9285 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -44,6 +44,7 @@ import org.traccar.api.resource.GroupResource;
import org.traccar.api.resource.NotificationResource;
import org.traccar.api.resource.DeviceResource;
import org.traccar.api.resource.PositionResource;
+import org.traccar.api.resource.ReportResource;
import org.traccar.api.resource.CommandTypeResource;
import org.traccar.api.resource.DeviceGeofenceResource;
import org.traccar.api.resource.EventResource;
@@ -160,7 +161,7 @@ public class WebServer {
GroupResource.class, DeviceResource.class, PositionResource.class,
CommandTypeResource.class, EventResource.class, GeofenceResource.class,
DeviceGeofenceResource.class, GeofencePermissionResource.class, GroupGeofenceResource.class,
- NotificationResource.class);
+ NotificationResource.class, ReportResource.class);
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);