What's wrong with this AQL query in M2Doc template?

Hi all,
I created a hierarchy of Logical Functions, with property value groups defined with PVMT.
The extension is called la.SF, and I would like to sort them in the generated document by a property value named Id, with values like LF-00-01, LF-00-02, etc.

I use the AQL query

selection.eAllContents(la::LogicalFunction)->sortedBy(a | a.ownedPropertyValueGroups->select(b | b.name  = 'la.SF')->first().ownedPropertyValues->select(c | c.name = 'Id')->first().getValue())

but this query fails to sort the output of eAllContents.

Any suggestion?

Thanks in advance

The expression seems correct. You can test each part of the expression on one specific element to make sure. Maybe the value is not a String ? or at some point you have a collection (but with the ->first() that should not be the case). You can check the type of different parts of the expression.

Sequence{'LF-02-03', 'LF-02-01', 'LF-02-02', 'LF-00-03', 'LF-00-01', 'LF-00-02', 'LF-01-03', 'LF-01-01', 'LF-01-02', 'LF-03-03', 'LF-03-01', 'LF-03-02'}->sortedBy(v | v)

Sorts values as expected.

Maybe some of the LogicalFunction don’t have this property setted and should not be part of the initial selection ?

Hi Yvan,

this is the “unsorted” dump

selection.ownedPropertyValueGroups->select(a | a.name = 'la.SF').ownedPropertyValues->select(b | b.name = 'Id').getValue()

image

And this is the sorted (or supposed sorted) dump

selection.eAllContents(la::LogicalFunction)->sortedBy(a | (a.ownedPropertyValueGroups->select(b | b.name .equals('la.SF'))
->first().ownedPropertyValues->select(c | c.name.equals('Id'))
->first().getValue()))
.ownedPropertyValueGroups->select(a | a.name = 'la.SF').ownedPropertyValues->select(b | b.name = 'Id').getValue()

image

The output remains the same, suggesting that the lambda expression provided to the query might not be properly evaluated. Should I consider grouping certain parts of the expression with parentheses for proper execution?

Pier Giorgio

I think the .getValue() might not return a String. Can you try in the sort:

.getValue().toString()

Just to make sure…

Added toString().

… no changes.

I’m not really sure why but the result of:

a.ownedPropertyValueGroups->select(b | b.name  = 'la.SF')->first().ownedPropertyValues->select(c | c.name = 'Id')->first().getValue()

Doesn’t seem to be a String but maybe a collection… even if it should not ? I will need to debug that… But as a workaround you can use ->toString() it will convert the all collection (?) to a String:

selection.eAllContents(la::LogicalFunction)->sortedBy(a | a.ownedPropertyValueGroups->select(b | b.name  = 'la.SF')->first().ownedPropertyValues->select(c | c.name = 'Id')->first().getValue()->toString()).ownedPropertyValueGroups->select(a | a.name = 'la.SF').ownedPropertyValues->select(b | b.name = 'Id').getValue()

AQL flatten collections to prevent collections of collections but maybe in this case at least one flatten didn’t work.

Hi Yvan,
I’m quite confused about the behavior of the query.
I changed a bit the query using any instead of select. I got different results from M2Doc and Sirius interpreters

AQL query:

aql:self.eAllContents(la::LogicalFunction)->sortedBy(lf | lf.appliedPropertyValueGroups.ownedPropertyValues->any(pv | pv.name ='Id').value).appliedPropertyValueGroups.ownedPropertyValues->select(a | a.name = 'Id').value

elements correctly sorted

image

M2Doc query

selection.eAllContents(la::LogicalFunction)->sortedBy(lf | lf.appliedPropertyValueGroups.ownedPropertyValues->any(pv | pv.name ='Id').getValue()).appliedPropertyValueGroups.ownedPropertyValues->select(a | a.name = 'Id').getValue()

elements not sorted
image

I think the getValue() could be the one returning a Collection instead of a String. The feature access value returns a String. So the first expression should be used or the second one with addition of ->toString() to convert the Collection to a String that can be sorted.

1 Like

It worked!

selection.eAllContents(la::LogicalFunction)->sortedBy(lf | lf.appliedPropertyValueGroups.ownedPropertyValues->any(pv | pv.name ='Id').getValue()->toString()).appliedPropertyValueGroups.ownedPropertyValues->select(a | a.name = 'Id').getValue()

image

Thank you so much for your invaluable assistance.

Pier Giorgio

1 Like