|
@@ -12,6 +12,8 @@ import org.springframework.validation.BindingResult;
|
|
|
import scot.carricksoftware.grants.commands.text.PersonTextCommand;
|
|
import scot.carricksoftware.grants.commands.text.PersonTextCommand;
|
|
|
import scot.carricksoftware.grants.constants.ApplicationConstants;
|
|
import scot.carricksoftware.grants.constants.ApplicationConstants;
|
|
|
import scot.carricksoftware.grants.constants.ValidationConstants;
|
|
import scot.carricksoftware.grants.constants.ValidationConstants;
|
|
|
|
|
+import scot.carricksoftware.grants.domains.people.Person;
|
|
|
|
|
+import scot.carricksoftware.grants.validators.helpers.ValidateTypes;
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
@SuppressWarnings("unused")
|
|
|
@Component
|
|
@Component
|
|
@@ -19,17 +21,35 @@ public class PersonTextCommandValidator {
|
|
|
|
|
|
|
|
private static final Logger logger = LogManager.getLogger(PersonTextCommandValidator.class);
|
|
private static final Logger logger = LogManager.getLogger(PersonTextCommandValidator.class);
|
|
|
|
|
|
|
|
|
|
+ private final ValidateTypes validateTypes;
|
|
|
|
|
+
|
|
|
|
|
+ public PersonTextCommandValidator(ValidateTypes validateTypes) {
|
|
|
|
|
+ this.validateTypes = validateTypes;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void validate(PersonTextCommand personTextCommand, BindingResult bindingResult) {
|
|
public void validate(PersonTextCommand personTextCommand, BindingResult bindingResult) {
|
|
|
- logger.debug("PersonTextCommandValidator::validate");
|
|
|
|
|
- if (personTextCommand.getPerson() == null) {
|
|
|
|
|
- bindingResult.rejectValue("person", ApplicationConstants.EMPTY_STRING,
|
|
|
|
|
- null,
|
|
|
|
|
- ValidationConstants.PERSON_IS_NULL);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ logger.debug("PersonTextCommandValidator::validate");
|
|
|
|
|
+ validatePerson(personTextCommand.getPerson(), bindingResult);
|
|
|
|
|
+ validateOrder(personTextCommand.getOrder(), bindingResult);
|
|
|
|
|
+ validateLevel(personTextCommand.getLevel(), bindingResult);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void validateLevel(String level, BindingResult bindingResult) {
|
|
|
|
|
+ logger.debug("PersonTextCommandValidator::validateLevel");
|
|
|
|
|
+ validateTypes.validateIntegerRange(level, ApplicationConstants.LATEX_BOOK, ApplicationConstants.LATEX_SUB_PARAGRAPH, "level",
|
|
|
|
|
+ ValidationConstants.LEVEL_IS_NULL, ValidationConstants.LEVEL_IS_INVALID, ValidationConstants.LEVEL_IS_OUTSIDE_LIMITS, bindingResult);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void validatePerson(Person person, BindingResult bindingResult) {
|
|
|
|
|
+ logger.debug("PersonTextCommandValidator::validatePerson");
|
|
|
|
|
+ validateTypes.validatePerson(person, "person", ValidationConstants.PERSON_IS_NULL, bindingResult);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void validateOrder(String order, BindingResult bindingResult) {
|
|
|
|
|
+ logger.debug("PersonTextCommandValidator::validateOrder");
|
|
|
|
|
+ validateTypes.validateNonNegativeInteger(order, "order",ValidationConstants.ORDER_IS_NULL,
|
|
|
|
|
+ ValidationConstants.ORDER_IS_INVALID, ValidationConstants.ORDER_IS_NEGATIVE,bindingResult);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|