Sfoglia il codice sorgente

Divorce certificate Validator structure

Andrew Grant 3 mesi fa
parent
commit
0b00ed178c

+ 5 - 5
src/main/java/scot/carricksoftware/grants/controllers/certificates/divorcecertificates/DivorceCertificateFormControllerImpl.java

@@ -25,7 +25,7 @@ import scot.carricksoftware.grants.converters.certificates.divorcecertificates.D
 import scot.carricksoftware.grants.converters.certificates.divorcecertificates.DivorceCertificateConverterImpl;
 import scot.carricksoftware.grants.services.certificates.divorcecertificates.DivorceCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
-import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidator;
+import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidatorImpl;
 
 
 @SuppressWarnings("LoggingSimilarMessage")
@@ -37,20 +37,20 @@ public class DivorceCertificateFormControllerImpl implements DivorceCertificateF
     @SuppressWarnings({"FieldCanBeLocal", "unused"})
     private final DivorceCertificateCommandConverterImpl divorceCertificateCommandConverter;
     private final DivorceCertificateConverterImpl divorceCertificateConverter;
-    private final DivorceCertificateCommandValidator divorceCertificateCommandValidator;
+    private final DivorceCertificateCommandValidatorImpl divorceCertificateCommandValidatorImpl;
     private final PersonService personService;
 
 
     public DivorceCertificateFormControllerImpl(DivorceCertificateService divorceCertificateService,
                                                 DivorceCertificateCommandConverterImpl divorceCertificateCommandConverter,
                                                 DivorceCertificateConverterImpl divorceCertificateConverter,
-                                                DivorceCertificateCommandValidator divorceCertificateCommandValidator, PersonService personService) {
+                                                DivorceCertificateCommandValidatorImpl divorceCertificateCommandValidatorImpl, PersonService personService) {
         this.divorceCertificateService = divorceCertificateService;
         this.divorceCertificateCommandConverter = divorceCertificateCommandConverter;
 
 
         this.divorceCertificateConverter = divorceCertificateConverter;
-        this.divorceCertificateCommandValidator = divorceCertificateCommandValidator;
+        this.divorceCertificateCommandValidatorImpl = divorceCertificateCommandValidatorImpl;
         this.personService = personService;
     }
 
@@ -80,7 +80,7 @@ public class DivorceCertificateFormControllerImpl implements DivorceCertificateF
     public String saveOrUpdate(@Valid @ModelAttribute DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult, Model model) {
         logger.debug("DivorceCertificateFormControllerImpl::saveOrUpdate");
 
-        divorceCertificateCommandValidator.validate(divorceCertificateCommand, bindingResult);
+        divorceCertificateCommandValidatorImpl.validate(divorceCertificateCommand, bindingResult);
 
 
         if (bindingResult.hasErrors()) {

+ 19 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/divorcecertificate/DivorceCertificateCommandDatesValidator.java

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates.divorcecertificate;
+
+import org.springframework.stereotype.Component;
+import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.commands.certificates.divorcecertificates.DivorceCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
+
+
+@Component
+public interface DivorceCertificateCommandDatesValidator {
+
+    void validate(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult);
+}
+

+ 25 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/divorcecertificate/DivorceCertificateCommandDatesValidatorImpl.java

@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates.divorcecertificate;
+
+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.certificates.divorcecertificates.DivorceCertificateCommand;
+
+
+@Component
+public class DivorceCertificateCommandDatesValidatorImpl implements DivorceCertificateCommandDatesValidator {
+
+    private static final Logger logger = LogManager.getLogger(DivorceCertificateCommandDatesValidatorImpl.class);
+
+    @Override
+    public void validate(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult) {
+        logger.info("DivorceCertificateCommandPeopleValidator::validate");
+    }
+}
+

+ 19 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/divorcecertificate/DivorceCertificateCommandPeopleValidator.java

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates.divorcecertificate;
+
+import org.springframework.stereotype.Component;
+import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.commands.certificates.divorcecertificates.DivorceCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
+
+
+@Component
+public interface DivorceCertificateCommandPeopleValidator {
+
+    void validate(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult);
+}
+

+ 26 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/divorcecertificate/DivorceCertificateCommandPeopleValidatorImpl.java

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates.divorcecertificate;
+
+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.certificates.divorcecertificates.DivorceCertificateCommand;
+
+
+@Component
+public class DivorceCertificateCommandPeopleValidatorImpl implements DivorceCertificateCommandPeopleValidator {
+
+    private static final Logger logger = LogManager.getLogger(DivorceCertificateCommandPeopleValidatorImpl.class);
+
+    @Override
+    public void validate(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult) {
+        logger.info("DivorceCertificateCommandPeopleValidator::validate");
+
+    }
+}
+

+ 2 - 46
src/main/java/scot/carricksoftware/grants/validators/certificates/divorcecertificate/DivorceCertificateCommandValidator.java

@@ -5,57 +5,13 @@
 
 package scot.carricksoftware.grants.validators.certificates.divorcecertificate;
 
-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.certificates.divorcecertificates.DivorceCertificateCommand;
-import scot.carricksoftware.grants.constants.ApplicationConstants;
-import scot.carricksoftware.grants.constants.ValidationConstants;
-
 
 @Component
-public class DivorceCertificateCommandValidator {
-    private static final Logger logger = LogManager.getLogger(DivorceCertificateCommandValidator.class);
-
-    @SuppressWarnings("unused")
-    public void validate(@SuppressWarnings("unused") DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult) {
-        logger.debug("Validating death certificate command");
-        validateTheTwoPartiesInIsolation(divorceCertificateCommand, bindingResult);
-
-
-        if (divorceCertificateCommand.getFirstParty() != null &&
-                divorceCertificateCommand.getSecondParty() != null) {
-            validateThePartiesTogether(divorceCertificateCommand, bindingResult);
-        }
-
-    }
-
-    private void validateThePartiesTogether(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult) {
-        if (divorceCertificateCommand.getFirstParty().equals(divorceCertificateCommand.getSecondParty())) {
-            bindingResult.rejectValue("firstParty", ApplicationConstants.EMPTY_STRING,
-                    null,
-                    ValidationConstants.SAME_TWO_PARTIES);
-            bindingResult.rejectValue("secondParty", ApplicationConstants.EMPTY_STRING,
-                    null,
-                    ValidationConstants.SAME_TWO_PARTIES);
-        }
-    }
-
-    private void validateTheTwoPartiesInIsolation(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult) {
-        if (divorceCertificateCommand.getFirstParty() == null) {
-            bindingResult.rejectValue("firstParty", ApplicationConstants.EMPTY_STRING,
-                    null,
-                    ValidationConstants.FIRST_PARTY_IS_NULL);
-        }
-        if (divorceCertificateCommand.getSecondParty() == null) {
-            bindingResult.rejectValue("secondParty", ApplicationConstants.EMPTY_STRING,
-                    null,
-                    ValidationConstants.SECOND_PARTY_IS_NULL);
-        }
-
-    }
-
+public interface DivorceCertificateCommandValidator {
 
+    void validate(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult);
 }
 

+ 40 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/divorcecertificate/DivorceCertificateCommandValidatorImpl.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates.divorcecertificate;
+
+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.certificates.divorcecertificates.DivorceCertificateCommand;
+
+
+
+@Component
+public class DivorceCertificateCommandValidatorImpl implements DivorceCertificateCommandValidator {
+    private static final Logger logger = LogManager.getLogger(DivorceCertificateCommandValidatorImpl.class);
+
+    final DivorceCertificateCommandPeopleValidator divorceCertificateCommandPeopleValidator;
+
+    final DivorceCertificateCommandDatesValidator divorceCertificateCommandDatesValidator;
+
+    public DivorceCertificateCommandValidatorImpl(DivorceCertificateCommandPeopleValidator divorceCertificateCommandPeopleValidator,
+                                                  DivorceCertificateCommandDatesValidator divorceCertificateCommandDatesValidator) {
+        this.divorceCertificateCommandPeopleValidator = divorceCertificateCommandPeopleValidator;
+        this.divorceCertificateCommandDatesValidator = divorceCertificateCommandDatesValidator;
+    }
+
+
+    @Override
+    public void validate(DivorceCertificateCommand divorceCertificateCommand, BindingResult bindingResult) {
+        logger.info("DivorceCertificateCommandValidator::validate");
+        divorceCertificateCommandPeopleValidator.validate(divorceCertificateCommand, bindingResult);
+        divorceCertificateCommandDatesValidator.validate(divorceCertificateCommand, bindingResult);
+    }
+
+
+}
+

+ 3 - 3
src/test/java/scot/carricksoftware/grants/controllers/certificates/divorcecertificates/DivorceCertificateFormControllerSaveOrUpdateTest.java

@@ -18,7 +18,7 @@ import scot.carricksoftware.grants.converters.certificates.divorcecertificates.D
 import scot.carricksoftware.grants.converters.certificates.divorcecertificates.DivorceCertificateConverterImpl;
 import scot.carricksoftware.grants.services.certificates.divorcecertificates.DivorceCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
-import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidator;
+import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidatorImpl;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
@@ -51,7 +51,7 @@ public class DivorceCertificateFormControllerSaveOrUpdateTest {
     BindingResult bindingResultMock;
 
     @Mock
-    private DivorceCertificateCommandValidator divorceCertificateCommandValidatorMock;
+    private DivorceCertificateCommandValidatorImpl divorceCertificateCommandValidatorImplMock;
 
     private DivorceCertificateCommand divorceCertificateCommand;
 
@@ -61,7 +61,7 @@ public class DivorceCertificateFormControllerSaveOrUpdateTest {
         divorceCertificateController = new DivorceCertificateFormControllerImpl(divorceCertificateServiceMock,
                 divorceCertificateCommandConverterMock,
                 divorceCertificateConverterMock,
-                divorceCertificateCommandValidatorMock,
+                divorceCertificateCommandValidatorImplMock,
                 personServiceMock);
         divorceCertificateCommand = new DivorceCertificateCommandImpl();
     }

+ 3 - 3
src/test/java/scot/carricksoftware/grants/controllers/certificates/divorcecertificates/DivorceCertificateFormControllerTest.java

@@ -20,7 +20,7 @@ import scot.carricksoftware.grants.converters.certificates.divorcecertificates.D
 import scot.carricksoftware.grants.domains.certificates.DivorceCertificate;
 import scot.carricksoftware.grants.services.certificates.divorcecertificates.DivorceCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
-import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidator;
+import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidatorImpl;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -51,7 +51,7 @@ public class DivorceCertificateFormControllerTest {
     private Model modelMock;
 
     @Mock
-    private DivorceCertificateCommandValidator divorceCertificateCommandValidatorMock;
+    private DivorceCertificateCommandValidatorImpl divorceCertificateCommandValidatorImplMock;
 
 
     @BeforeEach
@@ -59,7 +59,7 @@ public class DivorceCertificateFormControllerTest {
         divorceCertificateFormController = new DivorceCertificateFormControllerImpl(divorceCertificateServiceMock,
                 divorceCertificateCommandConverterMock,
                 divorceCertificateConverterMock,
-                divorceCertificateCommandValidatorMock,
+                divorceCertificateCommandValidatorImplMock,
                 personServiceMock);
     }
 

+ 4 - 4
src/test/java/scot/carricksoftware/grants/controllers/certificates/divorcecertificates/DivorceCertificateFormControllerValidationTest.java

@@ -19,7 +19,7 @@ import scot.carricksoftware.grants.converters.certificates.divorcecertificates.D
 import scot.carricksoftware.grants.converters.certificates.divorcecertificates.DivorceCertificateConverterImpl;
 import scot.carricksoftware.grants.services.certificates.divorcecertificates.DivorceCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
-import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidator;
+import scot.carricksoftware.grants.validators.certificates.divorcecertificate.DivorceCertificateCommandValidatorImpl;
 
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -48,7 +48,7 @@ public class DivorceCertificateFormControllerValidationTest {
     private PersonService personServiceMock;
 
     @Mock
-    private DivorceCertificateCommandValidator divorceCertificateCommandValidatorMock;
+    private DivorceCertificateCommandValidatorImpl divorceCertificateCommandValidatorImplMock;
 
     @Mock
     private Model modelMock;
@@ -59,7 +59,7 @@ public class DivorceCertificateFormControllerValidationTest {
         divorceCertificateController = new DivorceCertificateFormControllerImpl(divorceCertificateServiceMock,
                 divorceCertificateCommandConverterMock,
                 divorceCertificateConverterMock,
-                divorceCertificateCommandValidatorMock,
+                divorceCertificateCommandValidatorImplMock,
                 personServiceMock);
     }
 
@@ -73,7 +73,7 @@ public class DivorceCertificateFormControllerValidationTest {
 
         divorceCertificateController.saveOrUpdate(divorceCertificateCommand, bindingResultMock, modelMock);
 
-        verify(divorceCertificateCommandValidatorMock).validate(divorceCertificateCommand, bindingResultMock);
+        verify(divorceCertificateCommandValidatorImplMock).validate(divorceCertificateCommand, bindingResultMock);
     }