浏览代码

CensusEntryService findAllByPerson(person)

Andrew Grant 3 月之前
父节点
当前提交
f637f65b85

+ 1 - 1
docs/Structure.txt

@@ -1,4 +1,4 @@
-TexController -> TexWriter -> PartsWriter -> PeoplePartWriter -> (PeoplePartHeader+PersonSectionWriter) -> (PersonPart SubSectionHeading + PersonTimeLineWriter)
+TexController -> TexWriter -> PartsWriter -> PeoplePartWriter -> (PeoplePartHeader+PersonSectionWriter) -> (PersonPart SubSectionHeading + PersonSubSectionTimeLineWriter)
 
 
 

+ 2 - 1
src/main/java/scot/carricksoftware/grantswriter/repositories/people/ReadOnlyRepository.java → src/main/java/scot/carricksoftware/grantswriter/repositories/ReadOnlyRepository.java

@@ -3,7 +3,7 @@
  *
  */
 
-package scot.carricksoftware.grantswriter.repositories.people;
+package scot.carricksoftware.grantswriter.repositories;
 
 import org.springframework.data.domain.Sort;
 import org.springframework.data.repository.NoRepositoryBean;
@@ -15,4 +15,5 @@ import java.util.List;
 public interface ReadOnlyRepository<T, ID> extends Repository<T, ID> {
 
     List<T> findAll(Sort sort);
+
 }

+ 19 - 0
src/main/java/scot/carricksoftware/grantswriter/repositories/censusentry/CensusEntryRepository.java

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 19:47. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grantswriter.repositories.censusentry;
+
+import org.springframework.stereotype.Repository;
+import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.repositories.ReadOnlyRepository;
+
+import java.util.List;
+
+@SuppressWarnings("unused")
+@Repository
+public interface CensusEntryRepository extends ReadOnlyRepository<CensusEntry, Long> {
+    List<CensusEntry> findAllByPerson(Person person);
+}

+ 1 - 1
src/main/java/scot/carricksoftware/grantswriter/repositories/people/PersonRepository.java

@@ -7,10 +7,10 @@ package scot.carricksoftware.grantswriter.repositories.people;
 
 import org.springframework.stereotype.Repository;
 import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.repositories.ReadOnlyRepository;
 
 @SuppressWarnings("unused")
 @Repository
 public interface PersonRepository extends ReadOnlyRepository<Person, Long> {
 
-
 }

+ 16 - 0
src/main/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryService.java

@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.services.censusentry;
+
+import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
+import java.util.List;
+
+public interface CensusEntryService {
+
+    List<CensusEntry> findAllByPerson(Person person);
+}

+ 43 - 0
src/main/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryServiceImpl.java

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.services.censusentry;
+
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Service;
+import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.repositories.censusentry.CensusEntryRepository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+@Service
+public class CensusEntryServiceImpl implements CensusEntryService {
+
+    private static final Logger logger = LogManager.getLogger(CensusEntryServiceImpl.class);
+
+    private final CensusEntryRepository censusEntryRepository;
+
+    public CensusEntryServiceImpl(CensusEntryRepository censusEntryRepository) {
+        this.censusEntryRepository = censusEntryRepository;
+    }
+
+    @Override
+    public List<CensusEntry> findAllByPerson(Person person) {
+        logger.debug("PersonServiceImpl::findAll");
+        List<CensusEntry> result = new ArrayList<>();
+        Iterable<CensusEntry> censusEntryIterable = censusEntryRepository.findAllByPerson(person);
+        censusEntryIterable.forEach(result::add);
+        return result;
+    }
+
+
+
+
+}

+ 0 - 9
src/main/java/scot/carricksoftware/grantswriter/services/people/CensusEntryService.java

@@ -1,9 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-package scot.carricksoftware.grantswriter.services.people;
-
-public interface CensusEntryService {
-}

+ 0 - 9
src/main/java/scot/carricksoftware/grantswriter/services/people/CensusEntryServiceImpl.java

@@ -1,9 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-package scot.carricksoftware.grantswriter.services.people;
-
-public class CensusEntryServiceImpl implements CensusEntryService {
-}

+ 9 - 2
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterImpl.java

@@ -6,21 +6,28 @@
 package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections;
 
 import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
 import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.services.censusentry.CensusEntryService;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
 
+import java.util.List;
+
 @Component
 public class PersonSubSectionTimeLineWriterImpl implements PersonSubSectionTimeLineWriter {
 
-private final LatexSubSectionHeader latexSubSectionHeader;
+    private final LatexSubSectionHeader latexSubSectionHeader;
+    private final CensusEntryService censusEntryService;
 
-    public PersonSubSectionTimeLineWriterImpl(LatexSubSectionHeader latexSubSectionHeader) {
+    public PersonSubSectionTimeLineWriterImpl(LatexSubSectionHeader latexSubSectionHeader, CensusEntryService censusEntryService) {
         this.latexSubSectionHeader = latexSubSectionHeader;
+        this.censusEntryService = censusEntryService;
     }
 
     @Override
     public void write(Person person) {
         // get census record for name
         latexSubSectionHeader.write("Timeline");
+        List<CensusEntry>  censusEntryList = censusEntryService.findAllByPerson(person);
     }
 }

+ 8 - 3
src/test/java/scot/carricksoftware/grantswriter/services/people/CensusEntryServiceTest.java → src/test/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryServiceTest.java

@@ -3,20 +3,25 @@
  *
  */
 
-package scot.carricksoftware.grantswriter.services.people;
+package scot.carricksoftware.grantswriter.services.censusentry;
 
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import scot.carricksoftware.grantswriter.repositories.censusentry.CensusEntryRepository;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 class CensusEntryServiceTest {
-private CensusEntryService censusEntryService;
+    private CensusEntryService censusEntryService;
+
+    @Mock
+    private CensusEntryRepository censusEntryRepositoryMock;
 
     @BeforeEach
     void setUp() {
-        censusEntryService = new CensusEntryServiceImpl();
+        censusEntryService = new CensusEntryServiceImpl(censusEntryRepositoryMock);
     }
 
     @Test

+ 5 - 1
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterTest.java

@@ -11,6 +11,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.services.censusentry.CensusEntryService;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
 
 import static org.mockito.Mockito.verify;
@@ -23,12 +24,15 @@ class PersonSubSectionTimeLineWriterTest {
     @Mock
     private LatexSubSectionHeader latexSubSectionHeaderMock;
 
+    @Mock
+    private CensusEntryService censusEntryServiceMock;
+
     @Mock
     private Person personMock;
 
     @BeforeEach
     void setUp() {
-        writer = new PersonSubSectionTimeLineWriterImpl(latexSubSectionHeaderMock);
+        writer = new PersonSubSectionTimeLineWriterImpl(latexSubSectionHeaderMock, censusEntryServiceMock);
     }
 
     @Test