JEXL deviceTime to milliseconds not working any more

Victor Butler8 months ago

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?

Victor Butler8 months ago

Any suggestions?

Anton Tananaev8 months ago

Have you tried just .time? Just guessing here.

Victor Butler8 months ago

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.

Victor Butler8 months ago

Any other ideas how to parse the date string? Or where to look for the updated JEXL syntax?

Victor Butler8 months ago

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;

Victor Butler8 months ago

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

However
serverTime.substring(2) does not return anything

For that I have no explanation....

Anton Tananaev8 months ago

Time is not a string. In JSON it is a string, but on the server side it's a Date object.

Victor Butler8 months ago

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?

Anton Tananaev8 months ago

It might be related to this change:

https://github.com/traccar/traccar/pull/5036

Victor Butler8 months ago

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

Anton Tananaev8 months ago

Probably.

Victor Butler8 months ago

Thanks, will test and update.

Victor Butler7 months ago

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?

Anton Tananaev7 months ago

Unfortunately this is not something I can help with on the forum.