From 2d82cc60a221798fddaf7101aa17589a1e96f2e2 Mon Sep 17 00:00:00 2001 From: Lee Surprenant Date: Fri, 1 Oct 2021 17:40:12 -0400 Subject: [PATCH] Handle null values in fhir-server-config and throw for exceptional case Previously, we'd through an IllegalStateException if we encountered a null value. This came up because the helm `toJson` function produces all possibly fields for an object, even when some are null. If we have an invalid config (such as described above), in FHIRRestHelper.validateResource we were swallowing the underlying exception and instread constructing a generic OperationOutcomeIssue with message "Error retrieving profile configuration". This was being handled just like any other validation error and so, even though it was a server config issue, this was not clear to the client. Signed-off-by: Lee Surprenant --- .../main/java/com/ibm/fhir/config/PropertyGroup.java | 10 ++++++---- .../registry/ServerRegistryResourceProvider.java | 4 ++-- .../java/com/ibm/fhir/server/util/FHIRRestHelper.java | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fhir-config/src/main/java/com/ibm/fhir/config/PropertyGroup.java b/fhir-config/src/main/java/com/ibm/fhir/config/PropertyGroup.java index 57d61636b49..20fca98e6a6 100644 --- a/fhir-config/src/main/java/com/ibm/fhir/config/PropertyGroup.java +++ b/fhir-config/src/main/java/com/ibm/fhir/config/PropertyGroup.java @@ -11,14 +11,14 @@ import java.util.List; import java.util.Map; +import com.ibm.fhir.core.FHIRUtilities; + import jakarta.json.JsonArray; import jakarta.json.JsonNumber; import jakarta.json.JsonObject; import jakarta.json.JsonString; import jakarta.json.JsonValue; -import com.ibm.fhir.core.FHIRUtilities; - /** * This class represents a collection of properties - a property group. This could be the entire set of properties * resulting from loading the configuration, or it could be just a sub-structure within the overall config hierarchy, as @@ -107,7 +107,7 @@ public String getStringProperty(String propertyName, String defaultValue) throws /** * This is a convenience function that will retrieve an array property, then convert it * to a list of Strings by calling toString() on each array element. - * + * * @param propertyName the name of the property to retrieve * @return a List containing the elements from the JSON array property; possibly null * @throws Exception @@ -262,7 +262,7 @@ public String toString() { /** * Converts the specified JsonValue into the appropriate java.lang.* type. * @param jsonValue the JsonValue instance to be converted - * @return an instance of Boolean, Integer, String, PropertyGroup, or List + * @return either null or an instance of Boolean, Integer, String, PropertyGroup, or List * @throws Exception */ public static Object convertJsonValue(JsonValue jsonValue) throws Exception { @@ -292,6 +292,8 @@ public static Object convertJsonValue(JsonValue jsonValue) throws Exception { case FALSE: result = Boolean.FALSE; break; + case NULL: + break; default: throw new IllegalStateException("Unexpected JSON value type: " + jsonValue.getValueType().name()); } diff --git a/fhir-server/src/main/java/com/ibm/fhir/server/registry/ServerRegistryResourceProvider.java b/fhir-server/src/main/java/com/ibm/fhir/server/registry/ServerRegistryResourceProvider.java index fa42f92ee22..264cc681d4f 100644 --- a/fhir-server/src/main/java/com/ibm/fhir/server/registry/ServerRegistryResourceProvider.java +++ b/fhir-server/src/main/java/com/ibm/fhir/server/registry/ServerRegistryResourceProvider.java @@ -136,13 +136,13 @@ private List computeRegistryResources(Class validateResource(Resource resource) throws FHIRValidationExc } } } catch (Exception e) { - return Collections.singletonList(buildOperationOutcomeIssue(IssueSeverity.ERROR, IssueType.UNKNOWN, - "Error retrieving profile configuration.")); + throw new FHIRValidationException("Error retrieving profile configuration.", e); } // If required profiles were configured, perform validation of asserted profiles against required profiles