Requirements, Relation Type display with M2Doc

Hi all !

I have a little problem here that I can’t seem to find an answer online or with colleagues.
I am basically trying to display different requirements from my model and how they are assessed. (satisfied) This is my code:

I can display the requirements names without a problem but in order to catch the element that resolves this requirement, I have to use the relation type ‘Satisfied By’ and look at the target of this latter.

The problem being, when I do that on the interpreter of Capella it works perfectly, but using M2doc seems to be problematic, as it sees all the elements as Abstract Relations which don’t have the “target” attribute. (I also made a special case for if the element solving the requirement was a functional chain as they don’t have a “name”).

I also had a problem with the links connected to constraints as those also don’t have the features name and target…

Did someone already tried to do that and achieve it ?

Thank you so much in advance for your help!
Best regards,

Not sure, but I think you need to cast to the specific type defining the target and name features.

You can find this specific type by selecting the Rela element from your example in the interpreter view and ask for its EClass:


and get its EPackage name:


Then you can filter on the specific type:

rep.ownedRelations->filter(<package name>::<specific class name>)

Let me know if it solve your issue.

Hi ! Thanks for your answer.
Unfortunately, I couldn’t solve my issue with this method. Maybe I got it wrong but it didn’t work to filter by class and package. Also, the target i’m looking at can be anything (DataLink, functionnal chain, System function, …) so if you meant to look for 1 type of target, I don’t know if it feasible… ?

Here is the updated code with the errors linked to it.
Thank you again so much for your help !

Errors requirements 2

The first probleme is Req.ownedRelations returns a list of AbstractRelation and this class is abstract (you can have instance of it in your model, only instances of its sub EClasses). It doesn’t contains the target feature. You need to find the sub EClass containing the target feature. You can do this by asking the EClass of the variable Rela:


Then you can filter Req.ownedRelations with this type and you will be able to access the feature target:

Req.ownedRelations->filter(<EClass from above query>)

The second point for the name feature, you can call an EOperation getLabel() on elements form the Capella metamodel:


It should return something readable by an human. An other solution is to cast as a AbstractNamedElement and use the feature name:


Note, this will only work if someExpression returns instances of AbstractNamedElement.

Hi ! Thanks again for your help, the issue is finally solved.
I managed it by selecting elements which returned .ownedAttributes -> size() <> 0 and then filtering on CapellaIncomingRelation. Then it worked. (also, I got rid of the Functional Chain possibilities, as they are quite problematic, they don’t work with .name nor with getLabel, the only way to fetch smtg from them is to look for their target’s names. So i just did not look into them. :smiley: )

I post the solution that made it work under this post.

Thank you again for your help !

1 Like