Эх сурвалжийг харах

GatherBirthCertificateNewBornTimeLineData

Andrew Grant 2 сар өмнө
parent
commit
5f5462b984

+ 4 - 1
docs/Structure.txt

@@ -7,4 +7,7 @@ personSection::write -> (personSectionHeader::write, clearExistingTimeLineData::
            personSubSectionTimeLineWriter::write, personSubSectionReferencesWriter::write
 
 
-gatherTimeLineData::gather -> (gatherCensusTimeLineData::gather, GatherBirthCertificateTimeLineData::gather)
+gatherTimeLineData::gather -> (gatherCensusTimeLineData::gather, GatherBirthCertificateTimeLineData::gather)
+
+
+GatherBirthCertificateTimeLineData::gather -> (GatherBirthCertificateNewBornTimeLineData::gather,  )

+ 48 - 0
src/main/java/scot/carricksoftware/grantswriter/domains/certificates/birthcertificate/BirthCertificate.java

@@ -5,11 +5,15 @@
 
 package scot.carricksoftware.grantswriter.domains.certificates.birthcertificate;
 
+import jakarta.persistence.Column;
 import jakarta.persistence.Entity;
 import jakarta.persistence.JoinColumn;
 import jakarta.persistence.ManyToOne;
+import org.springframework.format.annotation.DateTimeFormat;
 import scot.carricksoftware.grantswriter.BaseEntity;
+import scot.carricksoftware.grantswriter.constants.ApplicationConstants;
 import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.domains.places.Place;
 
 @Entity
 public class BirthCertificate extends BaseEntity {
@@ -34,6 +38,29 @@ public class BirthCertificate extends BaseEntity {
     @JoinColumn(name = "`informant_id`")
     private Person informant;
 
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @Column(name = "`when_born`")
+    @DateTimeFormat(pattern = ApplicationConstants.DATE_TIME_FORMAT)
+    private String whenBorn;
+
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @ManyToOne
+    @JoinColumn(name = "`where_born_id`")
+    private Place whereBorn;
+
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @Column(name = "`untracked_where_born`")
+    private String untrackedWhereBorn;
+
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @Column(name = "`when_registered`")
+    private String whenRegistered;
+
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @Column(name = "`where_registered`")
+    private String whereRegistered;
+
+
     public Person getNewBorn() {
         return newBorn;
     }
@@ -65,4 +92,25 @@ public class BirthCertificate extends BaseEntity {
     public void setInformant(Person informant) {
         this.informant = informant;
     }
+
+    public String getWhenBorn() {
+        return whenBorn;
+    }
+
+
+    public Place getWhereBorn() {
+        return whereBorn;
+    }
+
+    public String getUntrackedWhereBorn() {
+        return untrackedWhereBorn;
+    }
+
+    public String getWhenRegistered() {
+        return whenRegistered;
+    }
+
+    public String getWhereRegistered() {
+        return whereRegistered;
+    }
 }

+ 3 - 1
src/main/java/scot/carricksoftware/grantswriter/repositories/certificates/birthcertificate/BirthCertificateRepository.java

@@ -7,10 +7,12 @@ package scot.carricksoftware.grantswriter.repositories.certificates.birthcertifi
 
 import org.springframework.stereotype.Repository;
 import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.BirthCertificate;
+import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.repositories.ReadOnlyRepository;
 
 @SuppressWarnings("unused")
 @Repository
 public interface BirthCertificateRepository extends ReadOnlyRepository<BirthCertificate, Long> {
-    
+
+    Iterable<BirthCertificate> findAllByNewBorn(Person person);
 }

+ 6 - 0
src/main/java/scot/carricksoftware/grantswriter/services/certificates/birthcertificate/BirthCertificateService.java

@@ -6,6 +6,12 @@
 package scot.carricksoftware.grantswriter.services.certificates.birthcertificate;
 
 
+import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.BirthCertificate;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
+import java.util.List;
+
 public interface BirthCertificateService {
 
+    List<BirthCertificate> findAllByNewBorn(Person person);
 }

+ 26 - 0
src/main/java/scot/carricksoftware/grantswriter/services/certificates/birthcertificate/BirthCertificateServiceImpl.java

@@ -5,9 +5,35 @@
 
 package scot.carricksoftware.grantswriter.services.certificates.birthcertificate;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.BirthCertificate;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.repositories.certificates.birthcertificate.BirthCertificateRepository;
+
+import java.util.ArrayList;
+import java.util.List;
 
 @Component
 public class BirthCertificateServiceImpl implements BirthCertificateService {
 
+    private static final Logger logger = LogManager.getLogger(BirthCertificateServiceImpl.class);
+
+    private final BirthCertificateRepository birthCertificateRepository;
+
+    public BirthCertificateServiceImpl(BirthCertificateRepository birthCertificateRepository) {
+        this.birthCertificateRepository = birthCertificateRepository;
+    }
+
+    @Override
+    public List<BirthCertificate> findAllByNewBorn(Person person) {
+        logger.debug("PersonServiceImpl::findAllByPerson");
+        List<BirthCertificate> result = new ArrayList<>();
+        Iterable<BirthCertificate> birthCertificatesIterable = birthCertificateRepository.findAllByNewBorn(person);
+        for (BirthCertificate birthCertificate : birthCertificatesIterable) {
+            result.add(birthCertificate);
+        }
+        return result;
+    }
 }

+ 16 - 9
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherBirthCertificateTimeLineDataImpl.java

@@ -6,31 +6,38 @@
 package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
 
 import org.springframework.stereotype.Component;
-import scot.carricksoftware.grantswriter.data.TimeLineData;
+import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.BirthCertificate;
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.services.certificates.birthcertificate.BirthCertificateService;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateNewBornTimeLineData;
+
+import java.util.List;
 
 @Component
 public class GatherBirthCertificateTimeLineDataImpl implements GatherBirthCertificateTimeLineData {
 
-    @SuppressWarnings({"FieldCanBeLocal", "unused"})
     private final BirthCertificateService birthCertificateService;
-    @SuppressWarnings({"FieldCanBeLocal", "unused"})
-    private final TimeLineData timelineData;
 
-    public GatherBirthCertificateTimeLineDataImpl(BirthCertificateService birthCertificateService, TimeLineData timelineData) {
+
+    private final GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData;
+
+    public GatherBirthCertificateTimeLineDataImpl(BirthCertificateService birthCertificateService,
+                                                  GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData) {
         this.birthCertificateService = birthCertificateService;
-        this.timelineData = timelineData;
+        this.gatherBirthCertificateNewBornTimeLineData = gatherBirthCertificateNewBornTimeLineData;
     }
 
     @Override
     public void gather(Person person) {
-        throw new UnsupportedOperationException();
+        gatherNewBorn(person);
     }
 
     @SuppressWarnings("unused")
-    private void gatherNewBorn(@SuppressWarnings("unused") Person person) {
-        throw new UnsupportedOperationException();
+    private void gatherNewBorn(Person person) {
+        List<BirthCertificate> birthCertificates = birthCertificateService.findAllByNewBorn(person);
+        if (!birthCertificates.isEmpty()) {
+            gatherBirthCertificateNewBornTimeLineData.gather(birthCertificates);
+        }
     }
 
     @SuppressWarnings("unused")

+ 15 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/GatherBirthCertificateNewBornTimeLineData.java

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2;
+
+import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.BirthCertificate;
+
+import java.util.List;
+
+public interface GatherBirthCertificateNewBornTimeLineData {
+   void gather(List<BirthCertificate> birthCertificates);
+
+}

+ 99 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/GatherBirthCertificateNewBornTimeLineDataImpl.java

@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.data.DMY;
+import scot.carricksoftware.grantswriter.data.DMYImpl;
+import scot.carricksoftware.grantswriter.data.TimeLineData;
+import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.BirthCertificate;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeMap;
+
+@Component
+public class GatherBirthCertificateNewBornTimeLineDataImpl implements GatherBirthCertificateNewBornTimeLineData {
+
+    private final TimeLineData timelineData;
+
+    private static final Logger logger = LogManager.getLogger(GatherBirthCertificateNewBornTimeLineDataImpl.class);
+
+    public GatherBirthCertificateNewBornTimeLineDataImpl(TimeLineData timelineData) {
+        this.timelineData = timelineData;
+    }
+
+    @Override
+    public void gather(List<BirthCertificate> birthCertificates) {
+        logger.info("GatherBirthCertificateNewBornTimeLineDataImpl::Gather");
+        for (BirthCertificate birthCertificate : birthCertificates) {
+            addWhenBorn(timelineData.getTimeLine(), timelineData.getRefs(), birthCertificate);
+            addWhenRegistered(timelineData.getTimeLine(), timelineData.getRefs(), birthCertificate);
+            addMotherAndFather(timelineData.getTimeLine(), timelineData.getRefs(), birthCertificate);
+        }
+    }
+
+    private void addWhenBorn(TreeMap<DMY, List<String>> timeLine, SortedSet<String> refs, BirthCertificate birthCertificate) {
+        logger.info("GatherBirthCertificateNewBornTimeLineDataImpl::AddWhenBorn");
+        String key = birthCertificate.getWhenBorn();
+        DMY dmyKey = new DMYImpl();
+        dmyKey.parse(key);
+
+        List<String> existingValues = timeLine.get(dmyKey);
+        if (existingValues == null) {
+            existingValues = new ArrayList<>();
+        }
+
+        if (birthCertificate.getWhereBorn() != null) {
+            existingValues.add("Born at " + birthCertificate.getWhereBorn().toString());
+        } else {
+            existingValues.add("Born at " + birthCertificate.getUntrackedWhereBorn());
+        }
+        timeLine.put(dmyKey, existingValues);
+
+        refs.add("Birth Certificate for : " + birthCertificate.getNewBorn());
+    }
+
+    private void addWhenRegistered(TreeMap<DMY, List<String>> timeLine, SortedSet<String> refs, BirthCertificate birthCertificate) {
+        logger.info("GatherBirthCertificateNewBornTimeLineDataImpl::AddWhenRegistered");
+        String key = birthCertificate.getWhenRegistered();
+        DMY dmyKey = new DMYImpl();
+        dmyKey.parse(key);
+
+        List<String> existingValues = timeLine.get(dmyKey);
+        if (existingValues == null) {
+            existingValues = new ArrayList<>();
+        }
+
+        if (birthCertificate.getInformant() != null) {
+            existingValues.add("Birth Registered by " + birthCertificate.getInformant().toString() + " at " + birthCertificate.getWhereRegistered());
+        } else {
+            existingValues.add("Birth Registered by " + birthCertificate.getInformant().toString() + " at " + birthCertificate.getWhereRegistered());
+        }
+        timeLine.put(dmyKey, existingValues);
+
+    }
+
+    private void addMotherAndFather(TreeMap<DMY, List<String>> timeLine, SortedSet<String> refs, BirthCertificate birthCertificate) {
+        logger.info("GatherBirthCertificateNewBornTimeLineDataImpl::AddMotherAndFather");
+        String key = birthCertificate.getWhenRegistered();
+        DMY dmyKey = new DMYImpl();
+        dmyKey.parse(key);
+
+        List<String> existingValues = timeLine.get(dmyKey);
+        if (existingValues == null) {
+            existingValues = new ArrayList<>();
+        }
+
+        existingValues.add("Mother Registered as " + birthCertificate.getMother().toString());
+        existingValues.add("Father Registered as " + birthCertificate.getFather().toString());
+
+       timeLine.put(dmyKey, existingValues);
+    }
+}

+ 0 - 3
src/test/java/scot/carricksoftware/grantswriter/data/helpers/AddCensusEntryTest.java

@@ -41,15 +41,12 @@ class AddCensusEntryTest {
 
     private Place place;
 
-
     @Mock
     private Census censusMock;
 
     @Mock
     private CensusEntry censusEntryMock;
 
-
-
     @BeforeEach
     void setUp() {
         addCensusEntry = new AddCensusEntryImpl();

+ 35 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/GatherBirthCertificateNewBornTimeLineDataImplTest.java

@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import scot.carricksoftware.grantswriter.data.TimeLineData;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@ExtendWith(MockitoExtension.class)
+class GatherBirthCertificateNewBornTimeLineDataImplTest {
+
+    private GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData;
+
+    @Mock
+    TimeLineData timeLineDataMock;
+
+    @BeforeEach
+    void setUp() {
+        gatherBirthCertificateNewBornTimeLineData = new GatherBirthCertificateNewBornTimeLineDataImpl(timeLineDataMock);
+    }
+
+    @Test
+    void constructorTest() {
+        assertNotNull(gatherBirthCertificateNewBornTimeLineData);
+    }
+
+}