Any suggestions?
Have you tried just .time
? Just guessing here.
serverTime.time
:
org.traccar.handler.ComputedAttributesHandler.computeAttribute:142@1:15 undefined property 'time' - Property (ComputedAttributesHandler:143 < AttributeResource:63 < ... < OverrideFilter:49 < ...)
serverTime.time()
: Nothing is returned.
Any other ideas how to parse the date string? Or where to look for the updated JEXL syntax?
Is it possible that some computedAttributes
congifuration needs to be enabled?
The only ones described in the Configuration section are those, but none of them seem related:
processing.computedAttributes.lastAttributes
Include last position attributes in the computed attribute context.
processing.computedAttributes.localVariables
Enable local variables declaration.
processing.computedAttributes.loops
Enable loops processing.
processing.computedAttributes.newInstanceCreation
Enable new instances creation. When disabled, parsing a script/expression using 'new(...)' will throw a parsing exception;
Further into testing:
In positions I have:"protocol": "teltonika",
"serverTime": "2024-04-26T09:23:59.000+00:00",
Both protocol
and serverTime
appear to be strings.
Then I do a test:protocol.substring(2)
returns ltonika
HoweverserverTime.substring(2)
does not return anything
For that I have no explanation....
Time is not a string. In JSON it is a string, but on the server side it's a Date
object.
If it's a date object, one of these should work but they don't:
serverTime.getInstance().getTime()
serverTime.getInstance().toString()
What are we missing?
It might be related to this change:
Yes I've seen that and I also saw only a few of those were implemented, which is probably the root cause.
Can this be the one we need:
processing.computedAttributes.parser.method_calls
- if this is disabled, using obj.samplemethod() would result in an exception
Probably.
Thanks, will test and update.
So I tested by adding the method call code, enabled it in the traccar.xml
, server restarted and still nothing:
Code added in a similar fashion to this commit:
https://github.com/traccar/traccar/commit/8acc8f0eb2fec2e9b079950ebad835f027fe3f9c
In src/main/java/org/traccar/config/Keys.java
, I added this:
public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_METHOD_CALLS = new BooleanConfigKey(
"processing.computedAttributes.method_calls",
List.of(KeyType.CONFIG));
In src/main/java/org/traccar/handler/ComputedAttributesHandler.java
, I edited this:
features = new JexlFeatures()
.localVar(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES))
.loops(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOOPS))
.methodCall(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_METHOD_CALLS)) //<-----The new line
.newInstance(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION))
.structuredLiteral(true);
traccar.xml
enabled :<entry key='processing.computedAttributes.method_calls'>true</entry>
Any ideas of what I might be missing?
Unfortunately this is not something I can help with on the forum.
deviceTime.getTime()
used to give us the time in milliseconds in computed attributes.It seems after the JEXL upgrade this no longer works.
Anyone knows what is the proper way to parse the deviceTime now?