Explorar el Código

GatherBirthCertificateMotherTimeLineData

Andrew Grant hace 2 meses
padre
commit
e90d9a894c

+ 2 - 0
src/main/java/scot/carricksoftware/grantswriter/repositories/certificates/birthcertificate/BirthCertificateRepository.java

@@ -17,4 +17,6 @@ public interface BirthCertificateRepository extends ReadOnlyRepository<BirthCert
     Iterable<BirthCertificate> findAllByNewBorn(Person person);
 
     Iterable<BirthCertificate> findAllByFather(Person person);
+
+    Iterable<BirthCertificate> findAllByMother(Person person);
 }

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

@@ -16,4 +16,6 @@ public interface BirthCertificateService {
     List<BirthCertificate> findAllByNewBorn(Person person);
 
     List<BirthCertificate> findAllByFather(Person person);
+
+    List<BirthCertificate> findAllByMother(Person person);
 }

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

@@ -47,4 +47,15 @@ public class BirthCertificateServiceImpl implements BirthCertificateService {
         }
         return result;
     }
+
+    @Override
+    public List<BirthCertificate> findAllByMother(Person person) {
+        logger.debug("PersonServiceImpl::findAllByMother");
+        List<BirthCertificate> result = new ArrayList<>();
+        Iterable<BirthCertificate> birthCertificatesIterable = birthCertificateRepository.findAllByMother(person);
+        for (BirthCertificate birthCertificate : birthCertificatesIterable) {
+            result.add(birthCertificate);
+        }
+        return result;
+    }
 }

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

@@ -10,6 +10,7 @@ import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.B
 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.GatherBirthCertificateFatherTimeLineData;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateMotherTimeLineData;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateNewBornTimeLineData;
 
 import java.util.List;
@@ -23,17 +24,21 @@ public class GatherBirthCertificateTimeLineDataImpl implements GatherBirthCertif
 
     private final GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineData;
 
+    private final GatherBirthCertificateMotherTimeLineData gatherBirthCertificateMotherTimeLineData;
+
     public GatherBirthCertificateTimeLineDataImpl(BirthCertificateService birthCertificateService,
-                                                  GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData, GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineData) {
+                                                  GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData, GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineData, GatherBirthCertificateMotherTimeLineData gatherBirthCertificateMotherTimeLineData) {
         this.birthCertificateService = birthCertificateService;
         this.gatherBirthCertificateNewBornTimeLineData = gatherBirthCertificateNewBornTimeLineData;
         this.gatherBirthCertificateFatherTimeLineData = gatherBirthCertificateFatherTimeLineData;
+        this.gatherBirthCertificateMotherTimeLineData = gatherBirthCertificateMotherTimeLineData;
     }
 
     @Override
     public void gather(Person person) {
         gatherNewBorn(person);
         gatherFather(person);
+        gatherMother(person);
     }
 
     @SuppressWarnings("unused")
@@ -52,7 +57,8 @@ public class GatherBirthCertificateTimeLineDataImpl implements GatherBirthCertif
 
     @SuppressWarnings("unused")
     private void gatherMother(@SuppressWarnings("unused") Person person) {
-        throw new UnsupportedOperationException();
+        List<BirthCertificate> birthCertificates = birthCertificateService.findAllByMother(person);
+        gatherBirthCertificateMotherTimeLineData.gather(birthCertificates);
     }
 
     @SuppressWarnings("unused")

+ 15 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/GatherBirthCertificateMotherTimeLineData.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 GatherBirthCertificateMotherTimeLineData {
+   void gather(List<BirthCertificate> birthCertificates);
+
+}

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

@@ -0,0 +1,62 @@
+/*
+ * 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.TreeMap;
+
+@Component
+public class GatherBirthCertificateMotherTimeLineDataImpl implements GatherBirthCertificateMotherTimeLineData {
+
+    private final TimeLineData timelineData;
+
+    private static final Logger logger = LogManager.getLogger(GatherBirthCertificateMotherTimeLineDataImpl.class);
+
+    public GatherBirthCertificateMotherTimeLineDataImpl(TimeLineData timelineData) {
+        this.timelineData = timelineData;
+    }
+
+    @Override
+    public void gather(List<BirthCertificate> birthCertificates) {
+        logger.info("GatherBirthCertificateNewBornTimeLineDataImpl::Gather");
+        for (BirthCertificate birthCertificate : birthCertificates) {
+            addMother(timelineData.getTimeLine(), birthCertificate);
+            addRefs(birthCertificate);
+        }
+    }
+
+    private void addMother(TreeMap<DMY, List<String>> timeLine, BirthCertificate birthCertificate) {
+        logger.info("GatherBirthCertificateMotherTimeLineDataImpl::AddMother");
+
+        List<String> existingValues = timeLine.get(getDMY(birthCertificate.getWhenBorn()));
+        if (existingValues == null) {
+            existingValues = new ArrayList<>();
+        }
+
+        existingValues.add("Registered as the mother of " + birthCertificate.getNewBorn());
+        timeLine.put(getDMY(birthCertificate.getWhenBorn()), existingValues);
+
+    }
+
+    private void addRefs(BirthCertificate birthCertificate) {
+        timelineData.getRefs().add("Birth Certificate for : " + birthCertificate.getNewBorn());
+    }
+
+    private DMY getDMY(String dateKey) {
+        DMY dmyKey = new DMYImpl();
+        dmyKey.parse(dateKey);
+        return dmyKey;
+    }
+}

+ 6 - 1
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherBirthCertificateTimeLineDataTest.java

@@ -14,6 +14,7 @@ import scot.carricksoftware.grantswriter.domains.certificates.birthcertificate.B
 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.GatherBirthCertificateFatherTimeLineData;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateMotherTimeLineData;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateNewBornTimeLineData;
 
 import java.util.ArrayList;
@@ -38,12 +39,16 @@ class GatherBirthCertificateTimeLineDataTest {
     @Mock
     private GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineDataMock;
 
+    @Mock
+    private GatherBirthCertificateMotherTimeLineData gatherBirthCertificateMotherTimeLineDataMock;
+
     @BeforeEach
     void setUp() {
         gatherBirthCertificateTimeLineData = new GatherBirthCertificateTimeLineDataImpl(
                 birthCertificateServiceMock,
                 gatherBirthCertificateNewBornTimeLineDataMock,
-                gatherBirthCertificateFatherTimeLineDataMock);
+                gatherBirthCertificateFatherTimeLineDataMock,
+                gatherBirthCertificateMotherTimeLineDataMock);
     }
 
     @Test