From 657eaf77583ac4645f3aae0d3f11755c9f6ea8eb Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 13 Aug 2019 08:18:02 -0400 Subject: [PATCH] Add graphql and _filter support --- .../jpa/starter/FhirServerConfigCommon.java | 2 ++ .../uhn/fhir/jpa/starter/HapiProperties.java | 34 ++++++++++++------- .../fhir/jpa/starter/JpaRestfulServer.java | 13 ++++--- src/main/resources/hapi.properties | 5 +++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java b/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java index 7523a0b..a396ee4 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java @@ -111,6 +111,8 @@ public class FhirServerConfigCommon { retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.WEBSOCKET); } + retVal.setFilterParameterEnabled(HapiProperties.getFilterSearchEnabled()); + return retVal; } diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java b/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java index 3ef8bcb..793edbd 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java @@ -6,8 +6,8 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.ETagSupportEnum; import com.google.common.annotations.VisibleForTesting; -import java.io.InputStream; import java.io.FileInputStream; +import java.io.InputStream; import java.util.Arrays; import java.util.Properties; import java.util.Set; @@ -16,6 +16,7 @@ import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.*; public class HapiProperties { + public static final String BINARY_STORAGE_ENABLED = "binary_storage.enabled"; static final String ALLOW_EXTERNAL_REFERENCES = "allow_external_references"; static final String ALLOW_MULTIPLE_DELETE = "allow_multiple_delete"; static final String ALLOW_PLACEHOLDER_REFERENCES = "allow_placeholder_references"; @@ -51,10 +52,10 @@ public class HapiProperties { static final String ALLOW_CONTAINS_SEARCHES = "allow_contains_searches"; static final String ALLOW_OVERRIDE_DEFAULT_SEARCH_PARAMS = "allow_override_default_search_params"; static final String EMAIL_FROM = "email.from"; - public static final String BINARY_STORAGE_ENABLED = "binary_storage.enabled"; private static final String VALIDATE_REQUESTS_ENABLED = "validation.requests.enabled"; private static final String VALIDATE_RESPONSES_ENABLED = "validation.responses.enabled"; - + private static final String FILTER_SEARCH_ENABLED = "filter_search.enabled"; + private static final String GRAPHQL_ENABLED = "graphql.enabled"; private static Properties properties; /* @@ -77,7 +78,7 @@ public class HapiProperties { public static Properties getProperties() { if (properties == null) { // Load the configurable properties file - try (InputStream in = HapiProperties.class.getClassLoader().getResourceAsStream(HAPI_PROPERTIES)){ + try (InputStream in = HapiProperties.class.getClassLoader().getResourceAsStream(HAPI_PROPERTIES)) { HapiProperties.properties = new Properties(); HapiProperties.properties.load(in); } catch (Exception e) { @@ -85,8 +86,8 @@ public class HapiProperties { } Properties overrideProps = loadOverrideProperties(); - if(overrideProps != null) { - properties.putAll(overrideProps); + if (overrideProps != null) { + properties.putAll(overrideProps); } } @@ -96,17 +97,17 @@ public class HapiProperties { /** * If a configuration file path is explicitly specified via -Dhapi.properties=, the properties there will * be used to override the entries in the default hapi.properties file (currently under WEB-INF/classes) + * * @return properties loaded from the explicitly specified configuraiton file if there is one, or null otherwise. */ private static Properties loadOverrideProperties() { String confFile = System.getProperty(HAPI_PROPERTIES); - if(confFile != null) { + if (confFile != null) { try { Properties props = new Properties(); props.load(new FileInputStream(confFile)); return props; - } - catch (Exception e) { + } catch (Exception e) { throw new ConfigurationException("Could not load HAPI properties file: " + confFile, e); } } @@ -287,8 +288,8 @@ public class HapiProperties { public static Set getSupportedResourceTypes() { String[] types = defaultString(getProperty("supported_resource_types")).split(","); return Arrays.stream(types) - .map(t->trim(t)) - .filter(t->isNotBlank(t)) + .map(t -> trim(t)) + .filter(t -> isNotBlank(t)) .collect(Collectors.toSet()); } @@ -358,7 +359,16 @@ public class HapiProperties { } public static boolean getValidateResponsesEnabled() { - return HapiProperties.getBooleanProperty(VALIDATE_REQUESTS_ENABLED, false); + return HapiProperties.getBooleanProperty(VALIDATE_RESPONSES_ENABLED, false); + } + + public static boolean getFilterSearchEnabled() { + return HapiProperties.getBooleanProperty(FILTER_SEARCH_ENABLED, true); + } + + public static boolean getGraphqlEnabled() { + return HapiProperties.getBooleanProperty(GRAPHQL_ENABLED, true); } } + diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java b/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java index c8fa268..9b6a62c 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java @@ -9,10 +9,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoRegistry; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor; -import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; -import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2; -import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider; -import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider; +import ca.uhn.fhir.jpa.provider.*; import ca.uhn.fhir.jpa.provider.dstu3.JpaConformanceProviderDstu3; import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3; import ca.uhn.fhir.jpa.provider.r4.JpaConformanceProviderR4; @@ -54,7 +51,6 @@ public class JpaRestfulServer extends RestfulServer { * specified in the properties file. */ ApplicationContext appCtx = (ApplicationContext) getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT"); - // Customize supported resource types Set supportedResourceTypes = HapiProperties.getSupportedResourceTypes(); if (!supportedResourceTypes.isEmpty()) { @@ -281,6 +277,13 @@ public class JpaRestfulServer extends RestfulServer { } } + // GraphQL + if (HapiProperties.getGraphqlEnabled()) { + if (fhirVersion.isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { + registerProvider(appCtx.getBean(GraphQLProvider.class)); + } + } + } } diff --git a/src/main/resources/hapi.properties b/src/main/resources/hapi.properties index 6b23b23..2cc874a 100644 --- a/src/main/resources/hapi.properties +++ b/src/main/resources/hapi.properties @@ -47,6 +47,11 @@ validation.requests.enabled=false # Should outgoing responses be validated validation.responses.enabled=false +################################################### +# Search Features +################################################### +filter_search.enabled=true +graphql.enabled=true ################################################### # Supported Resources