[Engine-devel] Query regarding ValidationUtils#validateInputs

This is a multi-part message in MIME format. --------------060906010904020105000601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, This is regarding the following validation method we have in ValidationUtils: /public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);/ I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method: protected boolean canDoAction() { ... for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) { List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick); if(errors != null) { for(String error : errors) { addCanDoActionMessage(error); } } } ... } Regards, Shireesh --------------060906010904020105000601 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> Hi,<br> <br> This is regarding the following validation method we have in ValidationUtils:<br> <br> <i>public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);</i><br> <br> I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:<br> <br> protected boolean canDoAction() {<br> ...<br> for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) {<br> List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick);<br> if(errors != null) {<br> for(String error : errors) {<br> addCanDoActionMessage(error);<br> }<br> }<br> }<br> ...<br> }<br> <br> Regards,<br> Shireesh<br> </body> </html> --------------060906010904020105000601--

--=_e21defe9-d4a0-4579-ac6e-9f383c6664d2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit ----- Original Message -----
From: "Shireesh Anjal" <sanjal@redhat.com> To: engine-devel@ovirt.org Sent: Thursday, April 12, 2012 9:35:25 AM Subject: [Engine-devel] Query regarding ValidationUtils#validateInputs
Hi,
This is regarding the following validation method we have in ValidationUtils:
public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);
I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:
protected boolean canDoAction() { ... for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) { List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick); if(errors != null) { for(String error : errors) { addCanDoActionMessage(error); } } } ... }
Regards, Shireesh
_______________________________________________ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel
i don't think there is a reason to restrict only for VdcActionParametersBase, roy what do you think? also you can use here getReturnValue().getCanDoActionMessages().addAll(errors); instead of going over on all errors. --=_e21defe9-d4a0-4579-ac6e-9f383c6664d2 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit <html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'><br><br><hr id="zwchr"><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Shireesh Anjal" <sanjal@redhat.com><br><b>To: </b>engine-devel@ovirt.org<br><b>Sent: </b>Thursday, April 12, 2012 9:35:25 AM<br><b>Subject: </b>[Engine-devel] Query regarding ValidationUtils#validateInputs<br><br> Hi,<br> <br> This is regarding the following validation method we have in ValidationUtils:<br> <br> <i>public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);</i><br> <br> I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:<br> <br> protected boolean canDoAction() {<br> ...<br> for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) {<br> List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick);<br> if(errors != null) {<br> for(String error : errors) {<br> addCanDoActionMessage(error);<br> }<br> }<br> }<br> ...<br> }<br> <br> Regards,<br> Shireesh<br> <br>_______________________________________________<br>Engine-devel mailing list<br>Engine-devel@ovirt.org<br>http://lists.ovirt.org/mailman/listinfo/engine-devel<br></blockquote>i don't think there is a reason to restrict only for VdcActionParametersBase, roy what do you think?<br><br>also you can use here<br>getReturnValue().getCanDoActionMessages().addAll(errors);<br>instead of going over on all errors.<br></div></body></html> --=_e21defe9-d4a0-4579-ac6e-9f383c6664d2--

This is a multi-part message in MIME format. --------------080707050808080009010909 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 04/12/2012 10:50 AM, Omer Frenkel wrote:
------------------------------------------------------------------------
*From: *"Shireesh Anjal" <sanjal@redhat.com> *To: *engine-devel@ovirt.org *Sent: *Thursday, April 12, 2012 9:35:25 AM *Subject: *[Engine-devel] Query regarding ValidationUtils#validateInputs
Hi,
This is regarding the following validation method we have in ValidationUtils:
/public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);/
I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:
protected boolean canDoAction() { ... for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) { List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick); if(errors != null) { for(String error : errors) { addCanDoActionMessage(error); } } } ... }
Regards, Shireesh
_______________________________________________ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel
i don't think there is a reason to restrict only for VdcActionParametersBase, roy what do you think?
also you can use here getReturnValue().getCanDoActionMessages().addAll(errors); instead of going over on all errors.
pls see SetupNetworksParameters.java for validating a list of network interfaces. hibernate validator supports trivial object graphs and members that are arrays, list and java.util.map implementations. If your code looks like that it should work. If you are using special validation groups please add them to your command with addValidationGroups. this should work: GlusterCommandParameters.java @Valid List<Bricks> bricks Bricks.java @NotNull Guid id --------------080707050808080009010909 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> </head> <body text="#000000" bgcolor="#FFFFFF"> On 04/12/2012 10:50 AM, Omer Frenkel wrote: <blockquote cite="mid:15a5329c-4579-4ef6-b1c8-be0b260e859b@zmail07.collab.prod.int.phx2.redhat.com" type="cite"> <style type="text/css">p { margin: 0; }</style> <div style="font-family: Times New Roman; font-size: 12pt; color: #000000"><br> <br> <hr id="zwchr"> <blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Shireesh Anjal" <a class="moz-txt-link-rfc2396E" href="mailto:sanjal@redhat.com"><sanjal@redhat.com></a><br> <b>To: </b><a class="moz-txt-link-abbreviated" href="mailto:engine-devel@ovirt.org">engine-devel@ovirt.org</a><br> <b>Sent: </b>Thursday, April 12, 2012 9:35:25 AM<br> <b>Subject: </b>[Engine-devel] Query regarding ValidationUtils#validateInputs<br> <br> Hi,<br> <br> This is regarding the following validation method we have in ValidationUtils:<br> <br> <i>public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);</i><br> <br> I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:<br> <br> protected boolean canDoAction() {<br> ...<br> for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) {<br> List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick);<br> if(errors != null) {<br> for(String error : errors) {<br> addCanDoActionMessage(error);<br> }<br> }<br> }<br> ...<br> }<br> <br> Regards,<br> Shireesh<br> <br> _______________________________________________<br> Engine-devel mailing list<br> <a class="moz-txt-link-abbreviated" href="mailto:Engine-devel@ovirt.org">Engine-devel@ovirt.org</a><br> <a class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/engine-devel">http://lists.ovirt.org/mailman/listinfo/engine-devel</a><br> </blockquote> i don't think there is a reason to restrict only for VdcActionParametersBase, roy what do you think?<br> <br> also you can use here<br> getReturnValue().getCanDoActionMessages().addAll(errors);<br> instead of going over on all errors.<br> </div> </blockquote> <br> pls see SetupNetworksParameters.java for validating a list of network interfaces.<br> <br> hibernate validator supports trivial object graphs and members that are arrays, list and java.util.map implementations.<br> If your code looks like that it should work. If you are using special validation groups please add them to your command with addValidationGroups.<br> <br> this should work:<br> <br> GlusterCommandParameters.java<br> @Valid<br> List<Bricks> bricks<br> <br> Bricks.java<br> @NotNull<br> Guid id<br> </body> </html> --------------080707050808080009010909--

This is a multi-part message in MIME format. --------------000503030108060803000801 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On Sunday 15 April 2012 11:31 AM, Roy Golan wrote:
On 04/12/2012 10:50 AM, Omer Frenkel wrote:
------------------------------------------------------------------------
*From: *"Shireesh Anjal" <sanjal@redhat.com> *To: *engine-devel@ovirt.org *Sent: *Thursday, April 12, 2012 9:35:25 AM *Subject: *[Engine-devel] Query regarding ValidationUtils#validateInputs
Hi,
This is regarding the following validation method we have in ValidationUtils:
/public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);/
I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:
protected boolean canDoAction() { ... for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) { List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick); if(errors != null) { for(String error : errors) { addCanDoActionMessage(error); } } } ... }
Regards, Shireesh
_______________________________________________ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel
i don't think there is a reason to restrict only for VdcActionParametersBase, roy what do you think?
also you can use here getReturnValue().getCanDoActionMessages().addAll(errors); instead of going over on all errors.
pls see SetupNetworksParameters.java for validating a list of network interfaces.
hibernate validator supports trivial object graphs and members that are arrays, list and java.util.map implementations. If your code looks like that it should work. If you are using special validation groups please add them to your command with addValidationGroups.
this should work:
GlusterCommandParameters.java @Valid List<Bricks> bricks
Bricks.java @NotNull Guid id
Thanks! I had tried adding @Valid annotation as suggested above, which had resulted in an exception from the validation engine, without any specific information about the problem, and I assumed that @Valid may not work on Lists. Digged deeper after reading your response, and found that the @Valid annotation resulted in a call to equals method on the entity, which had a bug, resulting in the exception. It all works well after fixing the bug.
_______________________________________________ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel
--------------000503030108060803000801 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> On Sunday 15 April 2012 11:31 AM, Roy Golan wrote: <blockquote cite="mid:4F8A643C.8060605@redhat.com" type="cite"> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> On 04/12/2012 10:50 AM, Omer Frenkel wrote: <blockquote cite="mid:15a5329c-4579-4ef6-b1c8-be0b260e859b@zmail07.collab.prod.int.phx2.redhat.com" type="cite"> <style type="text/css">p { margin: 0; }</style> <div style="font-family: Times New Roman; font-size: 12pt; color: #000000"><br> <br> <hr id="zwchr"> <blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Shireesh Anjal" <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:sanjal@redhat.com"><sanjal@redhat.com></a><br> <b>To: </b><a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:engine-devel@ovirt.org">engine-devel@ovirt.org</a><br> <b>Sent: </b>Thursday, April 12, 2012 9:35:25 AM<br> <b>Subject: </b>[Engine-devel] Query regarding ValidationUtils#validateInputs<br> <br> Hi,<br> <br> This is regarding the following validation method we have in ValidationUtils:<br> <br> <i>public static <T extends VdcActionParametersBase> ArrayList<String> validateInputs(List<Class<?>> validationGroupList, T parameters);</i><br> <br> I there any particular reason for supporting the validations only on objects of classes derived from VdcActionParametersBase? I guess this was done because this method is primarily intended to validate the action parameters passed to a BLL action, using the validation annotations on the parameter class. However I think this method can be useful for general use as well. e.g. I cannot add a "@Valid" annotation on a "list" or a "map" in a parameter class. So I need to iterate over the list/map, and validate each element inside the loop. The validation inside the loop can also utilize the above method if the restriction "extends VdcActionParametersBase" is removed. This will allow me to do the following in the canDoAction method:<br> <br> protected boolean canDoAction() {<br> ...<br> for(GlusterBrickEntity brick : getParameters().getGlusterVolume().getBricks()) {<br> List<String> errors = ValidationUtils.validateInputs(getValidationGroups(), brick);<br> if(errors != null) {<br> for(String error : errors) {<br> addCanDoActionMessage(error);<br> }<br> }<br> }<br> ...<br> }<br> <br> Regards,<br> Shireesh<br> <br> _______________________________________________<br> Engine-devel mailing list<br> <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Engine-devel@ovirt.org">Engine-devel@ovirt.org</a><br> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/engine-devel">http://lists.ovirt.org/mailman/listinfo/engine-devel</a><br> </blockquote> i don't think there is a reason to restrict only for VdcActionParametersBase, roy what do you think?<br> <br> also you can use here<br> getReturnValue().getCanDoActionMessages().addAll(errors);<br> instead of going over on all errors.<br> </div> </blockquote> <br> pls see SetupNetworksParameters.java for validating a list of network interfaces.<br> <br> hibernate validator supports trivial object graphs and members that are arrays, list and java.util.map implementations.<br> If your code looks like that it should work. If you are using special validation groups please add them to your command with addValidationGroups.<br> <br> this should work:<br> <br> GlusterCommandParameters.java<br> @Valid<br> List<Bricks> bricks<br> <br> Bricks.java<br> @NotNull<br> Guid id<br> </blockquote> <br> Thanks! I had tried adding @Valid annotation as suggested above, which had resulted in an exception from the validation engine, without any specific information about the problem, and I assumed that @Valid may not work on Lists. Digged deeper after reading your response, and found that the @Valid annotation resulted in a call to equals method on the entity, which had a bug, resulting in the exception. It all works well after fixing the bug.<br> <br> <blockquote cite="mid:4F8A643C.8060605@redhat.com" type="cite"> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> <pre wrap="">_______________________________________________ Engine-devel mailing list <a class="moz-txt-link-abbreviated" href="mailto:Engine-devel@ovirt.org">Engine-devel@ovirt.org</a> <a class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/engine-devel">http://lists.ovirt.org/mailman/listinfo/engine-devel</a> </pre> </blockquote> <br> </body> </html> --------------000503030108060803000801--
participants (3)
-
Omer Frenkel
-
Roy Golan
-
Shireesh Anjal