Creating validation rule with OCL2.0

UML related questions and discussions

Moderator: Moderators

Creating validation rule with OCL2.0

Postby ieva.gaidukeviciute@gmail.com » Mon Jan 23, 2017 1:56 pm

Hi,

I need to add validation rule constraint (using OCL2.0) that is validating type of the diagram. The problem is that diagram metaclass do not have any information about the type of the diagram.

My question would be if it is possible to get type of the diagram using OCL2.0?
ieva.gaidukeviciute@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Mon Jan 23, 2017 1:23 pm

Re: Creating validation rule with OCL2.0

Postby rimvydas.vaidelis » Wed Jan 25, 2017 12:50 am

Hi,

Type of a diagram is a dynamic derived property. Such properties are not accessible from OCL up to MD version 18.5.
In MD 18.5 version you can use following expression:

Code: Select all
self.DIAGRAM_TYPE_DERIVED_PROPERTY


Regards,
Rimvydas Vaidelis
rimvydas.vaidelis
Customer Support
Customer Support
 
Posts: 259
Posts Rating:15
Joined: Fri May 28, 2010 4:45 am

Re: Creating validation rule with OCL2.0

Postby Olivier CASSE - France » Sun Nov 19, 2017 8:51 am

Hi,

I'm looking for a way to use the 'self.DIAGRAM_TYPE_DERIVED_PROPERTY' mentioned here, but I got a "Unrecognized variable" error.
Could you please provide an example, for instance to check if a bdd named 'myBDD' is available in a specific package 'MyPackage'?

this is my attempt:
Code: Select all
Context Package
if self.qualifiedName = 'MyPackage'
then                       
self.DIAGRAM_TYPE_DERIVED_PROPERTY.name='myBDD'
else
true
endif


many thanks,
Olivier
User avatar
Olivier CASSE - France
Forum Beginner
Forum Beginner
 
Posts: 40
Posts Rating:1
Joined: Wed Jan 11, 2017 6:42 am
Location: France
Full name: Olivier CASSE

Re: Creating validation rule with OCL2.0

Postby rimvydas.vaidelis » Tue Nov 21, 2017 8:23 am

DIAGRAM_TYPE_DERIVED_PROPERTY is defined in Diagram type. It seems that you trying to access this property in Package.
rimvydas.vaidelis
Customer Support
Customer Support
 
Posts: 259
Posts Rating:15
Joined: Fri May 28, 2010 4:45 am

Re: Creating validation rule with OCL2.0

Postby Olivier CASSE - France » Wed Nov 22, 2017 2:55 am

Hello,

Ok got it, then I found how to use it.

Code: Select all
Context Diagram
-- Is there the expected diagram there?
if qualifiedName='1_Scope::BDD_Scope'
then
DIAGRAM_TYPE_DERIVED_PROPERTY='SysML Block Definition Diagram'
else
true
endif         


but I have an issue now, as my goal is to check if the BDD 'BDD_Scope' exists.
the above rule checks if an existing BDD is named BDD_Scope.
so if BDD's name is wrong, fine I have an error... but if there is no BDD with this name, no error...

this is why I tried using Package for the Context.
Would you have an idea for a rule checking if a specific named diagram, with a specific type is available in a specific package?

thanks in advance,
Olivier
User avatar
Olivier CASSE - France
Forum Beginner
Forum Beginner
 
Posts: 40
Posts Rating:1
Joined: Wed Jan 11, 2017 6:42 am
Location: France
Full name: Olivier CASSE

Re: Creating validation rule with OCL2.0

Postby rimvydas.vaidelis » Wed Nov 22, 2017 7:06 am

Code: Select all
if self.qualifiedName = 'data::MyPackage'
then
self.ownedElement -> select(oclIsTypeOf(Diagram)) -> collect(oclAsType(Diagram)) -> select(d | d.name = 'MyDiagram') -> exists(d | d.DIAGRAM_TYPE_DERIVED_PROPERTY = 'SysML Block Definition Diagram')
else
true
endif
rimvydas.vaidelis
Customer Support
Customer Support
 
Posts: 259
Posts Rating:15
Joined: Fri May 28, 2010 4:45 am

Re: Creating validation rule with OCL2.0

Postby Olivier CASSE - France » Wed Nov 22, 2017 8:41 am

F A N T A S T I C ! ! 8-)

works exactly as expected for a BDD,

I can see a last issue with State Machine Diagram underneath State Machine, Internal Block Diagram below a Block, Activities etc...with one element in between the Diagram and the package

May I still take advantage of your help ? :oops:

many thanks,
Olivier
User avatar
Olivier CASSE - France
Forum Beginner
Forum Beginner
 
Posts: 40
Posts Rating:1
Joined: Wed Jan 11, 2017 6:42 am
Location: France
Full name: Olivier CASSE

Re: Creating validation rule with OCL2.0

Postby rimvydas.vaidelis » Wed Nov 22, 2017 10:56 am

You can try this OCL:
Code: Select all
if self.qualifiedName = 'data::MyPackage'
then
self.ownedElement -> closure(ownedElement) -> select(oclIsTypeOf(Diagram)) -> collect(oclAsType(Diagram)) -> select(d | d.name = 'MyDiagram') -> exists(d | d.DIAGRAM_TYPE_DERIVED_PROPERTY = 'SysML Block Definition Diagram')
else
true
endif


Note: it collects all owned elements recursivelly.
rimvydas.vaidelis
Customer Support
Customer Support
 
Posts: 259
Posts Rating:15
Joined: Fri May 28, 2010 4:45 am

Re: Creating validation rule with OCL2.0

Postby olivier.casse.consulting@gmail.com » Wed Nov 22, 2017 11:06 am

Well done !

many thanks,
Olivier
olivier.casse.consulting@gmail.com
Forum Beginner
Forum Beginner
 
Posts: 34
Posts Rating:1
Joined: Tue Nov 21, 2017 8:24 am


Return to Software Modeling (UML)

Who is online

Users browsing this forum: No registered users and 1 guest