View Javadoc
1   package ca.uhn.fhir.jpa.subscription;
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.context.FhirContext;
24  import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
25  import org.hl7.fhir.r4.model.Subscription;
26  import org.springframework.messaging.MessageHandler;
27  
28  public abstract class BaseSubscriptionSubscriber implements MessageHandler {
29  
30  	private final IFhirResourceDao<?> mySubscriptionDao;
31  	private final Subscription.SubscriptionChannelType myChannelType;
32  	private final BaseSubscriptionInterceptor mySubscriptionInterceptor;
33  
34  	/**
35  	 * Constructor
36  	 */
37  	public BaseSubscriptionSubscriber(IFhirResourceDao<?> theSubscriptionDao, Subscription.SubscriptionChannelType theChannelType, BaseSubscriptionInterceptor theSubscriptionInterceptor) {
38  		mySubscriptionDao = theSubscriptionDao;
39  		myChannelType = theChannelType;
40  		mySubscriptionInterceptor = theSubscriptionInterceptor;
41  	}
42  
43  	public Subscription.SubscriptionChannelType getChannelType() {
44  		return myChannelType;
45  	}
46  
47  	public FhirContext getContext() {
48  		return getSubscriptionDao().getContext();
49  	}
50  
51  	public IFhirResourceDao getSubscriptionDao() {
52  		return mySubscriptionDao;
53  	}
54  
55  	public BaseSubscriptionInterceptor getSubscriptionInterceptor() {
56  		return mySubscriptionInterceptor;
57  	}
58  
59  
60  	/**
61  	 * Does this subscription type (e.g. rest hook, websocket, etc) apply to this interceptor?
62  	 */
63  	protected boolean subscriptionTypeApplies(CanonicalSubscription theSubscription) {
64  		Subscription.SubscriptionChannelType channelType = getChannelType();
65  		String subscriptionType = theSubscription.getChannelType().toCode();
66  		return subscriptionTypeApplies(subscriptionType, channelType);
67  	}
68  
69  	/**
70  	 * Does this subscription type (e.g. rest hook, websocket, etc) apply to this interceptor?
71  	 */
72  	static boolean subscriptionTypeApplies(String theSubscriptionChannelTypeCode, Subscription.SubscriptionChannelType theChannelType) {
73  		boolean subscriptionTypeApplies = false;
74   		if (theSubscriptionChannelTypeCode != null) {
75  			if (theChannelType.toCode().equals(theSubscriptionChannelTypeCode)) {
76  				subscriptionTypeApplies = true;
77  			}
78  		}
79  		return subscriptionTypeApplies;
80  	}
81  
82  }