Bläddra i källkod

Death certificate updates year of death
Closes #77

Andrew Grant 4 månader sedan
förälder
incheckning
765da622d5

+ 4 - 0
src/main/java/scot/carricksoftware/grants/commands/people/PersonCommand.java

@@ -64,4 +64,8 @@ public interface PersonCommand {
     List<PersonText> getPersonTexts();
 
     void setPersonTexts(List<PersonText> personTexts);
+
+    String getCertifiedYearOfDeath();
+
+    void setCertifiedYearOfDeath(String certifiedYearOfDeath);
 }

+ 10 - 0
src/main/java/scot/carricksoftware/grants/commands/people/PersonCommandImpl.java

@@ -30,6 +30,8 @@ public class PersonCommandImpl implements PersonCommand {
 
     private String certifiedYearOfBirth;
 
+    private String certifiedYearOfDeath;
+
     private List<BirthCertificate> birthCertificates = new ArrayList<>();
 
     private List<DeathCertificate> deathCertificates = new ArrayList<>();
@@ -163,5 +165,13 @@ public class PersonCommandImpl implements PersonCommand {
         this.personTexts = personTexts;
     }
 
+    @Override
+    public String getCertifiedYearOfDeath() {
+        return certifiedYearOfDeath;
+    }
 
+    @Override
+    public void setCertifiedYearOfDeath(String certifiedYearOfDeath) {
+        this.certifiedYearOfDeath = certifiedYearOfDeath;
+    }
 }

+ 1 - 1
src/main/java/scot/carricksoftware/grants/controllers/certificates/birthcertificates/BirthCertificateFormControllerImpl.java

@@ -111,7 +111,7 @@ public class BirthCertificateFormControllerImpl implements BirthCertificateFormC
             model.addAttribute(AttributeConstants.ORGANISATIONS, organisationService.findAll());
             return ViewConstants.BIRTH_CERTIFICATE_FORM;
         }
-//
+
         BirthCertificateCommand savedCommand = birthCertificateService.saveBirthCertificateCommand(birthCertificateCommand);
         updateCertifiedYearOfBirth.updateCertifiedYearOfBirth(savedCommand);
         model.addAttribute(AttributeConstants.BIRTH_CERTIFICATE_COMMAND, savedCommand);

+ 5 - 1
src/main/java/scot/carricksoftware/grants/controllers/certificates/deathcertificates/DeathCertificateFormControllerImpl.java

@@ -25,6 +25,7 @@ import scot.carricksoftware.grants.constants.ViewConstants;
 import scot.carricksoftware.grants.converters.certificates.deathcertificates.DeathCertificateCommandConverter;
 import scot.carricksoftware.grants.converters.certificates.deathcertificates.DeathCertificateConverter;
 import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
+import scot.carricksoftware.grants.services.certificates.deathcertificates.UpdateCertifiedYearOfDeath;
 import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.organisations.OrganisationService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
@@ -44,6 +45,7 @@ public class DeathCertificateFormControllerImpl implements DeathCertificateFormC
     private final PlaceService placeService;
     private final OrganisationService organisationService;
     private final CapitaliseDeathCertificate capitaliseDeathCertificate;
+    private final UpdateCertifiedYearOfDeath updateCertifiedYearOfDeath;
 
 
     public DeathCertificateFormControllerImpl(DeathCertificateService deathCertificateService,
@@ -53,7 +55,7 @@ public class DeathCertificateFormControllerImpl implements DeathCertificateFormC
                                               PersonService personService,
                                               PlaceService placeService,
                                               OrganisationService organisationService,
-                                              CapitaliseDeathCertificate capitaliseDeathCertificate) {
+                                              CapitaliseDeathCertificate capitaliseDeathCertificate, UpdateCertifiedYearOfDeath updateCertifiedYearOfDeath) {
         this.deathCertificateService = deathCertificateService;
         this.deathCertificateCommandConverter = deathCertificateCommandConverter;
 
@@ -65,6 +67,7 @@ public class DeathCertificateFormControllerImpl implements DeathCertificateFormC
 
         this.organisationService = organisationService;
         this.capitaliseDeathCertificate = capitaliseDeathCertificate;
+        this.updateCertifiedYearOfDeath = updateCertifiedYearOfDeath;
     }
 
     @SuppressWarnings("SameReturnValue")
@@ -109,6 +112,7 @@ public class DeathCertificateFormControllerImpl implements DeathCertificateFormC
         }
 
         DeathCertificateCommand savedCommand = deathCertificateService.saveDeathCertificateCommand(deathCertificateCommand);
+        updateCertifiedYearOfDeath.updateCertifiedYearOfDeath(savedCommand);
         model.addAttribute(AttributeConstants.DEATH_CERTIFICATE_COMMAND, savedCommand);
         model.addAttribute(AttributeConstants.PEOPLE, personService.findAll());
         model.addAttribute(AttributeConstants.PLACES, placeService.findAll());

+ 1 - 0
src/main/java/scot/carricksoftware/grants/converters/people/PersonCommandConverterImpl.java

@@ -20,6 +20,7 @@ public class PersonCommandConverterImpl implements PersonCommandConverter {
         result.setLastName(source.getLastName());
         result.setRecordedYearOfBirth(source.getRecordedYearOfBirth());
         result.setCertifiedYearOfBirth(source.getCertifiedYearOfBirth());
+        result.setCertifiedYearOfDeath(source.getCertifiedYearOfDeath());
 
         result.setCensusEntries(source.getCensusEntries());
         result.setDeathCertificates(source.getDeathCertificates());

+ 1 - 0
src/main/java/scot/carricksoftware/grants/converters/people/PersonConverterImpl.java

@@ -21,6 +21,7 @@ public class PersonConverterImpl implements PersonConverter {
         result.setLastName(source.getLastName());
         result.setRecordedYearOfBirth(source.getRecordedYearOfBirth());
         result.setCertifiedYearOfBirth(source.getCertifiedYearOfBirth());
+        result.setCertifiedYearOfDeath(source.getCertifiedYearOfDeath());
 
 
         result.setDivorceCertificates(source.getDivorceCertificates());

+ 15 - 0
src/main/java/scot/carricksoftware/grants/domains/people/Person.java

@@ -36,6 +36,9 @@ public class Person extends BaseEntity {
     @Column(name = "`certified_year_of_birth`")
     String certifiedYearOfBirth;
 
+    @Column(name = "`certified_year_of_death`")
+    String certifiedYearOfDeath;
+
     @OneToMany(mappedBy = "id", cascade = CascadeType.ALL, orphanRemoval = true)
     private List<BirthCertificate> birthCertificates = new ArrayList<>();
 
@@ -92,6 +95,10 @@ public class Person extends BaseEntity {
             }
         }
         builder.append("-");
+        if (certifiedYearOfDeath != null && !certifiedYearOfDeath.isEmpty())  {
+            builder.append(certifiedYearOfDeath);
+            builder.append(" ");
+        }
 
         return builder.toString();
     }
@@ -167,4 +174,12 @@ public class Person extends BaseEntity {
     public void setPersonTexts(List<PersonText> personTexts) {
         this.personTexts = personTexts;
     }
+
+    public String getCertifiedYearOfDeath() {
+        return certifiedYearOfDeath;
+    }
+
+    public void setCertifiedYearOfDeath(String certifiedYearOfDeath) {
+        this.certifiedYearOfDeath = certifiedYearOfDeath;
+    }
 }

+ 14 - 0
src/main/java/scot/carricksoftware/grants/services/certificates/deathcertificates/UpdateCertifiedYearOfDeath.java

@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.services.certificates.deathcertificates;
+
+
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+
+public interface UpdateCertifiedYearOfDeath {
+
+    void updateCertifiedYearOfDeath(DeathCertificateCommand deathCertificateCommand);
+}

+ 64 - 0
src/main/java/scot/carricksoftware/grants/services/certificates/deathcertificates/UpdateCertifiedYearOfDeathImpl.java

@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.services.certificates.deathcertificates;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.commands.people.PersonCommand;
+import scot.carricksoftware.grants.converters.people.PersonConverter;
+import scot.carricksoftware.grants.domains.people.Person;
+import scot.carricksoftware.grants.services.people.PersonService;
+
+import static java.util.Objects.isNull;
+
+@Component
+public class UpdateCertifiedYearOfDeathImpl implements UpdateCertifiedYearOfDeath {
+
+    private static final Logger logger = LogManager.getLogger(UpdateCertifiedYearOfDeathImpl.class);
+    private final PersonService personService;
+    private final PersonConverter personConverter;
+
+    public UpdateCertifiedYearOfDeathImpl(PersonConverter personConverter,
+                                          PersonService personService) {
+        this.personService = personService;
+        this.personConverter = personConverter;
+    }
+
+
+    @Override
+    public void updateCertifiedYearOfDeath(DeathCertificateCommand deathCertificateCommand) {
+        logger.debug("UpdateCertifiedYearOfBirthImpl::updateRecordedYearOfBirth");
+        Person person = deathCertificateCommand.getDeceased();
+        if (!isNull(person)) {
+           String certifiedYearOfDeath = getYearOfDeath(deathCertificateCommand.getWhenDied());
+           updateDate(person, certifiedYearOfDeath);
+        }
+    }
+
+    private String getYearOfDeath(String whenDied) {
+        logger.debug("UpdateRecordedYearOfBirthImpl::GetYearOfBirth");
+        return whenDied.substring(6, 10);
+    }
+
+    private void updateDate(Person person,
+                            String certifiedYearOfDeath) {
+        logger.debug("UpdateRecordedYearOfDeathImpl::UpdateDate");
+        PersonCommand personCommand = personConverter.convert(person);
+        if (personCommand != null) {
+            personCommand.setCertifiedYearOfDeath(certifiedYearOfDeath);
+            personService.savePersonCommand(personCommand);
+        } else {
+            logNoCommandError();
+        }
+    }
+
+    private void logNoCommandError() {
+        logger.info("PersonCommand = null.");
+    }
+
+}