(This is my last topic on ocl constraints I swear!)
Hello everyone,
I'm currently working on a constraint that checks if IDs (profiling field "user_id") of the components (sysml::SysMLPart) are unique.
In the existing template constraints there are things similar to this:
-- context sysml::SysMLPart
inv:
sysml::SysMLPart.allInstance()->one(element | element.user_id = self.user_id)
But it is very ineficient for our projects (which contain a lot of elements), this constraint take 15min+ to give results. There is also the fact that we allow to have the same ID in different models.
For that we can execute our constraint on sysml::SysMLContainerPackage and check for another profiling field "user_type = 'System Model'" but it requires collecting all the "owned_element" below. For that we have the following code :
self.oclAsType(sysml::SysMLElement)->closure(the_owned_elements)->select(item | item.oclIsTypeOf(sysml::SysMLElement))
But no matter what we do the select operation yields 0 elements. I verified that the closure operation worked and it has indeed 3000+ elements.
Moreover, during debugging I noticed the following thing :

Which I don't really understand, the console considers that it is sysml::SysMLElement but .oclIsTypeOf(sysml::SysMLElement) is false?
My final code whould be something like that:
inv:
self.the_owner.oclIsUndefined() and
self.user_type = 'System Model'
implies
self.oclAsType(sysml::SysMLElement)
->closure(the_owned_elements)
->select(item | item.oclIsTypeOf(sysml::SysMLPart))
->isUnique((item | item.oclIsTypeOf(sysml::SysMLPart).user_id)
But this does not evaluate
