Fixed NPEs on validation

This commit is contained in:
Nick Goupinets 2021-03-11 15:38:45 -05:00
parent 23f3cc1f42
commit 01b1210b8a
3 changed files with 22 additions and 2 deletions

View File

@ -126,9 +126,12 @@ public class AddressValidatingInterceptor extends ServerOperationInterceptorAdap
protected void validateAddress(IBase theAddress, FhirContext theFhirContext) {
try {
AddressValidationResult validationResult = getAddressValidator().isValid(theAddress, theFhirContext);
ourLog.debug("Validated address {}", validationResult);
myExtensionHelper.setValue(theAddress, IAddressValidator.ADDRESS_VALIDATION_EXTENSION_URL,
validationResult.isValid() ? IAddressValidator.EXT_VALUE_VALID : IAddressValidator.EXT_VALUE_INVALID, theFhirContext);
} catch (Exception ex) {
ourLog.warn("Unable to validate address", ex);
myExtensionHelper.setValue(theAddress, IAddressValidator.ADDRESS_VALIDATION_EXTENSION_URL, IAddressValidator.EXT_UNABLE_TO_VALIDATE, theFhirContext);
}
}

View File

@ -72,4 +72,14 @@ public class AddressValidationResult {
public void setRawResponse(String theRawResponse) {
this.myRawResponse = theRawResponse;
}
@Override
public String toString() {
return
" isValid=" + myIsValid +
", validatedAddressString='" + myValidatedAddressString + '\'' +
", validationResults=" + myValidationResults + '\'' +
", rawResponse='" + myRawResponse + '\'' +
", myValidatedAddress='" + myValidatedAddress + '\'';
}
}

View File

@ -86,7 +86,10 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
theResult.setValid(isValid(theMatch));
ourLog.debug("Address validation flag {}", theResult.isValid());
theResult.setValidatedAddressString(theMatch.get("Address").asText());
JsonNode addressNode = theMatch.get("Address");
if (addressNode != null) {
theResult.setValidatedAddressString(addressNode.asText());
}
ourLog.debug("Validated address string {}", theResult.getValidatedAddressString());
theResult.setValidatedAddress(toAddress(theMatch, theFhirContext));
@ -137,7 +140,11 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
private boolean isDuplicate(String theAddressLine, JsonNode theMatch) {
for (String s : DUPLICATE_FIELDS_IN_ADDRESS_LINES) {
theAddressLine = theAddressLine.replaceAll(theMatch.get(s).asText(""), "");
JsonNode node = theMatch.get(s);
if (node == null) {
continue;
}
theAddressLine = theAddressLine.replaceAll(node.asText(), "");
}
return theAddressLine.trim().isEmpty();
}