Setting properties for ModelConfig in addition to DaoConfig

Setting properties for handling Email via the emailSender() bean
This commit is contained in:
Sean McIlvenna
2019-02-12 14:08:07 -08:00
parent 4aaf6038cd
commit 269dd77351
3 changed files with 129 additions and 21 deletions

View File

@@ -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;
}
}