From 269dd773514ff17e89e19e3a858c8a76ea682f34 Mon Sep 17 00:00:00 2001 From: Sean McIlvenna Date: Tue, 12 Feb 2019 14:08:07 -0800 Subject: [PATCH 1/2] Setting properties for ModelConfig in addition to DaoConfig Setting properties for handling Email via the emailSender() bean --- .../jpa/starter/FhirServerConfigCommon.java | 107 ++++++++++++++---- .../uhn/fhir/jpa/starter/HapiProperties.java | 35 ++++++ src/main/resources/hapi.properties | 8 ++ 3 files changed, 129 insertions(+), 21 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 e128044..7666173 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java @@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException; import java.sql.Driver; import ca.uhn.fhir.jpa.model.entity.ModelConfig; +import ca.uhn.fhir.jpa.subscription.module.subscriber.email.IEmailSender; +import ca.uhn.fhir.jpa.subscription.module.subscriber.email.JavaMailEmailSender; import org.apache.commons.dbcp2.BasicDataSource; import org.hl7.fhir.instance.model.Subscription; import org.springframework.beans.factory.annotation.Autowire; @@ -12,7 +14,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; import ca.uhn.fhir.jpa.dao.DaoConfig; -import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; @@ -26,6 +27,51 @@ public class FhirServerConfigCommon { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirServerConfigCommon.class); + private Boolean allowContainsSearches = HapiProperties.getAllowContainsSearches(); + private Boolean allowMultipleDelete = HapiProperties.getAllowMultipleDelete(); + private Boolean allowExternalReferences = HapiProperties.getAllowExternalReferences(); + private Boolean expungeEnabled = HapiProperties.getExpungeEnabled(); + private Boolean allowPlaceholderReferences = HapiProperties.getAllowPlaceholderReferences(); + private Boolean subscriptionRestHookEnabled = HapiProperties.getSubscriptionRestHookEnabled(); + private Boolean subscriptionEmailEnabled = HapiProperties.getSubscriptionEmailEnabled(); + private Boolean allowOverrideDefaultSearchParams = HapiProperties.getAllowOverrideDefaultSearchParams(); + private String emailFrom = HapiProperties.getEmailFrom(); + private Boolean emailEnabled = HapiProperties.getEmailEnabled(); + private String emailHost = HapiProperties.getEmailHost(); + private Integer emailPort = HapiProperties.getEmailPort(); + private String emailUsername = HapiProperties.getEmailUsername(); + private String emailPassword = HapiProperties.getEmailPassword(); + + public FhirServerConfigCommon() { + ourLog.info("Server configured to " + (this.allowContainsSearches ? "allow" : "deny") + " contains searches"); + ourLog.info("Server configured to " + (this.allowMultipleDelete ? "allow" : "deny") + " multiple deletes"); + ourLog.info("Server configured to " + (this.allowExternalReferences ? "allow" : "deny") + " external references"); + ourLog.info("Server configured to " + (this.expungeEnabled ? "enable" : "disable") + " expunges"); + ourLog.info("Server configured to " + (this.allowPlaceholderReferences ? "allow" : "deny") + " placeholder references"); + ourLog.info("Server configured to " + (this.allowOverrideDefaultSearchParams ? "allow" : "deny") + " overriding default search params"); + + if (this.emailEnabled) { + ourLog.info("Server is configured to enable email with host '" + this.emailHost + "' and port " + this.emailPort.toString()); + ourLog.info("Server will use '" + this.emailFrom + "' as the from email address"); + + if (this.emailUsername != null && this.emailUsername.length() > 0) { + ourLog.info("Server is configured to use username '" + this.emailUsername + "' for email"); + } + + if (this.emailPassword != null && this.emailPassword.length() > 0) { + ourLog.info("Server is configured to use a password for email"); + } + } + + if (this.subscriptionRestHookEnabled) { + ourLog.info("REST-hook subscriptions enabled"); + } + + if (this.subscriptionEmailEnabled) { + ourLog.info("Email subscriptions enabled"); + } + } + /** * Configure FHIR properties around the the JPA server via this bean */ @@ -33,30 +79,19 @@ public class FhirServerConfigCommon { public DaoConfig daoConfig() { DaoConfig retVal = new DaoConfig(); - Boolean allowMultipleDelete = HapiProperties.getAllowMultipleDelete(); - retVal.setAllowMultipleDelete(allowMultipleDelete); - ourLog.info("Server configured to " + (allowMultipleDelete ? "allow" : "deny") + " multiple deletes"); - - Boolean allowExternalReferences = HapiProperties.getAllowExternalReferences(); - retVal.setAllowExternalReferences(allowExternalReferences); - ourLog.info("Server configured to " + (allowExternalReferences ? "allow" : "deny") + " external references"); - - Boolean expungeEnabled = HapiProperties.getExpungeEnabled(); - retVal.setExpungeEnabled(expungeEnabled); - ourLog.info("Server configured to " + (expungeEnabled ? "enable" : "disable") + " expunges"); - - Boolean allowPlaceholderReferences = HapiProperties.getAllowPlaceholderReferences(); - retVal.setAutoCreatePlaceholderReferenceTargets(allowPlaceholderReferences); - ourLog.info("Server configured to " + (allowPlaceholderReferences ? "allow" : "deny") + " placeholder references"); + retVal.setAllowContainsSearches(this.allowContainsSearches); + retVal.setAllowMultipleDelete(this.allowMultipleDelete); + retVal.setAllowExternalReferences(this.allowExternalReferences); + retVal.setExpungeEnabled(this.expungeEnabled); + retVal.setAutoCreatePlaceholderReferenceTargets(this.allowPlaceholderReferences); + retVal.setEmailFromAddress(this.emailFrom); // You can enable these if you want to support Subscriptions from your server - if (HapiProperties.getSubscriptionRestHookEnabled()) { - ourLog.info("Enabling REST-hook subscriptions"); + if (this.subscriptionRestHookEnabled) { retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK); } - if (HapiProperties.getSubscriptionEmailEnabled()) { - ourLog.info("Enabling email subscriptions"); + if (this.subscriptionEmailEnabled) { retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL); } @@ -65,7 +100,22 @@ public class FhirServerConfigCommon { @Bean public ModelConfig modelConfig() { - return new ModelConfig(); + ModelConfig modelConfig = new ModelConfig(); + modelConfig.setAllowContainsSearches(this.allowContainsSearches); + modelConfig.setAllowExternalReferences(this.allowExternalReferences); + modelConfig.setDefaultSearchParamsCanBeOverridden(this.allowOverrideDefaultSearchParams); + modelConfig.setEmailFromAddress(this.emailFrom); + + // You can enable these if you want to support Subscriptions from your server + if (this.subscriptionRestHookEnabled) { + modelConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK); + } + + if (this.subscriptionEmailEnabled) { + modelConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL); + } + + return modelConfig; } /** @@ -107,4 +157,19 @@ public class FhirServerConfigCommon { return retVal; } + @Bean() + public IEmailSender emailSender() { + if (this.emailEnabled) { + JavaMailEmailSender retVal = new JavaMailEmailSender(); + + retVal.setSmtpServerHostname(this.emailHost); + retVal.setSmtpServerPort(this.emailPort); + retVal.setSmtpServerUsername(this.emailUsername); + retVal.setSmtpServerPassword(this.emailPassword); + + return retVal; + } + + return null; + } } 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 f4fb68b..a59687c 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/HapiProperties.java @@ -36,6 +36,9 @@ public class HapiProperties { static final String SUBSCRIPTION_EMAIL_ENABLED = "subscription.email.enabled"; static final String SUBSCRIPTION_RESTHOOK_ENABLED = "subscription.resthook.enabled"; static final String TEST_PORT = "test.port"; + 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"; private static Properties properties; @@ -235,4 +238,36 @@ public class HapiProperties { public static Boolean getSubscriptionRestHookEnabled() { return HapiProperties.getBooleanProperty(SUBSCRIPTION_RESTHOOK_ENABLED, true); } + + public static Boolean getAllowContainsSearches() { + return HapiProperties.getBooleanProperty(ALLOW_CONTAINS_SEARCHES, true); + } + + public static Boolean getAllowOverrideDefaultSearchParams() { + return HapiProperties.getBooleanProperty(ALLOW_OVERRIDE_DEFAULT_SEARCH_PARAMS, true); + } + + public static String getEmailFrom() { + return HapiProperties.getProperty(EMAIL_FROM, "some@test.com"); + } + + public static Boolean getEmailEnabled() { + return HapiProperties.getBooleanProperty("email.enabled", false); + } + + public static String getEmailHost() { + return HapiProperties.getProperty("email.host"); + } + + public static Integer getEmailPort() { + return HapiProperties.getIntegerProperty("email.port", 0); + } + + public static String getEmailUsername() { + return HapiProperties.getProperty("email.username"); + } + + public static String getEmailPassword() { + return HapiProperties.getProperty("email.password"); + } } diff --git a/src/main/resources/hapi.properties b/src/main/resources/hapi.properties index 332825e..1a1a5d1 100644 --- a/src/main/resources/hapi.properties +++ b/src/main/resources/hapi.properties @@ -16,6 +16,8 @@ default_encoding=JSON etag_support=ENABLED default_page_size=20 max_page_size=200 +allow_override_default_search_params=true +allow_contains_searches=true allow_multiple_delete=true allow_external_references=true allow_placeholder_references=true @@ -33,6 +35,12 @@ server.name=Local Tester server.id=home test.port= subscription.email.enabled=true +email.enabled=false +email.from=some@test.com +email.host= +email.port=0 +email.username= +email.password= subscription.resthook.enabled=true hibernate.dialect=ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect hibernate.search.model_mapping=ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory From d829b91c03ed060f5b6d97cfe0232c18812b861c Mon Sep 17 00:00:00 2001 From: Joao Vicente Date: Thu, 21 Feb 2019 21:07:42 +0000 Subject: [PATCH 2/2] README stating config changes required for Jetty --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad0eb2b..f4ca773 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ In order to use this sample, you should have: # Running Locally -The easiest way to run this server is to run it directly in Maven using a built-in Jetty server. To do this, execute the following command: +The easiest way to run this server is to run it directly in Maven using a built-in Jetty server. To do this, change `src/main/resources/hapi.properties` `server_address` and `server.base` with the values commented out as *For Jetty, use this* and then execute the following command: ``` mvn jetty:run @@ -62,4 +62,4 @@ To configure the starter app to use MySQL, instead of the default Derby, update * datasource.url=jdbc:mysql://localhost:3306/hapi_dstu3 * hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -It is important to use MySQL5Dialect when using MySQL version 5+. \ No newline at end of file +It is important to use MySQL5Dialect when using MySQL version 5+.