Bläddra i källkod

WriteTimeLine

Andrew Grant 3 månader sedan
förälder
incheckning
f01db505d5

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

@@ -8,16 +8,12 @@ package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
-import scot.carricksoftware.grantswriter.constants.LatexConstants;
 import scot.carricksoftware.grantswriter.data.TimelineData;
 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.FileWriter;
-import scot.carricksoftware.grantswriter.writer.latex.LatexLongTabLeEnd;
-import scot.carricksoftware.grantswriter.writer.latex.LatexLongTableStart;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteTimeLine;
 
 import java.util.List;
 
@@ -29,52 +25,29 @@ public class PersonSubSectionTimeLineWriterImpl implements PersonSubSectionTimeL
     private final LatexSubSectionHeader latexSubSectionHeader;
     private final CensusEntryService censusEntryService;
     private final TimelineData timelineData;
-    private final FileWriter fileWriter;
-    private final LatexLongTableStart latexLongTableStart;
-    private final LatexLongTabLeEnd latexLongTabLeEnd;
+    private final WriteTimeLine writeTimeLine;
 
     public PersonSubSectionTimeLineWriterImpl(LatexSubSectionHeader latexSubSectionHeader,
                                               CensusEntryService censusEntryService,
                                               TimelineData timelineData,
-                                              FileWriter fileWriter, LatexLongTableStart latexLongTableStart, LatexLongTabLeEnd latexLongTabLeEnd) {
+                                              WriteTimeLine writeTimeLine) {
         this.latexSubSectionHeader = latexSubSectionHeader;
         this.censusEntryService = censusEntryService;
         this.timelineData = timelineData;
-        this.fileWriter = fileWriter;
-        this.latexLongTableStart = latexLongTableStart;
-        this.latexLongTabLeEnd = latexLongTabLeEnd;
+        this.writeTimeLine = writeTimeLine;
     }
 
     @Override
     public void write(Person person) {
         logger.info("PersonSubSectionTimeLineWriterImp::write");
+
         latexSubSectionHeader.write("Timeline");
         List<CensusEntry>  censusEntryList = censusEntryService.findAllByPerson(person);
         timelineData.clear();
         timelineData.add(censusEntryList);
-        latexLongTableStart.write("l l");
-        writeData(timelineData.getTimeline());
-        latexLongTabLeEnd.write();
-    }
-
-    private void writeData(LinkedMultiValueMap<String, String> map) {
-        logger.info("PersonSubSectionTimeLineWriterImp::writeData");
-
-        for (String key : map.keySet()) {
-            List<String> value = map.get(key);
-            if (value != null) {
-                for (String v : value) {
-                    String builder = key +
-                            LatexConstants.TABLE_COLUMN_END +
-                            v +
-                            LatexConstants.TABLE_LINE_END;
-                    fileWriter.writeLine(builder);
-                }
-            }
-        }
-
 
+        writeTimeLine.write(timelineData.getTimeline());
+    }
 
 
-    }
 }

+ 12 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/WriteTimeLine.java

@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
+
+import org.springframework.util.LinkedMultiValueMap;
+
+public interface WriteTimeLine {
+    void write (LinkedMultiValueMap<String, String> map);
+}

+ 62 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/WriteTimeLineImpl.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;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Component;
+import org.springframework.util.LinkedMultiValueMap;
+import scot.carricksoftware.grantswriter.constants.LatexConstants;
+import scot.carricksoftware.grantswriter.writer.FileWriter;
+import scot.carricksoftware.grantswriter.writer.latex.LatexLongTabLeEnd;
+import scot.carricksoftware.grantswriter.writer.latex.LatexLongTableStart;
+
+import java.util.List;
+
+
+@Component
+public class WriteTimeLineImpl implements WriteTimeLine {
+
+    private static final Logger logger = LogManager.getLogger(WriteTimeLineImpl.class);
+
+    private final FileWriter fileWriter;
+    private final LatexLongTableStart latexLongTableStart;
+    private final LatexLongTabLeEnd latexLongTabLeEnd;
+
+    public WriteTimeLineImpl(FileWriter fileWriter,
+                             LatexLongTableStart latexLongTableStart,
+                             LatexLongTabLeEnd latexLongTabLeEnd) {
+        this.fileWriter = fileWriter;
+        this.latexLongTableStart = latexLongTableStart;
+        this.latexLongTabLeEnd = latexLongTabLeEnd;
+    }
+
+    @Override
+    public void write(LinkedMultiValueMap<String, String> map) {
+        logger.info("PersonSubSectionTimeLineWriterImp::write");
+
+        latexLongTableStart.write("l l");
+        writeTheData(map);
+        latexLongTabLeEnd.write();
+    }
+
+    private void writeTheData(LinkedMultiValueMap<String, String> map) {
+        logger.info("PersonSubSectionTimeLineWriterImp::writeTHeData");
+
+        for (String key : map.keySet()) {
+            List<String> value = map.get(key);
+            if (value != null) {
+                for (String v : value) {
+                    String builder = key +
+                            LatexConstants.TABLE_COLUMN_END +
+                            v +
+                            LatexConstants.TABLE_LINE_END;
+                    fileWriter.writeLine(builder);
+                }
+            }
+        }
+    }
+}

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

@@ -12,10 +12,8 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grantswriter.data.TimelineData;
 import scot.carricksoftware.grantswriter.services.censusentry.CensusEntryService;
-import scot.carricksoftware.grantswriter.writer.FileWriter;
-import scot.carricksoftware.grantswriter.writer.latex.LatexLongTabLeEnd;
-import scot.carricksoftware.grantswriter.writer.latex.LatexLongTableStart;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteTimeLine;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
@@ -34,22 +32,14 @@ class PersonSubSectionTimeLineWriterTest {
     private TimelineData timelineDataMock;
 
     @Mock
-    private FileWriter fileWriterMock;
-
-    @Mock
-    private LatexLongTableStart latexLongTableStartMock;
-
-    @Mock
-    private LatexLongTabLeEnd latexLongTableEndMock;
+    private WriteTimeLine writeTimeLineMock;
 
     @BeforeEach
     void setUp() {
         writer = new PersonSubSectionTimeLineWriterImpl(latexSubSectionHeaderMock,
                 censusEntryServiceMock,
                 timelineDataMock,
-                fileWriterMock,
-                latexLongTableStartMock,
-                latexLongTableEndMock);
+                writeTimeLineMock);
     }
 
     @Test

+ 42 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/WriteTimeLineTest.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
+
+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.writer.FileWriter;
+import scot.carricksoftware.grantswriter.writer.latex.LatexLongTabLeEnd;
+import scot.carricksoftware.grantswriter.writer.latex.LatexLongTableStart;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@ExtendWith(MockitoExtension.class)
+class WriteTimeLineTest {
+
+    private WriteTimeLine writeTimeLine;
+
+    @Mock
+    private FileWriter fileWriterMock;
+
+    @Mock
+    private LatexLongTableStart latexLongTableStartMock;
+
+    @Mock
+    private LatexLongTabLeEnd latexLongTabLeEndMock;
+
+    @BeforeEach
+    void setUp() {
+        writeTimeLine = new WriteTimeLineImpl(fileWriterMock, latexLongTableStartMock, latexLongTabLeEndMock);
+    }
+
+    @Test
+    void constructorTest() {
+        assertNotNull(writeTimeLine);
+    }
+}