Re: [Engine-devel] Query regarding ValidationUtils#validateInputs
On Sunday 15 April 2012 11:31 AM, Roy Golan wrote: On 04/12/2012 10:50 AM, Omer Frenkel wrote: *From: *Shireesh Anjal san...@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 ArrayListString validateInputs(ListClass? 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()) { ListString 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 ListBricks 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 ___ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel
Re: [Engine-devel] Query regarding ValidationUtils#validateInputs
On 04/12/2012 10:50 AM, Omer Frenkel wrote: *From: *Shireesh Anjal san...@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 ArrayListString validateInputs(ListClass? 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()) { ListString 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 ListBricks bricks Bricks.java @NotNull Guid id ___ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel
[Engine-devel] Query regarding ValidationUtils#validateInputs
Hi, This is regarding the following validation method we have in ValidationUtils: /public static T extends VdcActionParametersBase ArrayListString validateInputs(ListClass? 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()) { ListString 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
Re: [Engine-devel] Query regarding ValidationUtils#validateInputs
- Original Message - From: Shireesh Anjal san...@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 ArrayListString validateInputs(ListClass? 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()) { ListString 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. ___ Engine-devel mailing list Engine-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-devel