Setting properties for ModelConfig in addition to DaoConfig
Setting properties for handling Email via the emailSender() bean
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user