View Javadoc
1   package ca.uhn.fhir.jpa.subscription.dbmatcher;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2019 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.dao.DaoConfig;
24  import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription;
25  import ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage;
26  import ca.uhn.fhir.jpa.subscription.module.matcher.ISubscriptionMatcher;
27  import ca.uhn.fhir.jpa.subscription.module.matcher.InMemorySubscriptionMatcher;
28  import ca.uhn.fhir.jpa.subscription.module.matcher.SubscriptionMatchResult;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  import org.springframework.beans.factory.annotation.Autowired;
32  
33  public class CompositeInMemoryDaoSubscriptionMatcher implements ISubscriptionMatcher {
34  	private Logger ourLog = LoggerFactory.getLogger(CompositeInMemoryDaoSubscriptionMatcher.class);
35  
36  	private final DaoSubscriptionMatcher myDaoSubscriptionMatcher;
37  	private final InMemorySubscriptionMatcher myInMemorySubscriptionMatcher;
38  	@Autowired
39  	DaoConfig myDaoConfig;
40  
41  	public CompositeInMemoryDaoSubscriptionMatcher(DaoSubscriptionMatcher theDaoSubscriptionMatcher, InMemorySubscriptionMatcher theInMemorySubscriptionMatcher) {
42  		myDaoSubscriptionMatcher = theDaoSubscriptionMatcher;
43  		myInMemorySubscriptionMatcher = theInMemorySubscriptionMatcher;
44  	}
45  
46  	@Override
47  	public SubscriptionMatchResult match(CanonicalSubscription theSubscription, ResourceModifiedMessage theMsg) {
48  		SubscriptionMatchResult result;
49  		if (myDaoConfig.isEnableInMemorySubscriptionMatching()) {
50  			result = myInMemorySubscriptionMatcher.match(theSubscription, theMsg);
51  			if (result.supported()) {
52  				// TODO KHS test
53  				result.setInMemory(true);
54  			} else {
55  				ourLog.info("Criteria {} for Subscription {} not supported by InMemoryMatcher: {}.  Reverting to DatabaseMatcher", theSubscription.getCriteriaString(), theSubscription.getIdElementString(), result.getUnsupportedReason());
56  				result = myDaoSubscriptionMatcher.match(theSubscription, theMsg);
57  			}
58  		} else {
59  			result = myDaoSubscriptionMatcher.match(theSubscription, theMsg);
60  		}
61  		return result;
62  	}
63  }