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 org.apache.commons.lang3.Validate;
25  import org.springframework.beans.factory.annotation.Autowired;
26  
27  import javax.annotation.PostConstruct;
28  
29  public class SubscriptionEmailInterceptor extends BaseSubscriptionInterceptor {
30  	private SubscriptionDeliveringEmailSubscriber mySubscriptionDeliverySubscriber;
31  
32  	/**
33  	 * This is set to autowired=false just so that implementors can supply this
34  	 * with a mechanism other than autowiring if they want
35  	 */
36  	@Autowired(required = false)
37  	private IEmailSender myEmailSender;
38  	private String myDefaultFromAddress = "noreply@unknown.com";
39  
40  	@Override
41  	public org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType getChannelType() {
42  		return org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.EMAIL;
43  	}
44  
45  	/**
46  	 * The "from" address to use for any sent emails that to not explicitly specity a from address
47  	 */
48  	public String getDefaultFromAddress() {
49  		return myDefaultFromAddress;
50  	}
51  
52  	/**
53  	 * The "from" address to use for any sent emails that to not explicitly specity a from address
54  	 */
55  	public void setDefaultFromAddress(String theDefaultFromAddress) {
56  		Validate.notBlank(theDefaultFromAddress, "theDefaultFromAddress must not be null or blank");
57  		myDefaultFromAddress = theDefaultFromAddress;
58  	}
59  
60  	public IEmailSender getEmailSender() {
61  		return myEmailSender;
62  	}
63  
64  	/**
65  	 * Set the email sender (this method does not need to be explicitly called if you
66  	 * are using autowiring to supply the sender)
67  	 */
68  	public void setEmailSender(IEmailSender theEmailSender) {
69  		myEmailSender = theEmailSender;
70  	}
71  
72  	@Override
73  	protected void registerDeliverySubscriber() {
74  		if (mySubscriptionDeliverySubscriber == null) {
75  			mySubscriptionDeliverySubscriber = new SubscriptionDeliveringEmailSubscriber(getSubscriptionDao(), getChannelType(), this);
76  		}
77  		getDeliveryChannel().subscribe(mySubscriptionDeliverySubscriber);
78  	}
79  
80  //	@PostConstruct
81  //	public void start() {
82  //		Validate.notNull(myEmailSender, "emailSender has not been configured");
83  //
84  //		super.start();
85  //	}
86  
87  	@Override
88  	protected void unregisterDeliverySubscriber() {
89  		getDeliveryChannel().unsubscribe(mySubscriptionDeliverySubscriber);
90  	}
91  }