Explorar o código

ValidateTwoFieldTypes

Andrew Grant hai 3 meses
pai
achega
d6262b7ef1

+ 2 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/deathcertificate/DeathCertificateUntrackedFieldsValidatorImpl.java

@@ -7,6 +7,7 @@ package scot.carricksoftware.grants.validators.certificates.deathcertificate;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
@@ -20,6 +21,7 @@ public class DeathCertificateUntrackedFieldsValidatorImpl implements DeathCertif
 
     private final ValidateTwoFieldTypes validateTwoFieldTypes;
 
+    @Autowired
     public DeathCertificateUntrackedFieldsValidatorImpl(ValidateTwoFieldTypes validateTwoFieldTypes) {
         this.validateTwoFieldTypes = validateTwoFieldTypes;
     }

+ 1 - 0
src/main/java/scot/carricksoftware/grants/validators/helpers/ValidateTwoFieldTypes.java

@@ -9,6 +9,7 @@ import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
+
 public interface ValidateTwoFieldTypes {
 
     void validatePersonAndUntrackedPerson(Person person, String untrackedPerson, String personFieldName, String untrackedFieldName, String message,  BindingResult bindingResult);

+ 7 - 3
src/main/java/scot/carricksoftware/grants/validators/helpers/ValidateTwoFieldTypesImpl.java

@@ -46,9 +46,13 @@ public class ValidateTwoFieldTypesImpl implements ValidateTwoFieldTypes {
 
     @Override
     public void validateNotSamePerson(Person firstPerson, Person secondPerson, String firstPersonFieldName, String secondPersonFieldName, String message, BindingResult bindingResult) {
-        if (secondPerson != null && firstPerson == secondPerson) {
-            bindingResult.rejectValue(firstPersonFieldName, ApplicationConstants.EMPTY_STRING, null, message);
-            bindingResult.rejectValue(secondPersonFieldName, ApplicationConstants.EMPTY_STRING, null, message);
+        if (firstPerson != null) {
+            if (secondPerson != null) {
+                if (firstPerson.equals(secondPerson)) {
+                    bindingResult.rejectValue(firstPersonFieldName, ApplicationConstants.EMPTY_STRING, null, message);
+                    bindingResult.rejectValue(secondPersonFieldName, ApplicationConstants.EMPTY_STRING, null, message);
+                }
+            }
         }
     }