aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/processing
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-05-18 13:57:29 +0500
committerAbyss777 <abyss@fox5.ru>2017-05-18 13:57:29 +0500
commit660828e48ac0657e9673c1d7647131ffa9d9c963 (patch)
treecf32d32f2c2e40572beeefdbd8f196784970537c /src/org/traccar/processing
parentee66c9239381168b36eaa68cd1e962e4034a81f2 (diff)
downloadtrackermap-server-660828e48ac0657e9673c1d7647131ffa9d9c963.tar.gz
trackermap-server-660828e48ac0657e9673c1d7647131ffa9d9c963.tar.bz2
trackermap-server-660828e48ac0657e9673c1d7647131ffa9d9c963.zip
Unwrap position fields and attributes to computedAttribute context.
Diffstat (limited to 'src/org/traccar/processing')
-rw-r--r--src/org/traccar/processing/ComputedAttributesHandler.java31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/org/traccar/processing/ComputedAttributesHandler.java b/src/org/traccar/processing/ComputedAttributesHandler.java
index ea7c0aa1d..b158431ef 100644
--- a/src/org/traccar/processing/ComputedAttributesHandler.java
+++ b/src/org/traccar/processing/ComputedAttributesHandler.java
@@ -16,7 +16,10 @@
*/
package org.traccar.processing;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Collection;
+import java.util.Map;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.JexlException;
@@ -36,10 +39,32 @@ public class ComputedAttributesHandler extends BaseDataHandler {
engine.setStrict(true);
}
+ private MapContext prepareContext(Position position) {
+ MapContext result = new MapContext();
+ Method[] methods = position.getClass().getMethods();
+ for (Method method : methods) {
+ if (method.getName().startsWith("get") && method.getParameterTypes().length == 0
+ && !method.getName().equals("getClass")) {
+ String name = method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4);
+
+ try {
+ if (!method.getReturnType().equals(Map.class)) {
+ result.set(name, method.invoke(position));
+ } else {
+ for (Object key : ((Map) method.invoke(position)).keySet()) {
+ result.set((String) key, ((Map) method.invoke(position)).get(key));
+ }
+ }
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ Log.warning(error);
+ }
+ }
+ }
+ return result;
+ }
+
public Object computeAttribute(Attribute attribute, Position position) throws JexlException {
- MapContext expressionContext = new MapContext();
- expressionContext.set("position", position);
- return engine.createExpression(attribute.getExpression()).evaluate(expressionContext);
+ return engine.createExpression(attribute.getExpression()).evaluate(prepareContext(position));
}
@Override