I have built a Spring REST service (Spring 4.0 and Java 8) and I have a Employee REST service where in the Employee class has the following attributes name, age, sex, salary, designation, company_id ,holiday_entitlement, manager_name & country.
I am looking to write a validation layer using Spring 4.0 , the validation needs to be dynamic based on the country of the employee
Validations Expected
Employee name, age, sex and country is mandatory.
Employee Sex has to be Male or Female
Employee age cannot be greater than 70 years and not lesser than 18 years.
For example if the country is UK, the holiday entitlement cannot be greater than 25 days If the country is US, the holiday entitlement cannot be greater than 20 days If the country is Spain, the holiday entitlement cannot be greater than 30 days
Similarly, if the country is UK, then it can accept a designation from only a predefined list of designations for UK, similar approach for other countries.
If the manager_name is provided , then I need to validate that he is part of the same company id as the employee. So I will have to lookup some DAO to get the manager's company ID.
Questions
A. Given the above validation requirements, I would like to understand if there are any specific classes in Spring that will allow dynamic validations such as based on country.
B. When would the validations be called, immediately post my JSON gets converted to a Java object by spring or within the Services layer (class annotated @Service).
C. Should I still use spring bean validations JSR 303 annotations in my Employee POJO or should the validations happen in a different class esp for attributes that are mandatory?