浏览代码

CertificateDate changed to String

Andrew Grant 6 月之前
父节点
当前提交
8a1c2010df
共有 14 个文件被更改,包括 47 次插入45 次删除
  1. 1 4
      src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificates.java
  2. 2 4
      src/main/java/scot/carricksoftware/grants/commands/certificates/birthcertificates/BirthCertificateCommand.java
  3. 3 5
      src/main/java/scot/carricksoftware/grants/commands/certificates/birthcertificates/BirthCertificateCommandImpl.java
  4. 1 0
      src/main/java/scot/carricksoftware/grants/constants/ApplicationConstants.java
  5. 10 1
      src/main/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerImpl.java
  6. 6 8
      src/main/java/scot/carricksoftware/grants/domains/certificates/BaseCertificate.java
  7. 1 4
      src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesTest.java
  8. 1 4
      src/test/java/scot/carricksoftware/grants/commands/certificates/BirthCertificateCommandImplTest.java
  9. 7 1
      src/test/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerSaveOrUpdateTest.java
  10. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerTest.java
  11. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerValidationTest.java
  12. 1 4
      src/test/java/scot/carricksoftware/grants/converters/certificates/birthcertificates/BirthCertificateCommandConverterTest.java
  13. 1 4
      src/test/java/scot/carricksoftware/grants/converters/certificates/birthcertificates/BirthCertificateConverterTest.java
  14. 1 4
      src/test/java/scot/carricksoftware/grants/domains/certificates/BirthCertificateTest.java

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

@@ -18,9 +18,6 @@ import scot.carricksoftware.grants.services.certificates.deathcertificates.Death
 import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
 
-import java.sql.Date;
-import java.time.LocalDate;
-
 @Component
 @Profile("dev")
 public class DataLoadCertificates {
@@ -51,7 +48,7 @@ public class DataLoadCertificates {
     private void loadBirthCertificates() {
         BirthCertificateCommand birthCertificateCommand = new BirthCertificateCommandImpl();
         birthCertificateCommand.setNewBorn(personService.findById(1L));
-        birthCertificateCommand.setCertificateDate(Date.valueOf(LocalDate.now()));
+        birthCertificateCommand.setCertificateDate("25/01/1953");
         birthCertificateCommand.setCertificateNumber("999");
         Place place = placeService.findById(1L);
 

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

@@ -8,8 +8,6 @@ package scot.carricksoftware.grants.commands.certificates.birthcertificates;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-
 public interface BirthCertificateCommand {
 
 
@@ -34,8 +32,8 @@ public interface BirthCertificateCommand {
     void setCertificateIssuedAt(Place certificateIssuedAt);
 
     @SuppressWarnings("unused")
-    Date getCertificateDate();
+    String getCertificateDate();
 
     @SuppressWarnings("unused")
-    void setCertificateDate(Date certificateDate);
+    void setCertificateDate(String certificateDate);
 }

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

@@ -8,8 +8,6 @@ package scot.carricksoftware.grants.commands.certificates.birthcertificates;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-
 public class BirthCertificateCommandImpl implements BirthCertificateCommand {
 
     Long Id;
@@ -20,7 +18,7 @@ public class BirthCertificateCommandImpl implements BirthCertificateCommand {
 
     private Place certificateIssuedAt;
 
-    private Date certificateDate;
+    private String certificateDate;
 
     public Long getId() {
         return Id;
@@ -61,12 +59,12 @@ public class BirthCertificateCommandImpl implements BirthCertificateCommand {
     }
 
     @Override
-    public Date getCertificateDate() {
+    public String getCertificateDate() {
         return certificateDate;
     }
 
     @Override
-    public void setCertificateDate(Date certificateDate) {
+    public void setCertificateDate(String certificateDate) {
         this.certificateDate = certificateDate;
     }
 }

+ 1 - 0
src/main/java/scot/carricksoftware/grants/constants/ApplicationConstants.java

@@ -19,6 +19,7 @@ public class ApplicationConstants {
 
     public static final int DEFAULT_PAGE_SIZE = 15;
     public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yyyy");
+    public static final String DATE_TIME_FORMAT = "dd-MM-yyyy";
     public final static String EMPTY_STRING = "";
 
     public static final int MINIMUM_NAME_LENGTH = 3;

+ 10 - 1
src/main/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerImpl.java

@@ -25,6 +25,7 @@ import scot.carricksoftware.grants.converters.certificates.birthcertificates.Bir
 import scot.carricksoftware.grants.converters.certificates.birthcertificates.BirthCertificateConverterImpl;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
 import scot.carricksoftware.grants.validators.certificates.BirthCertificateCommandValidator;
 
 @SuppressWarnings("LoggingSimilarMessage")
@@ -38,13 +39,15 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
     private final BirthCertificateConverterImpl birthCertificateConverter;
     private final BirthCertificateCommandValidator birthCertificateCommandValidator;
     private final PersonService personService;
+    private final PlaceService placeService;
 
 
     public BirthCertificateFormControllerImpl(BirthCertificateService birthCertificateService,
                                               BirthCertificateCommandConverterImpl birthCertificateCommandConverter,
                                               BirthCertificateConverterImpl birthCertificateConverter,
                                               BirthCertificateCommandValidator birthCertificateCommandValidator,
-                                              PersonService personService) {
+                                              PersonService personService,
+                                              PlaceService placeService) {
         this.birthCertificateService = birthCertificateService;
         this.birthCertificateCommandConverter = birthCertificateCommandConverter;
 
@@ -52,6 +55,7 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
         this.birthCertificateConverter = birthCertificateConverter;
         this.birthCertificateCommandValidator = birthCertificateCommandValidator;
         this.personService = personService;
+        this.placeService = placeService;
     }
 
     @SuppressWarnings("SameReturnValue")
@@ -61,6 +65,7 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
         logger.debug("BirthCertificateFormControllerImpl::getNewBirthCertificate");
         model.addAttribute(AttributeConstants.BIRTH_CERTIFICATE_COMMAND, new BirthCertificateCommandImpl());
         model.addAttribute(AttributeConstants.PEOPLE, personService.findAll());
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return ViewConstants.BIRTH_CERTIFICATE_FORM;
     }
 
@@ -71,6 +76,7 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
         logger.debug("BirthCertificateFormControllerImpl::birthCertificateEdit");
         model.addAttribute(AttributeConstants.BIRTH_CERTIFICATE_COMMAND, birthCertificateService.findById(Long.valueOf(id)));
         model.addAttribute(AttributeConstants.PEOPLE, personService.findAll());
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return ViewConstants.BIRTH_CERTIFICATE_FORM;
     }
 
@@ -86,12 +92,14 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
         if (bindingResult.hasErrors()) {
             bindingResult.getAllErrors().forEach(error -> logger.debug(error.getDefaultMessage()));
             model.addAttribute(AttributeConstants.PEOPLE, personService.findAll());
+            model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
             return ViewConstants.BIRTH_CERTIFICATE_FORM;
         }
 
         BirthCertificateCommand savedCommand = birthCertificateService.saveBirthCertificateCommand(birthCertificateCommand);
         model.addAttribute(AttributeConstants.BIRTH_CERTIFICATE_COMMAND, savedCommand);
         model.addAttribute(AttributeConstants.PEOPLE, personService.findAll());
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return MappingConstants.REDIRECT + CertificateMappingConstants.BIRTH_CERTIFICATE_SHOW.replace("{id}", "" + savedCommand.getId());
     }
 
@@ -104,6 +112,7 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
         BirthCertificateCommand savedCommand = birthCertificateConverter.convert(birthCertificateService.findById(Long.valueOf(id)));
         model.addAttribute(AttributeConstants.BIRTH_CERTIFICATE_COMMAND, savedCommand);
         model.addAttribute(AttributeConstants.PEOPLE, personService.findAll());
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return ViewConstants.BIRTH_CERTIFICATE_FORM;
     }
 

+ 6 - 8
src/main/java/scot/carricksoftware/grants/domains/certificates/BaseCertificate.java

@@ -10,13 +10,11 @@ import jakarta.persistence.Column;
 import jakarta.persistence.JoinColumn;
 import jakarta.persistence.ManyToOne;
 import jakarta.persistence.MappedSuperclass;
-import jakarta.persistence.Temporal;
-import jakarta.persistence.TemporalType;
+import org.springframework.format.annotation.DateTimeFormat;
 import scot.carricksoftware.grants.BaseEntity;
+import scot.carricksoftware.grants.constants.ApplicationConstants;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-
 
 @MappedSuperclass
 public class BaseCertificate extends BaseEntity {
@@ -29,8 +27,8 @@ public class BaseCertificate extends BaseEntity {
     private Place certificateIssuedAt;
 
     @Column(name= "`certificate_date`")
-    @Temporal(TemporalType.DATE)
-    private Date certificateDate;
+    @DateTimeFormat(pattern = ApplicationConstants.DATE_TIME_FORMAT)
+    private String certificateDate;
 
     @SuppressWarnings("unused")
     public String getCertificateNumber() {
@@ -53,12 +51,12 @@ public class BaseCertificate extends BaseEntity {
     }
 
     @SuppressWarnings("unused")
-    public Date getCertificateDate() {
+    public String getCertificateDate() {
         return certificateDate;
     }
 
     @SuppressWarnings("unused")
-    public void setCertificateDate(Date certificateDate) {
+    public void setCertificateDate(String certificateDate) {
         this.certificateDate = certificateDate;
     }
 }

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

@@ -15,9 +15,6 @@ import scot.carricksoftware.grants.services.certificates.deathcertificates.Death
 import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
 
-import java.sql.Date;
-import java.time.LocalDate;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -65,7 +62,7 @@ public class DataLoadCertificatesTest {
         assertEquals(person, captor.getValue().getNewBorn());
         assertEquals(place, captor.getValue().getCertificateIssuedAt());
         assertEquals("999", captor.getValue().getCertificateNumber());
-        assertEquals(Date.valueOf(LocalDate.now()), captor.getValue().getCertificateDate());
+        assertEquals("25/01/1953", captor.getValue().getCertificateDate());
     }
 
     @Test

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

@@ -12,9 +12,6 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-import java.time.LocalDate;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
@@ -73,7 +70,7 @@ class BirthCertificateCommandImplTest {
 
     @Test
     void setCertificateDateTest() {
-        Date certificateDate = Date.valueOf(LocalDate.now());
+        String certificateDate = GetRandomString();
         command.setCertificateDate(certificateDate);
         assertEquals(certificateDate, command.getCertificateDate());
     }

+ 7 - 1
src/test/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerSaveOrUpdateTest.java

@@ -18,6 +18,7 @@ import scot.carricksoftware.grants.converters.certificates.birthcertificates.Bir
 import scot.carricksoftware.grants.converters.certificates.birthcertificates.BirthCertificateConverterImpl;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
 import scot.carricksoftware.grants.validators.certificates.BirthCertificateCommandValidator;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -43,6 +44,10 @@ public class BirthCertificateFormControllerSaveOrUpdateTest {
     @Mock
     private PersonService personServiceMock;
 
+    @Mock
+    private PlaceService placeServiceMock;
+
+
 
     @Mock
     Model modelMock;
@@ -62,7 +67,8 @@ public class BirthCertificateFormControllerSaveOrUpdateTest {
                 birthCertificateCommandConverterMock,
                 birthCertificateConverterMock,
                 birthCertificateCommandValidatorMock,
-                personServiceMock);
+                personServiceMock,
+                placeServiceMock);
         birthCertificateCommand = new BirthCertificateCommandImpl();
     }
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerTest.java

@@ -20,6 +20,7 @@ import scot.carricksoftware.grants.converters.certificates.birthcertificates.Bir
 import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
 import scot.carricksoftware.grants.validators.certificates.BirthCertificateCommandValidator;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -48,6 +49,9 @@ public class BirthCertificateFormControllerTest {
     @Mock
     private PersonService personServiceMock;
 
+    @Mock
+    private PlaceService placeServiceMock;
+
     @Mock
     private Model modelMock;
 
@@ -61,7 +65,8 @@ public class BirthCertificateFormControllerTest {
                 birthCertificateCommandConverterMock,
                 birthCertificateConverterMock,
                 birthCertificateCommandValidatorMock,
-                personServiceMock);
+                personServiceMock,
+                placeServiceMock);
     }
 
     @Test

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerValidationTest.java

@@ -19,6 +19,7 @@ import scot.carricksoftware.grants.converters.certificates.birthcertificates.Bir
 import scot.carricksoftware.grants.converters.certificates.birthcertificates.BirthCertificateConverterImpl;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
 import scot.carricksoftware.grants.validators.certificates.BirthCertificateCommandValidator;
 
 import static org.mockito.Mockito.verify;
@@ -47,6 +48,9 @@ public class BirthCertificateFormControllerValidationTest {
     @Mock
     private PersonService personServiceMock;
 
+    @Mock
+    private PlaceService placeServiceMock;
+
     @Mock
     private BirthCertificateCommandValidator birthCertificateCommandValidatorMock;
 
@@ -60,7 +64,8 @@ public class BirthCertificateFormControllerValidationTest {
                 birthCertificateCommandConverterMock,
                 birthCertificateConverterMock,
                 birthCertificateCommandValidatorMock,
-                personServiceMock);
+                personServiceMock,
+                placeServiceMock);
     }
 
 

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

@@ -14,11 +14,8 @@ import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
-import static scot.carricksoftware.grants.GenerateRandomDateValues.GetRandomDate;
 import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
 import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
@@ -39,7 +36,7 @@ class BirthCertificateCommandConverterTest {
         BirthCertificateCommand source = new BirthCertificateCommandImpl();
         Place issuedAt = GetRandomPlace();
         String certificateNumber = GetRandomString();
-        Date certificateDate = GetRandomDate();
+        String certificateDate = GetRandomString();
 
         source.setId(id);
         source.setNewBorn(person);

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

@@ -13,11 +13,8 @@ import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
-import static scot.carricksoftware.grants.GenerateRandomDateValues.GetRandomDate;
 import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
 import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
@@ -38,7 +35,7 @@ class BirthCertificateConverterTest {
         BirthCertificate source = new BirthCertificate();
         Place issuedAt = GetRandomPlace();
         String certificateNumber = GetRandomString();
-        Date certificateDate = GetRandomDate();
+        String certificateDate = GetRandomString();
 
         source.setId(id);
         source.setNewBorn(person);

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

@@ -10,9 +10,6 @@ import org.junit.jupiter.api.Test;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.sql.Date;
-import java.time.LocalDate;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
@@ -72,7 +69,7 @@ class BirthCertificateTest {
 
     @Test
     void setCertificateDateTest() {
-        Date certificateDate = Date.valueOf(LocalDate.now());
+        String certificateDate = GetRandomString();
         certificate.setCertificateDate(certificateDate);
         assertEquals(certificateDate, certificate.getCertificateDate());
     }