Browse Source

Notes added to census entry form.
Census entry form happy if there is no person
CensusEntryValidator checks birth_day only if not null
Census entry data updated with condition
Closes #33

Andrew Grant 7 months ago
parent
commit
5ea6ad7fb1

+ 20 - 17
src/main/java/scot/carricksoftware/grants/services/census/censusentry/UpdateRecordedYearOfBirthImpl.java

@@ -31,27 +31,30 @@ public class UpdateRecordedYearOfBirthImpl implements UpdateRecordedYearOfBirth
     public void updateRecordedYearOfBirth(CensusEntryCommand censusEntryCommand) {
         logger.info("UpdateRecordedYearOfBirthImpl::updateRecordedYearOfBirth");
         Person person = censusEntryCommand.getPerson();
-        if (person.getRecordedYearOfBirth() == null) {
-            if(censusEntryCommand.getBirthYear() != null) {
-                PersonCommand personCommand = personConverter.convert(person);
-                if (personCommand != null) {
-                    personCommand.setRecordedYearOfBirth(censusEntryCommand.getBirthYear());
-                    personService.savePersonCommand(personCommand);
+        if (person != null) {
+            if (person.getRecordedYearOfBirth() == null) {
+                if (censusEntryCommand.getBirthYear() != null) {
+                    PersonCommand personCommand = personConverter.convert(person);
+                    if (personCommand != null) {
+                        personCommand.setRecordedYearOfBirth(censusEntryCommand.getBirthYear());
+                        personService.savePersonCommand(personCommand);
+                    } else {
+                        logNoCommandError();
+                    }
                 } else {
-                   logNoCommandError();
-                }
-            } else {
-                String dateString = censusEntryCommand.getCensus().getCensusDate().label;
-                String[] dateStrings = dateString.split("/");
-                Integer year = Integer.valueOf(dateStrings[2]);
-                try {
-                    Integer age = Integer.valueOf(censusEntryCommand.getAge());
-                    updateDate(person, String.valueOf(year - age));
-                } catch (NumberFormatException e) {
-                    logger.info(" -- Age cannot be parsed");
+                    String dateString = censusEntryCommand.getCensus().getCensusDate().label;
+                    String[] dateStrings = dateString.split("/");
+                    Integer year = Integer.valueOf(dateStrings[2]);
+                    try {
+                        Integer age = Integer.valueOf(censusEntryCommand.getAge());
+                        updateDate(person, String.valueOf(year - age));
+                    } catch (NumberFormatException e) {
+                        logger.info(" -- Age cannot be parsed");
+                    }
                 }
             }
         }
+
     }
 
     private void updateDate(Person person,

+ 2 - 2
src/main/java/scot/carricksoftware/grants/validators/census/CensusEntryCommandValidatorImpl.java

@@ -23,10 +23,10 @@ public class CensusEntryCommandValidatorImpl implements CensusEntryCommandValida
         logger.debug("censusEntryCommandValidator::validate");
         validateCensus(censusEntryCommand, bindingResult);
         validateNameAndPerson(censusEntryCommand, bindingResult);
-        if (censusEntryCommand.getBirthDay() != null) {
+        if (censusEntryCommand.getBirthDay() != null && !censusEntryCommand.getBirthDay().isEmpty()) {
             validateBirthDay(censusEntryCommand, bindingResult);
         }
-        if (censusEntryCommand.getBirthYear() != null) {
+        if (censusEntryCommand.getBirthYear() != null  && !censusEntryCommand.getBirthYear().isEmpty()) {
             validateBirthYear(censusEntryCommand, bindingResult);
         }
         validateAgeAndBirthYear(censusEntryCommand, bindingResult);

+ 1 - 1
src/main/resources/application.properties

@@ -2,7 +2,7 @@ spring.application.name=grants
 server.port=8086
 server.servlet.context-path=/grants
 spring.mvc.format.date=dd-MM-yyyy
-spring.profiles.active=dev
+spring.profiles.active=uat
 logging.level.scot.carricksoftware=trace
 
 

+ 11 - 0
src/main/resources/db/changelog/2025/05/02-01-changelog.sql

@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+-- liquibase formatted sql
+
+-- changeset apg:1746197059682-1
+ALTER TABLE census_entry
+    ADD notes VARCHAR(255) NULL;
+

+ 1 - 0
src/main/resources/db/changelog/master.xml

@@ -15,5 +15,6 @@
     <include file="/db/changelog/2025/04/28-01-changelog.sql"/>
     <include file="/db/changelog/2025/04/29-01-changelog.sql"/>
     <include file="/db/changelog/2025/05/01-01-changelog.sql"/>
+    <include file="/db/changelog/2025/05/02-01-changelog.sql"/>
 
 </databaseChangeLog>

+ 1 - 1
src/main/resources/templates/censusentry/list.html

@@ -37,7 +37,7 @@
 
             <tr th:each="entry   : ${censusEntries}">
                 <td th:text="${entry.id}">123</td>
-                <td th:text="${entry.person.toString()}">123</td>
+                <td th:text="${entry.person?.toString()}">123</td>
                 <td th:text="${entry.name}">123</td>
                 <td th:text="${entry.toString()}">123</td>