diff options
author | memesaregood1 <sifepe4679@yandex.ru> | 2023-02-22 22:46:50 +0300 |
---|---|---|
committer | memesaregood1 <sifepe4679@yandex.ru> | 2023-02-22 22:46:50 +0300 |
commit | 0fe0344a64b142ef4492ff6ad3c1f8590d336ab0 (patch) | |
tree | 6d78812cd1339daa02dbfe6dd51d8b21be9cc57d /src/main/java/org | |
parent | 9deca13ced10ef8a6df164831dd60ed4089a25a6 (diff) | |
download | trackermap-server-0fe0344a64b142ef4492ff6ad3c1f8590d336ab0.tar.gz trackermap-server-0fe0344a64b142ef4492ff6ad3c1f8590d336ab0.tar.bz2 trackermap-server-0fe0344a64b142ef4492ff6ad3c1f8590d336ab0.zip |
Alternative features activation way
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 8 | ||||
-rw-r--r-- | src/main/java/org/traccar/handler/ComputedAttributesHandler.java | 7 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 6aa41f85b..d3bba9ae7 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1299,21 +1299,21 @@ public final class Keys { public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES = new BooleanConfigKey( "processing.computedAttributes.deviceAttributes", List.of(KeyType.CONFIG)); - + /** * Enable local variables declaration. */ public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES = new BooleanConfigKey( "processing.computedAttributes.localVariables", List.of(KeyType.CONFIG)); - + /** * Enable loops processing. */ public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_LOOPS = new BooleanConfigKey( "processing.computedAttributes.loops", List.of(KeyType.CONFIG)); - + /** * Enable new instances creation. * When disabled, parsing a script/expression using 'new(...)' will throw a parsing exception; @@ -1321,7 +1321,7 @@ public final class Keys { public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION = new BooleanConfigKey( "processing.computedAttributes.newInstanceCreation", List.of(KeyType.CONFIG)); - + /** * Boolean flag to enable or disable reverse geocoder. */ diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index 73b549195..2964d81d7 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -55,6 +55,8 @@ public class ComputedAttributesHandler extends BaseDataHandler { private final JexlEngine engine; + private final JexlFeatures features; + private final boolean includeDeviceAttributes; @Inject @@ -62,7 +64,7 @@ public class ComputedAttributesHandler extends BaseDataHandler { this.cacheManager = cacheManager; JexlSandbox sandbox = new JexlSandbox(false); sandbox.allow("com.safe.Functions"); - JexlFeatures features = new JexlFeatures() + features = new JexlFeatures() .localVar(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES)) .loops(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOOPS)) .newInstance(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION)) @@ -71,7 +73,6 @@ public class ComputedAttributesHandler extends BaseDataHandler { .strict(true) .namespaces(Collections.singletonMap("math", Math.class)) .sandbox(sandbox) - .features(features) .create(); includeDeviceAttributes = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES); } @@ -113,7 +114,7 @@ public class ComputedAttributesHandler extends BaseDataHandler { */ @Deprecated public Object computeAttribute(Attribute attribute, Position position) throws JexlException { - return engine.createExpression(attribute.getExpression()).evaluate(prepareContext(position)); + return engine.createScript(features, engine.createInfo(), attribute.getExpression()).execute(prepareContext(position)); } @Override |