浏览代码

Validate RecordedYearOf Birth refactored

Andrew Grant 7 月之前
父节点
当前提交
e8d6280c39

+ 16 - 8
src/main/java/scot/carricksoftware/grants/services/census/censusentry/UpdateRecordedYearOfBirthImpl.java

@@ -34,13 +34,14 @@ public class UpdateRecordedYearOfBirthImpl implements UpdateRecordedYearOfBirth
         if (person.getRecordedYearOfBirth() == null) {
             if(censusEntryCommand.getBirthYear() != null) {
                 PersonCommand personCommand = personConverter.convert(person);
-                assert personCommand != null;
-                personCommand.setRecordedYearOfBirth(censusEntryCommand.getBirthYear());
-                personService.savePersonCommand(personCommand);
+                if (personCommand != null) {
+                    personCommand.setRecordedYearOfBirth(censusEntryCommand.getBirthYear());
+                    personService.savePersonCommand(personCommand);
+                } else {
+                   logNoCommandError();
+                }
             } else {
-
                 String dateString = censusEntryCommand.getCensus().getCensusDate().label;
-
                 String[] dateStrings = dateString.split("/");
                 Integer year = Integer.valueOf(dateStrings[2]);
                 try {
@@ -57,8 +58,15 @@ public class UpdateRecordedYearOfBirthImpl implements UpdateRecordedYearOfBirth
                             String dateString) {
         logger.info("UpdateRecordedYearOfBirthImpl::Date");
         PersonCommand personCommand = personConverter.convert(person);
-        assert (personCommand != null);
-        personCommand.setRecordedYearOfBirth(dateString);
-        personService.savePersonCommand(personCommand);
+        if (personCommand != null) {
+            personCommand.setRecordedYearOfBirth(dateString);
+            personService.savePersonCommand(personCommand);
+        } else {
+            logNoCommandError();
+        }
+    }
+
+    private void logNoCommandError(){
+        logger.info("Person could not be converted to PersonCommand");
     }
 }