1
votes

I'm new to ATL and OCL and I'm trying to transform this metamodel: enter image description here

into this one: enter image description here

The helper is meant to take all the tests created by the user admin and after that sum the id's of the Actions of that test.
I've done this helper:

helper def: actionsId: Integer = Test!Test.allInstances()->select(i | i.md.user='admin')->collect(n | n.act.id.toInteger())->sum();

But when I run the transformation I'm having this error:

org.eclipse.m2m.atl.engine.emfvm.VMException: Collections do not have properties, use ->collect()

This error is in the collect(n | n.act.id.toInteger()) part of the helper.

The rest of my code is this:

rule Testset2Testcase{
    from s: Test!Test
    to r: Testcase!Testcase(
        ident <- thisModule.actionId.toString(),
        date <- s.md.date,
        act <- thisModule.resolveTemp(s.act,'a')
    )
    do{
        'Bukatuta'.println();   
    }
}

rule Action2Activity{
    from s: Test!Action
    to a: Testcase!Activity(
        ident <- s.id   
    )
}

Sorry for my bad english.

2
are You read 'atl' tag description?Jacek Cz
I've read it now, sorry I thought it was about the ATL transformation language. I'll change it.Mikel Molinuevo

2 Answers

1
votes

My teacher helped me with this.
The problem was in the helper.
Doing this:

helper def: actionsId: Integer = Test!Test.allInstances()->select(i | i.md.user='admin')->collect(n | n.act.id.toInteger())->sum();

I was trying to take the id of a collection of collections of the type Action instead of taking the id of each objects.

With that helper I was taking a collection of collections so using flattener this collection of collections became a collection of Actions.

The helper written in a correct way looks like this:

helper def: actionsId: Integer = Test!Test.allInstances()->select(i | i.md.user='admin')->collect(n | n.act)->flatten()->collect(x | x.id.toInteger())->sum();
0
votes

Your expression looks plausible, but without your metamodel it is difficult to see where ATL is unhappy about use of a Collection property. If Test::md is a collection, the expression would just be stupid, though not for the reason given.

If ATL's hovertext doesn't help you understand your types, you might enter the same expression into the OCL Xtext Console and carefully hover over "." and "md" to get its accurate type analysis.

But beware, ATL has an independently developed embedded OCL that is not as rich as Eclipse OCL. Perhaps your expression is too complex for ATL; try breaking it up with let's.