Procházet zdrojové kódy

CertificateType added to form

Andrew Grant před 6 měsíci
rodič
revize
2d6c3b4200
16 změnil soubory, kde provedl 80 přidání a 30 odebrání
  1. 2 1
      src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificates.java
  2. 3 2
      src/main/java/scot/carricksoftware/grants/commands/certificates/birthcertificates/BirthCertificateCommand.java
  3. 4 3
      src/main/java/scot/carricksoftware/grants/commands/certificates/birthcertificates/BirthCertificateCommandImpl.java
  4. 2 1
      src/main/java/scot/carricksoftware/grants/constants/ValidationConstants.java
  5. 4 3
      src/main/java/scot/carricksoftware/grants/domains/certificates/BaseCertificate.java
  6. 19 0
      src/main/java/scot/carricksoftware/grants/enums/certificates/CertificateType.java
  7. 15 5
      src/main/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidator.java
  8. 8 7
      src/main/resources/templates/certificates/birthCertificate/form.html
  9. 2 1
      src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesTest.java
  10. 2 1
      src/test/java/scot/carricksoftware/grants/commands/certificates/BirthCertificateCommandImplTest.java
  11. 2 1
      src/test/java/scot/carricksoftware/grants/converters/certificates/birthcertificates/BirthCertificateCommandConverterTest.java
  12. 2 1
      src/test/java/scot/carricksoftware/grants/converters/certificates/birthcertificates/BirthCertificateConverterTest.java
  13. 4 2
      src/test/java/scot/carricksoftware/grants/domains/certificates/BirthCertificateTest.java
  14. 5 1
      src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorCertificateTest.java
  15. 4 0
      src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorDateTest.java
  16. 2 1
      src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorPersonTest.java

+ 2 - 1
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificates.java

@@ -13,6 +13,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
 import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
@@ -51,7 +52,7 @@ public class DataLoadCertificates {
         birthCertificateCommand.setNewBorn(personService.findById(1L));
         birthCertificateCommand.setCertificateDate("25/01/1953");
         birthCertificateCommand.setCertificateNumber("999");
-        birthCertificateCommand.setCertificateType("extract");
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
 
         Organisation organisation = organisationService.findById(1L);
         birthCertificateCommand.setCertificateSource(organisation);

+ 3 - 2
src/main/java/scot/carricksoftware/grants/commands/certificates/birthcertificates/BirthCertificateCommand.java

@@ -7,6 +7,7 @@ package scot.carricksoftware.grants.commands.certificates.birthcertificates;
 
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 public interface BirthCertificateCommand {
 
@@ -36,7 +37,7 @@ public interface BirthCertificateCommand {
     @SuppressWarnings("unused")
     void setCertificateDate(String certificateDate);
 
-    String getCertificateType();
+    CertificateType getCertificateType();
 
-    void setCertificateType(String certificateType);
+    void setCertificateType(CertificateType certificateType);
 }

+ 4 - 3
src/main/java/scot/carricksoftware/grants/commands/certificates/birthcertificates/BirthCertificateCommandImpl.java

@@ -7,6 +7,7 @@ package scot.carricksoftware.grants.commands.certificates.birthcertificates;
 
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 public class BirthCertificateCommandImpl implements BirthCertificateCommand {
 
@@ -20,7 +21,7 @@ public class BirthCertificateCommandImpl implements BirthCertificateCommand {
 
     private String certificateDate;
 
-    private String certificateType;
+    private CertificateType certificateType;
 
     public Long getId() {
         return Id;
@@ -72,12 +73,12 @@ public class BirthCertificateCommandImpl implements BirthCertificateCommand {
     }
 
     @Override
-    public String getCertificateType() {
+    public CertificateType getCertificateType() {
         return certificateType;
     }
 
     @Override
-    public void setCertificateType(String certificateType) {
+    public void setCertificateType(CertificateType certificateType) {
         this.certificateType = certificateType;
     }
 }

+ 2 - 1
src/main/java/scot/carricksoftware/grants/constants/ValidationConstants.java

@@ -27,8 +27,9 @@ public class ValidationConstants {
     public static final String PERSON_IS_NULL = "The person cannot be null.";
     public static final String NEWBORN_IS_NULL = "The New Born cannot be null.";
     public static final String CERTIFICATE_NUMBER_IS_NULL = "The certificate number cannot be null.";
-    public static final String ISSUED_AT_IS_NULL = "The certificate source cannot be null.";
+    public static final String SOURCE_IS_NULL = "The certificate source cannot be null.";
     public static final String CERTIFICATE_DATE_IS_NULL = "The certificate date cannot be null.";
+    public static final String CERTIFICATE_TYPE_IS_NULL = "The certificate type cannot be null.";
     public static final String DATE_IS_INVALID = "The certificate date is invalid or of the wrong format.";
 
     public static final String PLACE_IS_NULL = "The place cannot be null.";

+ 4 - 3
src/main/java/scot/carricksoftware/grants/domains/certificates/BaseCertificate.java

@@ -14,6 +14,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 import scot.carricksoftware.grants.BaseEntity;
 import scot.carricksoftware.grants.constants.ApplicationConstants;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 
 @MappedSuperclass
@@ -23,7 +24,7 @@ public class BaseCertificate extends BaseEntity {
     private String certificateNumber;
 
     @Column(name = "`certificate_type`")
-    private String certificateType;
+    private CertificateType certificateType;
 
     @ManyToOne
     @JoinColumn(name = "`organisation_id`")
@@ -62,11 +63,11 @@ public class BaseCertificate extends BaseEntity {
         this.certificateSource = organisation;
     }
 
-    public String getCertificateType() {
+    public CertificateType getCertificateType() {
         return certificateType;
     }
 
-    public void setCertificateType(String certificateType) {
+    public void setCertificateType(CertificateType certificateType) {
         this.certificateType = certificateType;
     }
 }

+ 19 - 0
src/main/java/scot/carricksoftware/grants/enums/certificates/CertificateType.java

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.enums.certificates;
+
+public enum CertificateType {
+
+    @SuppressWarnings("unused") EXTRACT("Extract");
+
+    @SuppressWarnings("unused")
+    public final String label;
+
+    @SuppressWarnings({"unused", "SameParameterValue"})
+    CertificateType(String label) {
+        this.label = label;
+    }
+}

+ 15 - 5
src/main/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidator.java

@@ -25,7 +25,8 @@ public class BirthCertificateCommandValidator {
 
         validateNewBorn(birthCertificateCommand, bindingResult);
         validateCertificateNumber(birthCertificateCommand, bindingResult);
-        validateCertificateIssuedAt(birthCertificateCommand, bindingResult);
+        validateCertificateSource(birthCertificateCommand, bindingResult);
+        validateCertificateType(birthCertificateCommand, bindingResult);
         validateCertificateDate(birthCertificateCommand, bindingResult);
         if (!bindingResult.hasErrors()) {
             validateCertificateLegitimateDate(birthCertificateCommand, bindingResult);
@@ -50,12 +51,21 @@ public class BirthCertificateCommandValidator {
         }
     }
 
-    private void validateCertificateIssuedAt(BirthCertificateCommand birthCertificateCommand, BindingResult bindingResult) {
-        logger.debug("Validating birth certificate Certificate Issued At");
+    private void validateCertificateSource(BirthCertificateCommand birthCertificateCommand, BindingResult bindingResult) {
+        logger.debug("Validating birth certificate Certificate Source");
         if (birthCertificateCommand.getCertificateSource() == null ) {
-            bindingResult.rejectValue("certificateIssuedAt", ApplicationConstants.EMPTY_STRING,
+            bindingResult.rejectValue("certificateSource", ApplicationConstants.EMPTY_STRING,
                     null,
-                    ValidationConstants.ISSUED_AT_IS_NULL);
+                    ValidationConstants.SOURCE_IS_NULL);
+        }
+    }
+
+    private void validateCertificateType(BirthCertificateCommand birthCertificateCommand, BindingResult bindingResult) {
+        logger.debug("Validating birth certificate Certificate Type");
+        if (birthCertificateCommand.getCertificateType() == null ) {
+            bindingResult.rejectValue("certificateType", ApplicationConstants.EMPTY_STRING,
+                    null,
+                    ValidationConstants.CERTIFICATE_TYPE_IS_NULL);
         }
     }
 

+ 8 - 7
src/main/resources/templates/certificates/birthCertificate/form.html

@@ -56,7 +56,7 @@
             </tr>
             <tr>
                 <td style="text-align: right;">
-                    <label for="certificateSource">Issued From&nbsp;</label>
+                    <label for="certificateSource">Certificate Source&nbsp;</label>
                 </td>
                 <td style="text-align: left;">
                     <div>
@@ -92,12 +92,13 @@
                     <label for="certificateType">Certificate Type&nbsp;</label>
                 </td>
                 <td style="text-align: left;">
-                    <input class="form-control" id="certificateType"
-                           th:field="*{certificateType}" type="text">
-                    <div th:if="${#fields.hasErrors('certificateType')}">
-                        <ul class="text-danger">
-                            <li th:each="err : ${#fields.errors('certificateType')}" th:text="${err}"/>
-                        </ul>
+                    <div>
+                        <select id="certificateType" style="width: 200px;" name="certificateType"
+                                th:field="*{certificateType}">
+                            <option th:value="${''}" th:text="${''}"></option>
+                            <option th:each="value : ${T(scot.carricksoftware.grants.enums.certificates.CertificateType).values()}"
+                                    th:value="${value}" th:text="${value.label}"></option>
+                        </select>
                     </div>
                 </td>
             </tr>

+ 2 - 1
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesTest.java

@@ -10,6 +10,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
@@ -63,7 +64,7 @@ public class DataLoadCertificatesTest {
         assertEquals(organisation, captor.getValue().getCertificateSource());
         assertEquals("999", captor.getValue().getCertificateNumber());
         assertEquals("25/01/1953", captor.getValue().getCertificateDate());
-        assertEquals("extract", captor.getValue().getCertificateType());
+        assertEquals(CertificateType.EXTRACT, captor.getValue().getCertificateType());
     }
 
     @Test

+ 2 - 1
src/test/java/scot/carricksoftware/grants/commands/certificates/BirthCertificateCommandImplTest.java

@@ -11,6 +11,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -89,7 +90,7 @@ class BirthCertificateCommandImplTest {
 
     @Test
     void setCertificateTypeTest() {
-        String certificateType = GetRandomString();
+        CertificateType certificateType = CertificateType.EXTRACT;
         command.setCertificateType(certificateType);
         assertEquals(certificateType, command.getCertificateType());
     }

+ 2 - 1
src/test/java/scot/carricksoftware/grants/converters/certificates/birthcertificates/BirthCertificateCommandConverterTest.java

@@ -13,6 +13,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
@@ -37,7 +38,7 @@ class BirthCertificateCommandConverterTest {
         Organisation issuedAt = GetRandomOrganisation();
         String certificateNumber = GetRandomString();
         String certificateDate = GetRandomString();
-        String certificateType = GetRandomString();
+        CertificateType certificateType = CertificateType.EXTRACT;
 
 
         source.setId(id);

+ 2 - 1
src/test/java/scot/carricksoftware/grants/converters/certificates/birthcertificates/BirthCertificateConverterTest.java

@@ -12,6 +12,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
@@ -36,7 +37,7 @@ class BirthCertificateConverterTest {
         Organisation certificateSource = GetRandomOrganisation();
         String certificateNumber = GetRandomString();
         String certificateDate = GetRandomString();
-        String certificateType = GetRandomString();
+        CertificateType certificateType = CertificateType.EXTRACT;
 
         source.setId(id);
         source.setNewBorn(person);

+ 4 - 2
src/test/java/scot/carricksoftware/grants/domains/certificates/BirthCertificateTest.java

@@ -9,6 +9,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -86,11 +87,12 @@ class BirthCertificateTest {
         assertNull(certificate.getCertificateType());
     }
 
+    @SuppressWarnings("unused")
     @Test
     void setCertificateTypeTest() {
         String certificateType = GetRandomString();
-        certificate.setCertificateType(certificateType);
-        assertEquals(certificateType, certificate.getCertificateType());
+        certificate.setCertificateType(CertificateType.EXTRACT);
+        assertEquals(CertificateType.EXTRACT, certificate.getCertificateType());
     }
 
 

+ 5 - 1
src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorCertificateTest.java

@@ -15,6 +15,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
@@ -53,6 +54,7 @@ class BirthCertificateCommandValidatorCertificateTest {
     public void certificateNumberTest() {
         birthCertificateCommand.setNewBorn(GetRandomPerson());
         birthCertificateCommand.setCertificateDate("25/01/1953");
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
 
         commandValidator.validate(birthCertificateCommand, bindingResultMock);
@@ -71,6 +73,7 @@ class BirthCertificateCommandValidatorCertificateTest {
     public void certificateSourceTest() {
         birthCertificateCommand.setNewBorn(GetRandomPerson());
         birthCertificateCommand.setCertificateNumber(GetRandomString());
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateDate("25/01/1953");
 
         commandValidator.validate(birthCertificateCommand, bindingResultMock);
@@ -80,7 +83,7 @@ class BirthCertificateCommandValidatorCertificateTest {
                 objectArgumentCaptor.capture(),
                 stringArgumentCaptor3.capture());
 
-        assertEquals("certificateIssuedAt", stringArgumentCaptor.getValue());
+        assertEquals("certificateSource", stringArgumentCaptor.getValue());
         assertEquals("The certificate source cannot be null.", stringArgumentCaptor3.getValue());
     }
 
@@ -89,6 +92,7 @@ class BirthCertificateCommandValidatorCertificateTest {
         birthCertificateCommand.setNewBorn(GetRandomPerson());
         birthCertificateCommand.setCertificateNumber(GetRandomString());
         birthCertificateCommand.setCertificateDate(GetRandomString());
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
 
         when(bindingResultMock.hasErrors()).thenReturn(false);

+ 4 - 0
src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorDateTest.java

@@ -15,6 +15,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
@@ -55,6 +56,7 @@ class BirthCertificateCommandValidatorDateTest {
         birthCertificateCommand.setNewBorn(GetRandomPerson());
         birthCertificateCommand.setCertificateNumber(GetRandomString());
         birthCertificateCommand.setCertificateDate(GetRandomString());
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
 
         when(bindingResultMock.hasErrors()).thenReturn(false);
@@ -74,6 +76,7 @@ class BirthCertificateCommandValidatorDateTest {
         birthCertificateCommand.setNewBorn(GetRandomPerson());
         birthCertificateCommand.setCertificateNumber(GetRandomString());
         birthCertificateCommand.setCertificateDate("01/01/2099");
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
 
         when(bindingResultMock.hasErrors()).thenReturn(false);
@@ -92,6 +95,7 @@ class BirthCertificateCommandValidatorDateTest {
     public void certificateNullDateTest() {
         birthCertificateCommand.setNewBorn(GetRandomPerson());
         birthCertificateCommand.setCertificateNumber(GetRandomString());
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
 
         when(bindingResultMock.hasErrors()).thenReturn(false);

+ 2 - 1
src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorPersonTest.java

@@ -15,6 +15,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
@@ -50,8 +51,8 @@ class BirthCertificateCommandValidatorPersonTest {
         birthCertificateCommand = new BirthCertificateCommandImpl();
         birthCertificateCommand.setCertificateDate("25/01/1953");
         birthCertificateCommand.setCertificateNumber("1953");
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
         birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
-
     }
 
     @Test