Browse Source

When registered validated

Andrew Grant 5 months ago
parent
commit
8a7cb3d3b3

+ 3 - 0
src/main/java/scot/carricksoftware/grants/constants/ValidationConstants.java

@@ -48,6 +48,9 @@ public class ValidationConstants {
     public static final String BRIDE_IS_NULL = "The bride cannot be null.";
     public static final String GROOM_IS_NULL = "The groom cannot be null.";
     public static final String SAME_BRIDE_AND_GROOM = "The bride and groom cannot be the same person.";
+    public static final String WHEN_REGISTERED_DATE_IS_NULL = "When registered cannot be null.";
+    public static final String WHEN_REGISTERED_DATE_IS_INVALID = "When registered date is invalid.";
+    public static final String WHEN_REGISTERED_DATE_IN_FUTURE = "Date should not be in the future.";
 
     public static final String FIRST_PARTY_IS_NULL = "The first party cannot be null.";
     public static final String SECOND_PARTY_IS_NULL = "The second party cannot be null.";

+ 11 - 0
src/main/java/scot/carricksoftware/grants/validators/certificates/birthcertificate/BirthCertificateCommandPartThreeValidatorImpl.java

@@ -33,6 +33,7 @@ public class BirthCertificateCommandPartThreeValidatorImpl implements BirthCerti
         validateWhenBorn(birthCertificateCommand, bindingResult);
         validateFatherAndUntrackedFather(birthCertificateCommand, bindingResult);
         validateWhereBornAndUntrackedWhereBorn(birthCertificateCommand, bindingResult);
+        validateWhenRegistered(birthCertificateCommand, bindingResult);
     }
 
 
@@ -62,4 +63,14 @@ public class BirthCertificateCommandPartThreeValidatorImpl implements BirthCerti
                 "whereBorn", "untrackedWhereBorn", ValidationConstants.WHERE_BORN_AND_UNTRACKED_WHERE_BORN,bindingResult);
     }
 
+    private void validateWhenRegistered(BirthCertificateCommand birthCertificateCommand, BindingResult bindingResult) {
+        logger.debug("Validating birth certificate Registration Date");
+        validateTypes.validatePastDate(birthCertificateCommand.getWhenRegistered(),
+                "whenRegistered",
+                ValidationConstants.WHEN_REGISTERED_DATE_IS_NULL,
+                ValidationConstants.WHEN_REGISTERED_DATE_IS_INVALID,
+                ValidationConstants.WHEN_REGISTERED_DATE_IN_FUTURE,
+                bindingResult);
+    }
+
 }

+ 5 - 0
src/main/resources/templates/certificates/birthCertificate/form.html

@@ -326,6 +326,11 @@
                         <input class="whenRegistered" id="whenRegistered"
                                th:field="*{whenRegistered}" type="text">
                     </div>
+                    <div th:if="${#fields.hasErrors('whenRegistered')}">
+                        <ul class="text-danger">
+                            <li th:each="err : ${#fields.errors('whenRegistered')}" th:text="${err}"/>
+                        </ul>
+                    </div>
                 </td>
             </tr>
             <tr style = "border-bottom: 5px solid #ccc;">