How to validate an element based on assigned stereotype

Discussions about Domain Specific Language customizations

Moderator: Moderators

How to validate an element based on assigned stereotype

Postby christophe.waterplas@incose.org » Tue Jul 09, 2019 3:33 am

Hello,

I want to define a number of ranges (i.e. min-max values) as ValueTypes, which I can then use as the types for a block's value properties. To that effect I created a <<Range>> stereotype with a min and max tag.

What I would like to do now is to create a validation rule that would check the properties value (i.e. slots) of instance specifications based on such block are within the Range applicable to their type. I can create a constraint that would check each value is within a predefined range (i.e. hardcoded min/max). However I would like the min/max to be derived from the <<Range>> stereotype applied to the properties' type.

Can someone provide guidance on how to define such validation rule?

In the example below the Block "Range Values" has two value properties, value1 and value2. The type of value1 is "Range A", which has the <<Range>> stereotype with tag values min = 5 and max = 10. Similarly value2 has "Range B" as a type, with stereotype <<Range>> with min = 15, max = 25. The validation rule I want should check any value1 slot (instance specification) is within the range defined by Range A (i.e. 5, 10) and correspondingly for slots of value2.

Range Definitions.png


Regards,
Christophe.

Range Validation.mdzip
You do not have the required permissions to view the files attached to this post.
christophe.waterplas@incose.org
Forum Newbie
Forum Newbie
 
Posts: 16
Posts Rating:1
Joined: Sun Aug 10, 2014 8:00 pm

Re: How to validate an element based on assigned stereotype

Postby TomasJkn » Mon Jul 29, 2019 9:01 am

Hello dear Christophe,
That is quite easy to do. The only snag is that literal real values (which you want to be checking) can occur in multiple places in UML/SysML model.
The slot value that You've mentioned is only one of such places. Another example could be default value of the value property.
You need a separate rule for each case.

Knowing this, the rules are straightforward to construct.
For validating literal reals in slots:
Code: Select all
context LiteralReal inv:
    self.owner.oclIsKindOf(Slot) and
    self.owner.oclAsType(Slot).definingFeature.type.oclIsKindOf(Range_Profile::Range)
    implies
    let range:Range_Profile::Range = self.owner.oclAsType(Slot).definingFeature.type.oclAsType(Range_Profile::Range) in
    self.value >= range.min and self.value <= range.max                                                                                 

For validating literal reals in default values:
Code: Select all
context LiteralReal inv:
    self.owner.oclIsKindOf(Property) and
    self.owner.oclAsType(Property).type.oclIsKindOf(Range_Profile::Range)
    implies
    let range:Range_Profile::Range = self.owner.oclAsType(Property).type.oclAsType(Range_Profile::Range) in
    self.value >= range.min and self.value <= range.max


Note: this is not an exhaustive list of cases where range check validation could be applied, but other cases can be covered similarly

Please see the attached project with additional rules.

I hope this helps.

PS We strongly recommend to register your future questions to No Magic staff as tickets in our knowledgebase http://knowledgebase.nomagic.com , as it allows to set privacy level, easy status tracking and attachment management.

Sincerely,
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
Last edited by TomasJkn on Mon Jul 29, 2019 9:06 am, edited 1 time in total.
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
TomasJkn
Customer Support
Customer Support
 
Posts: 63
Posts Rating:6
Joined: Mon May 10, 2010 9:24 am

Re: How to validate an element based on assigned stereotype

Postby TomasJkn » Mon Jul 29, 2019 9:04 am

The improved project
You do not have the required permissions to view the files attached to this post.
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
TomasJkn
Customer Support
Customer Support
 
Posts: 63
Posts Rating:6
Joined: Mon May 10, 2010 9:24 am

Re: How to validate an element based on assigned stereotype

Postby christophe.waterplas@incose.org » Thu Aug 01, 2019 10:53 pm

Hello Tomas,

This is great! That's what I needed. It works well, but the validation rules for LiteralReal are not being evaluated when clicking on the "Validate Diagram" button. It only works from the Analyse->Validation->Validate menu or from the explorer tree.

Once validated the invalid elements do get highlighted on the diagram but with a dashed red border.

And, if I use an Instance Table then nothing is highlighted at all.

Is there any way to fix that? The most important would be to highlight the invalid values on an instance table.

Regards
Christophe.
christophe.waterplas@incose.org
Forum Newbie
Forum Newbie
 
Posts: 16
Posts Rating:1
Joined: Sun Aug 10, 2014 8:00 pm

Re: How to validate an element based on assigned stereotype

Postby TomasJkn » Mon Aug 05, 2019 4:08 am

Hello Christophe,

It works well, but the validation rules for LiteralReal are not being evaluated when clicking on the "Validate Diagram" button. It only works from the Analyse->Validation->Validate menu or from the explorer tree.

This is strange. For me it works with Validate Diagram (on symbolic diagrams). What service pack are you on? 18.5SP3 should work OK.

Once validated the invalid elements do get highlighted on the diagram but with a dashed red border.

And, if I use an Instance Table then nothing is highlighted at all.

Is there any way to fix that? The most important would be to highlight the invalid values on an instance table.


This is the consequence of validating "too fine" a model element - the dashed border means that it is not the depicted element itself that is being validated but the owned element inside it.
So the diagram considers that depicted element is a slot, and since slot itself is not invalid (according to this rule formulation), it is not highlighted with red border.
But slot owns another model element - literal real value, which is invalid (according to this rule formulation), hence the slot is highlighed with red dash.

Similarly, the instance table considers the cell to depict a slot, not a value.

To overcome this, you can reformulate the rules in such a way that it is a slot that fails, not the owned literal real of the slot.
The OCL would be something like this:
Code: Select all
context Slot inv:
    (not self.definingFeature.type->isEmpty() and self.definingFeature.type.oclIsKindOf(Range_Profile::Range))
    implies
    let range:Range_Profile::Range = self.definingFeature.type.oclAsType(Range_Profile::Range) in
    self.value->forAll(v:ValueSpecification|
        v.oclIsKindOf(LiteralReal) implies
        (v.oclAsType(LiteralReal).value >= range.min and v.oclAsType(LiteralReal).value <= range.max)
    )   


I have altered the example. Please see the Range Validation Alternative validation suite in the attached project.

I hope this helps.

Sincerely,
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
You do not have the required permissions to view the files attached to this post.
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
TomasJkn
Customer Support
Customer Support
 
Posts: 63
Posts Rating:6
Joined: Mon May 10, 2010 9:24 am

Re: How to validate an element based on assigned stereotype

Postby christophe.waterplas@incose.org » Tue Aug 06, 2019 6:22 pm

Hello Tomas,

This solution works! Now I can validate from within the diagram.

Thank you very much for your help!

Regards,
Christophe.
christophe.waterplas@incose.org
Forum Newbie
Forum Newbie
 
Posts: 16
Posts Rating:1
Joined: Sun Aug 10, 2014 8:00 pm


Return to DSL

Who is online

Users browsing this forum: No registered users and 0 guests