<div dir="ltr">Hi,<div><br></div><div>2014-07-29 15:31 GMT+02:00 Richard Fanning <span dir="ltr">&lt;<a href="mailto:Richard.Fanning@fineos.com" target="_blank">Richard.Fanning@fineos.com</a>&gt;</span>:<br></div><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">






<div>
<font face="Calibri"><span style="font-size:11pt">
<div><font color="#632423">Hi there,</font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">We are starting to use bean validation in our product and something we would like to do is what I’ve coined as “implicit constraints”. I’d like to run this by the mailing list and get your thoughts on this as a potential feature in
the spec.</font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">The use case we have is we have a “DateTime” object which represents Date &amp; Time. Our DateTime object pre-dates JDK 8 (and JodaTime).  A DateTime for us has some constraints</font></div>
<div><font color="#632423"> </font></div>
<ol style="margin:0px;padding-left:36pt">
<font color="#632423">
<li>The DateTime cannot me before LOW_DATE <font face="Wingdings">à</font> 01-01-1970 00:00:00</li><li>The DateTime cannot me after HIGH_DATE <font face="Wingdings">à</font> 31-12-2150 23:59:59</li></font>
</ol>
<div><font color="#632423"> </font></div>
<div><font color="#632423">Not sure of the exact history of these constraints but it would seem like we are trying to invent a new y2k <font face="Wingdings">J</font> </font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">These constraints were enforced prior to our usage of Bean Validation as these were burnt into the setter of generated POJO’s (domain objects) but now that we are moving from generated domain objects to JPA style POJO’s we’d like
to use Bean Validation to apply the same constraints.</font></div></span></font></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><font face="Calibri"><span style="font-size:11pt">
<div><font color="#632423">Assume we have an object which has a DateTime property as shown below</font></div>
<div><font color="#632423"> </font></div>
<div><font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>public</b><font color="black"> </font><b>class</b><font color="black"> TestObject {</font></span></font></div>
<div> </div>
<div>        <font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>private</b></span></font><font face="Consolas"><span style="font-size:10pt"> DateTime </span></font><font face="Consolas" color="#0000C0"><span style="font-size:10pt">myDateTime</span></font><font face="Consolas"><span style="font-size:10pt">;</span></font></div>

<div>        </div>
<div>        <font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>public</b></span></font><font face="Consolas"><span style="font-size:10pt"> DateTime getMyDateTime() {</span></font></div>
<div>                <font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>return</b></span></font><font face="Consolas"><span style="font-size:10pt"> </span></font><font face="Consolas" color="#0000C0"><span style="font-size:10pt">myDateTime</span></font><font face="Consolas"><span style="font-size:10pt">;</span></font></div>

<div>        <font face="Consolas"><span style="font-size:10pt">}</span></font></div>
<div> </div>
<div>        <font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>public</b></span></font><font face="Consolas"><span style="font-size:10pt"> </span></font><font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>void</b></span></font><font face="Consolas"><span style="font-size:10pt">
setMyDateTime(DateTime </span></font><font face="Consolas" color="#6A3E3E"><span style="font-size:10pt">myDateTime</span></font><font face="Consolas"><span style="font-size:10pt">) {</span></font></div>
<div>                <font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>this</b></span></font><font face="Consolas"><span style="font-size:10pt">.</span></font><font face="Consolas" color="#0000C0"><span style="font-size:10pt">myDateTime</span></font><font face="Consolas"><span style="font-size:10pt">
= </span></font><font face="Consolas" color="#6A3E3E"><span style="font-size:10pt">myDateTime</span></font><font face="Consolas"><span style="font-size:10pt">;</span></font></div>
<div>        <font face="Consolas"><span style="font-size:10pt">}</span></font></div>
<div>        </div>
<div><font face="Consolas"><span style="font-size:10pt">}</span></font></div>
<div><font face="Consolas"><span style="font-size:10pt"> </span></font></div>
<div><font color="#632423">We’d like if developers did not need to add an annotation all DateTime properties to constrain with the implicit constraints.. i.e.</font></div>
<div><font color="#632423"> </font></div>
<div><font face="Consolas"><span style="font-size:10pt">@Date</span></font></div>
<div><font face="Consolas" color="#7F0055"><span style="font-size:10pt"><b>private</b><font color="black"> DateTime </font><font color="#0000C0">myDateTime</font><font color="black">;</font></span></font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">In our opinion this annotation serves no additional purpose and would be an extra onus on the developer to add this so they ensure the value meets internal DateTime criteria. </font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">Looking at the 1.1 spec I cannot see any way of applying constraints without annotating (well you can use HV XML but that would need to be done for all fields).. Is that correct.</font></div></span></font></div>
</blockquote><div><br></div><div>Yes, the spec defines constraint declaration via annotations and XML. Hibernate Validator in addition has a (public) API for programmatic constraint declaration.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><font face="Calibri"><span style="font-size:11pt"><div><font color="#632423"> </font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">I’ve managed to implement “implicit constraints” by using non-standard Hibernate Validator API’s (i.e. using reflection I added an additional MetaDataProvider which added ConstrainedElements ( to the BeanConfiguration)). I can share
this on GitHub is anyone is interested in taking a look.</font></div></span></font></div></blockquote><div><br></div><div>You should better use the HV constraint API for this [1]. You could inspect your beans using reflection and define a @Date constraint for each DateTime property you find. MetaDataProvider et al. are internal APIs which may change without notice between releases.</div>
<div><br></div><div>Standardizing this API might be a useful addition as it allows to implement cases as yours in a portable manner. Not sure whether the spec should explicitly support this requirement, as it may be very specific.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="Calibri"><span style="font-size:11pt">
<div><font color="#632423">Appreciate any feedback you might have.</font></div>
<div><font color="#632423"> </font></div>
<div><font color="#632423">Thanks</font></div>
<div><font color="#632423"><br>

Rich</font></div></span></font></blockquote><div><br></div><div>--Gunnar</div><div><br></div><div>[1] <a href="http://docs.jboss.org/hibernate/validator/5.1/reference/en-US/html_single/#section-programmatic-api">http://docs.jboss.org/hibernate/validator/5.1/reference/en-US/html_single/#section-programmatic-api</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><font face="Calibri"><span style="font-size:11pt">
<div> </div>
<div> </div>
</span></font>
<p>
<font face="arial,helvetica,sans-serif">__________________________________________________________<br>FINEOS Corporation is the global brand name of FINEOS Corporation and its affiliated <br>group companies worldwide.<br>
<br>The information contained in this e-mail is confidential, may be privileged and is intended <br>only for the use of the recipient named above. If you are not the intended recipient or a <br>representative of the intended recipient, you have received this e-mail in error and must <br>
not copy, use or disclose the contents of this e-mail to anybody else.  <br><br>If you have received this e-mail in error, please notify the sender immediately by return <br>e-mail and permanently delete the copy you received.  This e-mail has been swept for <br>
computer viruses. However, you should carry out your own virus checks. <br>Registered in Ireland, No. 205721.  <a href="http://www.FINEOS.com" target="_blank">http://www.FINEOS.com</a><br>__________________________________________________________<br>
</font></p>
</div>

<br>_______________________________________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br></blockquote></div><br></div></div>