From 3c6343e20da69c34ea0757deb8f8b81c14df3d2c Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 4 Jul 2019 09:48:40 -0400 Subject: [PATCH] Allow customizing the list of supported resources --- .../ca/uhn/fhir/jpa/starter/HapiProperties.java | 13 +++++++++++++ .../ca/uhn/fhir/jpa/starter/JpaRestfulServer.java | 8 ++++++++ src/main/resources/hapi.properties | 13 +++++++++++++ 3 files changed, 34 insertions(+) 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 3cb3ebb..a33ad3c 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java @@ -8,7 +8,12 @@ import com.google.common.annotations.VisibleForTesting; import java.io.InputStream; import java.io.FileInputStream; +import java.util.Arrays; import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.apache.commons.lang3.StringUtils.*; public class HapiProperties { static final String ALLOW_EXTERNAL_REFERENCES = "allow_external_references"; @@ -268,6 +273,14 @@ public class HapiProperties { return HapiProperties.getProperty(CORS_ALLOWED_ORIGIN, "*"); } + public static Set getSupportedResourceTypes() { + String[] types = defaultString(getProperty("supported_resource_types")).split(","); + return Arrays.stream(types) + .map(t->trim(t)) + .filter(t->isNotBlank(t)) + .collect(Collectors.toSet()); + } + public static String getServerName() { return HapiProperties.getProperty(SERVER_NAME, "Local Tester"); } 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 512b184..2e1b996 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java @@ -35,6 +35,7 @@ import org.springframework.web.cors.CorsConfiguration; import javax.servlet.ServletException; import java.util.Arrays; +import java.util.Set; public class JpaRestfulServer extends RestfulServer { @@ -51,6 +52,13 @@ public class JpaRestfulServer extends RestfulServer { */ ApplicationContext appCtx = (ApplicationContext) getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT"); + // Customize supported resource types + Set supportedResourceTypes = HapiProperties.getSupportedResourceTypes(); + if (!supportedResourceTypes.isEmpty()) { + DaoRegistry daoRegistry = appCtx.getBean(DaoRegistry.class); + daoRegistry.setSupportedResourceTypes(supportedResourceTypes); + } + /* * ResourceProviders are fetched from the Spring context */ diff --git a/src/main/resources/hapi.properties b/src/main/resources/hapi.properties index f2e1888..537f034 100644 --- a/src/main/resources/hapi.properties +++ b/src/main/resources/hapi.properties @@ -38,6 +38,15 @@ datasource.password= server.name=Local Tester server.id=home test.port= + +# Enable the following property if you want to customize the +# list of resources that is supported by the server (i.e. to +# disable specific resources) +#supported_resource_types=Patient,Observation,Encounter + +################################################### +# Database Settings +################################################### hibernate.dialect=ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect hibernate.search.model_mapping=ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory hibernate.format_sql=false @@ -52,6 +61,10 @@ hibernate.search.default.directory_provider=filesystem hibernate.search.default.indexBase=target/lucenefiles hibernate.search.lucene_version=LUCENE_CURRENT tester.config.refuse_to_fetch_third_party_urls=false + +################################################## +# CORS Settings +################################################## cors.enabled=true cors.allowed_origin=*