View Javadoc
1   package ca.uhn.fhir.jpa.subscription.email;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.jpa.subscription.BaseSubscriptionInterceptor;
24  import ca.uhn.fhir.jpa.subscription.CanonicalSubscription;
25  import org.apache.commons.lang3.Validate;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.messaging.MessageHandler;
28  
29  import java.util.Optional;
30  
31  public class SubscriptionEmailInterceptor extends BaseSubscriptionInterceptor {
32  
33  	/**
34  	 * This is set to autowired=false just so that implementors can supply this
35  	 * with a mechanism other than autowiring if they want
36  	 */
37  	@Autowired(required = false)
38  	private IEmailSender myEmailSender;
39  	private String myDefaultFromAddress = "noreply@unknown.com";
40  
41  	@Override
42  	protected Optional<MessageHandler> createDeliveryHandler(CanonicalSubscription theSubscription) {
43  		return Optional.of(new SubscriptionDeliveringEmailSubscriber(getSubscriptionDao(), getChannelType(), this));
44  	}
45  
46  	@Override
47  	public org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType getChannelType() {
48  		return org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.EMAIL;
49  	}
50  
51  	/**
52  	 * The "from" address to use for any sent emails that to not explicitly specity a from address
53  	 */
54  	public String getDefaultFromAddress() {
55  		return myDefaultFromAddress;
56  	}
57  
58  	/**
59  	 * The "from" address to use for any sent emails that to not explicitly specity a from address
60  	 */
61  	public void setDefaultFromAddress(String theDefaultFromAddress) {
62  		Validate.notBlank(theDefaultFromAddress, "theDefaultFromAddress must not be null or blank");
63  		myDefaultFromAddress = theDefaultFromAddress;
64  	}
65  
66  	public IEmailSender getEmailSender() {
67  		return myEmailSender;
68  	}
69  
70  	/**
71  	 * Set the email sender (this method does not need to be explicitly called if you
72  	 * are using autowiring to supply the sender)
73  	 */
74  	public void setEmailSender(IEmailSender theEmailSender) {
75  		myEmailSender = theEmailSender;
76  	}
77  
78  
79  }