|
|
@@ -5,51 +5,15 @@
|
|
|
|
|
|
package scot.carricksoftware.grants.validators.text;
|
|
|
|
|
|
-import org.apache.logging.log4j.LogManager;
|
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
import scot.carricksoftware.grants.commands.text.PersonTextCommand;
|
|
|
-import scot.carricksoftware.grants.constants.ApplicationConstants;
|
|
|
-import scot.carricksoftware.grants.constants.ValidationConstants;
|
|
|
-import scot.carricksoftware.grants.domains.people.Person;
|
|
|
-import scot.carricksoftware.grants.validators.helpers.ValidateTypes;
|
|
|
|
|
|
-@SuppressWarnings("unused")
|
|
|
-@Component
|
|
|
-public class PersonTextCommandValidator {
|
|
|
-
|
|
|
- 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) {
|
|
|
- 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);
|
|
|
- }
|
|
|
+@Component
|
|
|
+public interface PersonTextCommandValidator {
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
+ void validate(PersonTextCommand personTextCommand, BindingResult bindingResult);
|
|
|
|
|
|
}
|
|
|
|