Hello all,
I have encountered following observation related o OCL/AQL
My goal was to simply create a result accumulated over the Collection.
In JS one can use reduce in Arrays, or join on Arrays/String to create accumulated value
For a demo purpose just using simple example ( emulate join(delim) in OCL/AQL)
Sequence of strings -> single string
Now I have played around with the OCL statements inside of the OCL console and compare the evaluation results for derived profile properties ( OCL/AQL)
let source:Sequence(String)=Sequence{'a','bcd','h'}
in
source->asSet()->iterate(curr:String;acc:String=''| acc+curr+'('+source->indexOf(curr).toString()+'),')
OCL Console:
>>'a(1),bcd(2),h(3),'
OCL Derived Property:
>>Status ERROR: de.ikv.medini.evaluation.engine.mdtocl code=4 Can not evaluate script java.lang.NullPointerException: Cannot invoke "java.lang.Class.getMethod(String, java.lang.Class[])" because "containerClass" is null
AQL Derived Property:
>>false
for some reason the OCL property has some issues with usage source->indexOf(..) and AQL does not return anything at all instead it returns bollean false
Another use case could be that one would want to limit the precision of number in a derived property.
So lets try to do this using toString().tokenize('.') some native supported methods
let proc:Sequence(String)=10.253215151515151.toString().tokenize('.'),
places:Integer=3
in
proc->first()+'.'+proc->last().substring(1,if proc->last().size() > places then Sequence{1,places}->max() else proc->last().size() endif )
OCL Concosle:
>> 10.235
OLC property:
>>10.253
AQL (reqriting neeed due to missing ->max() service, using AQL's number.max(number)
proc->first()+'.'+proc->last().substring(1,if proc->last().size() > places then 1,max(places) else proc->last().size() endif )
>>10.253PS: for AQL the code needed to be rewritten, because the Collection->max() does no exists in AQL (available number.max(number)
My questions:
- Any idea why the there was a Error raised in OCL property linked to the source->indexOf(), can you confirm you can see the same ?
- Is there any other alternative in AQL to OCL's ->iterate()
- Would it be possible to extend the Collection by ->iterate()service?
( I think only for AQL evaluation engine used in profile properties/AQL evaluations inside of scripts
I think the iterate can be useful when it comes to accumulating some result out of Collection( string, number ,... )
PS2: All tested on 25R1
Thanks,
Marian