Prechádzať zdrojové kódy

Status button added to index.html

Andrew Grant 2 mesiacov pred
rodič
commit
6405f56962

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

@@ -15,4 +15,6 @@ import scot.carricksoftware.grantswriter.repositories.ReadOnlyRepository;
 public interface BirthCertificateRepository extends ReadOnlyRepository<BirthCertificate, Long> {
 
     Iterable<BirthCertificate> findAllByNewBorn(Person person);
+
+    Iterable<BirthCertificate> findAllByFather(Person person);
 }

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

@@ -14,4 +14,6 @@ import java.util.List;
 public interface BirthCertificateService {
 
     List<BirthCertificate> findAllByNewBorn(Person person);
+
+    List<BirthCertificate> findAllByFather(Person person);
 }

+ 12 - 1
src/main/java/scot/carricksoftware/grantswriter/services/certificates/birthcertificate/BirthCertificateServiceImpl.java

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

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

@@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
 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.GatherBirthCertificateFatherTimeLineData;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateNewBornTimeLineData;
 
 import java.util.List;
@@ -18,18 +19,21 @@ public class GatherBirthCertificateTimeLineDataImpl implements GatherBirthCertif
 
     private final BirthCertificateService birthCertificateService;
 
-
     private final GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData;
 
+    private final GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineData;
+
     public GatherBirthCertificateTimeLineDataImpl(BirthCertificateService birthCertificateService,
-                                                  GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData) {
+                                                  GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineData, GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineData) {
         this.birthCertificateService = birthCertificateService;
         this.gatherBirthCertificateNewBornTimeLineData = gatherBirthCertificateNewBornTimeLineData;
+        this.gatherBirthCertificateFatherTimeLineData = gatherBirthCertificateFatherTimeLineData;
     }
 
     @Override
     public void gather(Person person) {
         gatherNewBorn(person);
+        gatherFather(person);
     }
 
     @SuppressWarnings("unused")
@@ -42,7 +46,8 @@ public class GatherBirthCertificateTimeLineDataImpl implements GatherBirthCertif
 
     @SuppressWarnings("unused")
     private void gatherFather(@SuppressWarnings("unused") Person person) {
-        throw new UnsupportedOperationException();
+        List<BirthCertificate> birthCertificates = birthCertificateService.findAllByFather(person);
+        gatherBirthCertificateFatherTimeLineData.gather(birthCertificates);
     }
 
     @SuppressWarnings("unused")

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

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

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

+ 3 - 0
src/main/resources/templates/index.html

@@ -23,6 +23,9 @@
 
         <tbody>
         <tr>
+            <td>
+                <a class="btn btn-primary btn-lg btn-block" href="status">System Status</a>
+            </td>
             <td>
                 <a class="btn btn-primary btn-lg btn-block" href="files">Specify Files</a>
             </td>

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

@@ -13,6 +13,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 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.GatherBirthCertificateFatherTimeLineData;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.GatherBirthCertificateNewBornTimeLineData;
 
 import java.util.ArrayList;
@@ -26,7 +27,6 @@ import static scot.carricksoftware.grantswriter.GenerateRandomPeopleValues.GetRa
 @ExtendWith(MockitoExtension.class)
 class GatherBirthCertificateTimeLineDataTest {
 
-
     private GatherBirthCertificateTimeLineData gatherBirthCertificateTimeLineData;
 
     @Mock
@@ -35,10 +35,15 @@ class GatherBirthCertificateTimeLineDataTest {
     @Mock
     private GatherBirthCertificateNewBornTimeLineData gatherBirthCertificateNewBornTimeLineDataMock;
 
+    @Mock
+    private GatherBirthCertificateFatherTimeLineData gatherBirthCertificateFatherTimeLineDataMock;
 
     @BeforeEach
     void setUp() {
-        gatherBirthCertificateTimeLineData = new GatherBirthCertificateTimeLineDataImpl(birthCertificateServiceMock, gatherBirthCertificateNewBornTimeLineDataMock);
+        gatherBirthCertificateTimeLineData = new GatherBirthCertificateTimeLineDataImpl(
+                birthCertificateServiceMock,
+                gatherBirthCertificateNewBornTimeLineDataMock,
+                gatherBirthCertificateFatherTimeLineDataMock);
     }
 
     @Test