-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Validator: constrain when two groups are "active"
PostPosted: Fri Sep 30, 2016 3:55 am 
Newbie

Joined: Fri Sep 30, 2016 3:05 am
Posts: 2
Hi all,

I am new to Bean Validation and the first task I picked up is defining validation constraints for a third-party model (FHIR DSTU2).

The first problem is that the model has to be validated from two input sources with different constraints.
Because of this I defined two validation groups so that the constraints can be different for the inputs.

The second problem is that some of the properties are inherited and they have different constraints for different subclasses.
To solve this I redefine the Default group sequence to include a Group specific to the subclass. In the super class I can use this Group to define the constraint needed by the subclass.

And now the combined problem: I have to create constraints for inherited properties that are different for the two inputs. Following the previous approach that would require to check for the simultaneous presence of validation groups - i.e. enabling a constraint when BOTH groups are active.
However, I think no such thing is possible in Bean Validation.

Or is there a solution?
Thank you in advance,
Csaba


Top
 Profile  
 
 Post subject: Re: Validator: constrain when two groups are "active"
PostPosted: Fri Oct 07, 2016 2:30 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

Could you provide a small example of what you want to achieve?

I feel you may be better off using either XML-based constraints (with one mapping file per "input source") or using the HV API for programmatic constraint definition which allows you to declare constraints in a dynamic fashion, again based on the specific "input source".

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Validator: constrain when two groups are "active"
PostPosted: Mon Oct 10, 2016 4:15 am 
Newbie

Joined: Fri Sep 30, 2016 3:05 am
Posts: 2
Hi Gunnar,

Thank you for the suggestions.

Actually, the way I started was using the Hibernate API to define the constraints from code. (Since FHIR is a model that I do not own)
The alternative would have been to define the constraints in XML (- not overly happy with that).

The programmed constraints code became quite fast hard to maintain.

So what I did was to define a number of interfaces that correspond to FHIR model classes,
added the properties I need to validate, and annotated them.

Then wrote a "constraint collector" that walks through the dummy interfaces,
extracts the constraints using the Validation Metadata API and applies them to the real classes using the Hibernate API.

Now I can work as if I owned the FHIR sources.

Now, following your suggestion, I should not use validation groups for identifying the "input sources", but rather have the constraint collector create different constraints for the inputs.
I might add some custom annotations to the constraint annotations - will give it a try.

Thank you,
Csaba


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.