Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCLinEcore: Custom validation messages not working
OCLinEcore: Custom validation messages not working [message #1700726] Mon, 06 July 2015 16:48 Go to next message
Matthias Freund is currently offline Matthias FreundFriend
Messages: 8
Registered: May 2014
Junior Member
Hi all,

I am currently trying to realize custom OCL validation messages by means of the 'OCLinEcoreTutorial' but so far have not been successful. I have performed the following steps:


  1. Set the following OCL preferences

    • Executor targeted by the default OCL delegate: ".../Pivot"
    • Realisation of OCL embedded within Ecore models: "Generate Java Code in *Impl classes"
  2. Create the OCLinEcoreTutorial example
  3. Open the 'Tutorial.ecore' with the OCLinEcore editor
  4. Change the 'SufficientCopies' invariant of the 'Books' class as described here
  5. Generate the model code by means of the genmodel
  6. Make the generated 'TutorialValidator' extend the 'OCLinEcoreEObjectValidator'
  7. Run the generated model code
  8. Create a new model and validate it (with the 'Sample Reflective Ecore Model Editor')

When I validate the model, I always get the default error message (The 'SufficientCopies' constraint is violated ...) instead of the custom error message.

Did I miss anything or does this seem to be a bug? I tried to debug this myself and found that the correct error message seems to be assembled inside the 'SufficientCopies(...)' method of class 'BookImpl'. It is stored in a variable called 'TupleValue'. However, this does not seem to be passed to 'CGStringLogDiagnosticOperation.INSTANCE.evaluate(...)':

...
final /*@NonNull*/ /*@Thrown*/ TupleValue symbol_0 = ValueUtil.createTupleOfEach(TutorialTables.TUPLid_, sum_4, le_0);
final /*@NonInvalid*/ boolean status = (Boolean)symbol_0.getValue(1/*status*/);
final /*@NonInvalid*/ boolean logDiagnostic = ClassUtil.nonNullState(CGStringLogDiagnosticOperation.INSTANCE.evaluate(evaluator, TypeId.BOOLEAN, TutorialTables.STR_Book_c_c_SufficientCopies, this, diagnostics, context, severity_0, status, TutorialTables.INT_0).booleanValue());


Thanks in advance for any help!

Kind regards
Matthias
Re: OCLinEcore: Custom validation messages not working [message #1700730 is a reply to message #1700726] Mon, 06 July 2015 17:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6538
Registered: July 2009
Senior Member
HI

Oops.

CGStringLogDiagnosticOperation was a late addition to support
configurable severities for safe navigation. I can easily understand how
it breaks the code as you have described. However I'm surprised that no
JUnit test detected the breakage. I'm also puzzled that I missed the
regression while reviewing all the tutorials for Mars.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=471948 raised.

Regards

Ed Willink

On 06/07/2015 17:48, Matthias Freund wrote:
> Hi all,
>
> I am currently trying to realize custom OCL validation messages by
> means of the 'OCLinEcoreTutorial' but so far have not been successful.
> I have performed the following steps:
>
>
> Set the following OCL preferences
>
> Executor targeted by the default OCL delegate: ".../Pivot"
> Realisation of OCL embedded within Ecore models: "Generate Java Code
> in *Impl classes" Create the OCLinEcoreTutorial example
> Open the 'Tutorial.ecore' with the OCLinEcore editor
> Change the 'SufficientCopies' invariant of the 'Books' class as
> described
> http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FIntegration.html
> Generate the model code by means of the genmodel
> Make the generated 'TutorialValidator' extend the
> 'OCLinEcoreEObjectValidator'
> Run the generated model code
> Create a new model and validate it (with the 'Sample Reflective Ecore
> Model Editor')
>
> When I validate the model, I always get the default error message (The
> 'SufficientCopies' constraint is violated ...) instead of the custom
> error message.
>
> Did I miss anything or does this seem to be a bug? I tried to debug
> this myself and found that the correct error message seems to be
> assembled inside the 'SufficientCopies(...)' method of class
> 'BookImpl'. It is stored in a variable called 'TupleValue'. However,
> this does not seem to be passed to
> 'CGStringLogDiagnosticOperation.INSTANCE.evaluate(...)':
>
>
> ..
> final /*@NonNull*/ /*@Thrown*/ TupleValue symbol_0 =
> ValueUtil.createTupleOfEach(TutorialTables.TUPLid_, sum_4, le_0);
> final /*@NonInvalid*/ boolean status =
> (Boolean)symbol_0.getValue(1/*status*/);
> final /*@NonInvalid*/ boolean logDiagnostic =
> ClassUtil.nonNullState(CGStringLogDiagnosticOperation.INSTANCE.evaluate(evaluator,
> TypeId.BOOLEAN, TutorialTables.STR_Book_c_c_SufficientCopies, this,
> diagnostics, context, severity_0, status,
> TutorialTables.INT_0).booleanValue());
>
>
> Thanks in advance for any help!
>
> Kind regards
> Matthias
Re: OCLinEcore: Custom validation messages not working [message #1700750 is a reply to message #1700730] Mon, 06 July 2015 19:10 Go to previous messageGo to next message
Matthias Freund is currently offline Matthias FreundFriend
Messages: 8
Registered: May 2014
Junior Member
Hi,

thanks for the quick response!

Kind regards
Matthias
Re: OCLinEcore: Custom validation messages not working [message #1700869 is a reply to message #1700750] Tue, 07 July 2015 18:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6538
Registered: July 2009
Senior Member
Hi

I hope that you find

http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/6.0.1/N201507071256/mdt-ocl-Update-N201507071256.zip

fixes the problem.

Regards

Ed Willink


On 06/07/2015 20:10, Matthias Freund wrote:
> Hi,
>
> thanks for the quick response!
>
> Kind regards
> Matthias
Re: OCLinEcore: Custom validation messages not working [message #1700930 is a reply to message #1700869] Wed, 08 July 2015 09:16 Go to previous messageGo to next message
Matthias Freund is currently offline Matthias FreundFriend
Messages: 8
Registered: May 2014
Junior Member
Hi,

thanks! Now it works... Smile

Kind regards
Matthias
Re: OCLinEcore: Custom validation messages not working [message #1817977 is a reply to message #1700726] Tue, 03 December 2019 19:15 Go to previous messageGo to next message
Lars-Ola Österlund is currently offline Lars-Ola ÖsterlundFriend
Messages: 1
Registered: December 2019
Junior Member
I also try to generate custom messages but fail, started with the example from the library tutorial:
invariant SufficientCopies('There are '
+ library.loans->select((book = self))->size().toString()
+ ' loans for the ' + copies.toString() + ' copies of \'' + name + '\''):
library.loans->select((book = self))->size() <= copies;
Generated the code for the library tutorial and did a test run resulting in the built in report.
The documentation says the generated validator class must extend OCLinEcoreEObjectValidator instead of EObjectValidator so I changed that and added
"import org.eclipse.ocl.xtext.oclinecore.validation.OCLinEcoreEObjectValidator;"
and got the error
"The import org.eclipse.ocl.xtext cannot be resolved"
OCLinEcoreEObjectValidator documentation has a warning "This class may go obsolete once Bug 337792 resolved".
Another solved bugreport 471948 says a call to OCLinEcoreEObjectValidator is now working.
Then I debugged the existing code and found that the EObjectValidator validate method has an expression string with a "Tuple ..." containing the above message. But the message string is not transferred to the reportConstraintDelegateViolation method that generates the standard message.
Did I make a mistake somewhere or is the custom messaging not working?
I am using latest Eclipse (2019-09) and latest OCL downloads.
First I put this message in the bugreport337792, a mistake sorry about that.
Would much appreciate help on this.
Lars-Ola Österlund
Re: OCLinEcore: Custom validation messages not working [message #1818001 is a reply to message #1817977] Wed, 04 December 2019 06:28 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6538
Registered: July 2009
Senior Member
Hi

See the answer to the duplicate 'posting' to https://bugs.eclipse.org/bugs/show_bug.cgi?id=337792

Regards

Ed Willink
Previous Topic:Problems with a loop
Next Topic:Parsing constraints having elements from differents packages
Goto Forum:
  


Current Time: Sat Dec 14 06:10:49 GMT 2019

Powered by FUDForum. Page generated in 0.02082 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top