Răsfoiți Sursa

Structure of Parts, PeoplePart, PersonSection

Andrew Grant 3 luni în urmă
părinte
comite
82642e4c0b

+ 57 - 3
src/main/java/scot/carricksoftware/grantswriter/domains/people/Person.java

@@ -5,16 +5,27 @@
 
 package scot.carricksoftware.grantswriter.domains.people;
 
+import jakarta.persistence.Column;
 import jakarta.persistence.Entity;
 import scot.carricksoftware.grantswriter.BaseEntity;
 
 @Entity
 public class Person extends BaseEntity {
 
-    String firstName;
+    @Column(name = "`first_name`")
+    private String firstName;
+
+    @Column(name = "`last_name`")
     String lastName;
 
-    @SuppressWarnings("unused")
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @Column(name = "`recorded_year_of_birth`")
+    String recordedYearOfBirth;
+
+    @SuppressWarnings("JpaDataSourceORMInspection")
+    @Column(name = "`certified_year_of_birth`")
+    String certifiedYearOfBirth;
+
     public String getFirstName() {
         return firstName;
     }
@@ -23,7 +34,6 @@ public class Person extends BaseEntity {
         this.firstName = firstName;
     }
 
-    @SuppressWarnings("unused")
     public String getLastName() {
         return lastName;
     }
@@ -31,4 +41,48 @@ public class Person extends BaseEntity {
     public void setLastName(String lastName) {
         this.lastName = lastName;
     }
+
+    @SuppressWarnings("unused")
+    public String getRecordedYearOfBirth() {
+        return recordedYearOfBirth;
+    }
+
+    @SuppressWarnings("unused")
+    public void setRecordedYearOfBirth(String recordedYearOfBirth) {
+        this.recordedYearOfBirth = recordedYearOfBirth;
+    }
+
+    @SuppressWarnings("unused")
+    public String getCertifiedYearOfBirth() {
+        return certifiedYearOfBirth;
+    }
+
+    @SuppressWarnings("unused")
+    public void setCertifiedYearOfBirth(String certifiedYearOfBirth) {
+        this.certifiedYearOfBirth = certifiedYearOfBirth;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(this.lastName);
+        builder.append(", ");
+        builder.append(this.firstName);
+        builder.append(", ");
+        if (certifiedYearOfBirth != null) {
+            builder.append(certifiedYearOfBirth);
+            builder.append(" ");
+        }  else {
+            if (recordedYearOfBirth != null) {
+                builder.append("(");
+                builder.append(recordedYearOfBirth);
+                builder.append(")");
+                builder.append(" ");
+            }
+        }
+        builder.append("-");
+
+        return builder.toString();
+    }
+
 }

+ 1 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/PeopleParts.java → src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/PeoplePart.java

@@ -5,7 +5,7 @@
 
 package scot.carricksoftware.grantswriter.writer.latex.parts;
 
-public interface PeopleParts {
+public interface PeoplePart {
 
     void write();
 }

+ 39 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/PeoplePartImpl.java

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.services.people.PersonService;
+import scot.carricksoftware.grantswriter.writer.latex.sections.PersonSection;
+
+import java.util.List;
+
+@Component
+public class PeoplePartImpl implements PeoplePart {
+
+    private static final Logger logger = LogManager.getLogger(PeoplePartImpl.class);
+
+    private final PersonService personService;
+
+    private final PersonSection personSection;
+
+    public PeoplePartImpl(PersonService personService, PersonSection personSection) {
+        this.personService = personService;
+        this.personSection = personSection;
+    }
+
+    @Override
+    public void write() {
+        logger.info("PeoplePartsImpl.write()");
+        List<Person> people = personService.findAll();
+        for (Person person : people) {
+            personSection.write(person);
+        }
+    }
+}

+ 0 - 21
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/PeoplePartsImpl.java

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-package scot.carricksoftware.grantswriter.writer.latex.parts;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-@Component
-public class PeoplePartsImpl implements PeopleParts {
-
-    private static final Logger logger = LogManager.getLogger(PeoplePartsImpl.class);
-
-    @Override
-    public void write() {
-        logger.info("PeoplePartsImpl.write()");
-    }
-}

+ 4 - 4
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/WritePartsImpl.java

@@ -14,15 +14,15 @@ public class WritePartsImpl implements WriteParts {
 
     private static final Logger logger = LogManager.getLogger(WritePartsImpl.class);
 
-    private final PeopleParts peopleParts;
+    private final PeoplePart peoplePart;
 
-    public WritePartsImpl(PeopleParts peopleParts) {
-        this.peopleParts = peopleParts;
+    public WritePartsImpl(PeoplePart peoplePart) {
+        this.peoplePart = peoplePart;
     }
 
     @Override
     public void write() {
         logger.info("WritePartsImpl.write()");
-        peopleParts.write();
+        peoplePart.write();
     }
 }

+ 13 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/sections/PersonSection.java

@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.sections;
+
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
+public interface PersonSection {
+    @SuppressWarnings({"unused", "EmptyMethod"})
+    void write(Person person);
+}

+ 17 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/sections/PersonSectionImpl.java

@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.sections;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
+@Component
+public class PersonSectionImpl implements PersonSection {
+    @Override
+    public void write(Person person) {
+
+    }
+}

+ 2 - 2
src/main/resources/application-uat.properties

@@ -1,8 +1,8 @@
 # Set up for uat
 spring.datasource.url=jdbc:mariadb://git.carricksoftware.co.uk:3306/grants_uat
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
-spring.datasource.username=apg
-spring.datasource.password=sjkis27
+spring.datasource.username=grants_uat_readonly
+spring.datasource.password=martha
 
 
 

+ 39 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/PeoplePartTest.java

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts;
+
+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.services.people.PersonService;
+import scot.carricksoftware.grantswriter.writer.latex.sections.PersonSection;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@ExtendWith(MockitoExtension.class)
+class PeoplePartTest {
+
+    private PeoplePart peoplePart;
+
+    @Mock
+    private PersonService personServiceMock;
+
+    @Mock
+    private PersonSection personSectionMock;
+
+    @SuppressWarnings("EmptyMethod")
+    @BeforeEach
+    void setUp() {
+        peoplePart = new PeoplePartImpl(personServiceMock, personSectionMock);
+    }
+
+    @Test
+    void constructorTest() {
+        assertNotNull(peoplePart);
+    }
+}

+ 0 - 17
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/PeoplePartsTest.java

@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-package scot.carricksoftware.grantswriter.writer.latex.parts;
-
-import org.junit.jupiter.api.BeforeEach;
-
-
-class PeoplePartsTest {
-
-    @SuppressWarnings("EmptyMethod")
-    @BeforeEach
-    void setUp() {
-    }
-}

+ 3 - 3
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/WritePartsTest.java

@@ -20,11 +20,11 @@ class WritePartsTest {
     private WriteParts writeParts;
 
     @Mock
-    PeopleParts peoplePartsMock;
+    PeoplePart peoplePartMock;
 
     @BeforeEach
     void setUp() {
-        writeParts = new WritePartsImpl(peoplePartsMock);
+        writeParts = new WritePartsImpl(peoplePartMock);
     }
 
     @Test
@@ -35,6 +35,6 @@ class WritePartsTest {
     @Test
     void writeTest(){
         writeParts.write();
-        verify(peoplePartsMock).write();
+        verify(peoplePartMock).write();
     }
 }

+ 27 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/sections/PersonSectionTest.java

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.sections;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+
+class PersonSectionTest {
+
+    private PersonSection personSection;
+
+    @BeforeEach
+    void setUp() {
+        personSection = new PersonSectionImpl();
+    }
+
+    @Test
+    void constructorTest() {
+        assertNotNull(personSection);
+    }
+}