Lab validation back-end fix
Compare changes
@@ -343,7 +343,7 @@ public class LabController {
@@ -412,8 +412,9 @@ public class LabController {
This PR turned out longer and less focused than I intended so I don't expect everything to be accepted.
Makes sure exam labs are properly validated. Closes: #345 (closed)
I've added 2 ways to verify a lab.
LabValidator
. This makes sure that a bad @Validated
Lab form get's stopped at the web layer during the BindingResult
validation.ConstraintValidator
....
@ValidExamLab
public class Lab implements Serializable {
...
This makes sure that upon any Lab
entity's lifecyle events it gets validated and exam labs don't have null percentage, otherwise throws a ConstraintValidationException
. This should make sure no bad labs get persisted while keeping the @Nullable
annotation.
I noticed that Lab
has a custom getter that returns 0 if the examLabPercentage is null. I've removed this since it breaks validation. Do you maybe need a custom serializer for this?
If you like this validation pattern I can expand it to other classes who may have similar issues.