View Javadoc
1   /*
2    * Copyright 2016 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.fhir;
17  
18  import ca.uhn.fhir.context.FhirContext;
19  import ca.uhn.fhir.context.PerformanceOptionsEnum;
20  import org.openehealth.ipf.commons.ihe.core.TransactionConfiguration;
21  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategy;
22  import org.openehealth.ipf.commons.ihe.fhir.audit.FhirAuditDataset;
23  
24  import java.util.Collections;
25  import java.util.List;
26  
27  /**
28   * Static configuration for FHIR transaction components
29   *
30   * @author Christian Ohr
31   * @since 3.2
32   */
33  public class FhirTransactionConfiguration<T extends FhirAuditDataset> extends TransactionConfiguration<T> {
34  
35      private final FhirContext fhirContext;
36      private final List<? extends AbstractPlainProvider> staticResourceProviders;
37      private final ClientRequestFactory<?> staticClientRequestFactory;
38      private final FhirTransactionValidator fhirValidator;
39      private boolean supportsLazyLoading;
40      private boolean deferModelScanning;
41  
42      public FhirTransactionConfiguration(
43              String name,
44              String description,
45              boolean isQuery,
46              AuditStrategy<T> clientAuditStrategy,
47              AuditStrategy<T> serverAuditStrategy,
48              FhirContext fhirContext,
49              AbstractPlainProvider resourceProvider,
50              ClientRequestFactory<?> clientRequestFactory,
51              FhirTransactionValidator fhirValidator) {
52          this(name, description, isQuery, clientAuditStrategy, serverAuditStrategy, fhirContext,
53                  Collections.singletonList(resourceProvider), clientRequestFactory, fhirValidator);
54      }
55  
56      public FhirTransactionConfiguration(
57              String name,
58              String description,
59              boolean isQuery,
60              AuditStrategy<T> clientAuditStrategy,
61              AuditStrategy<T> serverAuditStrategy,
62              FhirContext fhirContext,
63              List<? extends AbstractPlainProvider> resourceProviders,
64              ClientRequestFactory<?> clientRequestFactory,
65              FhirTransactionValidator fhirValidator) {
66          super(name, description, isQuery, clientAuditStrategy, serverAuditStrategy);
67          this.fhirContext = fhirContext;
68          this.staticResourceProviders = resourceProviders;
69          this.staticClientRequestFactory = clientRequestFactory;
70          this.fhirValidator = fhirValidator;
71      }
72  
73      public List<? extends AbstractPlainProvider> getStaticResourceProvider() {
74          return staticResourceProviders;
75      }
76  
77      public ClientRequestFactory<?> getStaticClientRequestFactory() {
78          return staticClientRequestFactory;
79      }
80  
81      public FhirContext initializeFhirContext() {
82          fhirContext.setRestfulClientFactory(new SslAwareApacheRestfulClientFactory(fhirContext));
83          if (deferModelScanning) {
84              fhirContext.setPerformanceOptions(PerformanceOptionsEnum.DEFERRED_MODEL_SCANNING);
85          }
86          return fhirContext;
87      }
88  
89      public FhirTransactionValidator getFhirValidator() {
90          return fhirValidator;
91      }
92  
93      /**
94       * Determines if the component and backend implementation does support lazy-loading of search result sets.
95       * Even if true, the endpoint URI, however, must be explicitly configured to use lazy-loading.
96       *
97       * @param supportsLazyLoading true if this component support lazy-loading
98       */
99      public void setSupportsLazyLoading(boolean supportsLazyLoading) {
100         this.supportsLazyLoading = supportsLazyLoading;
101     }
102 
103     public boolean supportsLazyLoading() {
104         return supportsLazyLoading;
105     }
106 
107     public boolean isDeferModelScanning() {
108         return deferModelScanning;
109     }
110 
111     /**
112      * By default, HAPI will scan each model type it encounters as soon as it encounters it. This scan includes a check
113      * for all fields within the type, and makes use of reflection to do this. While this process is not particularly significant
114      * on reasonably performant machines, on some devices it may be desirable to defer this scan. When the scan is deferred,
115      * objects will only be scanned when they are actually accessed, meaning that only types that are actually used in an
116      * application get scanned.
117      */
118     public void setDeferModelScanning(boolean deferModelScanning) {
119         this.deferModelScanning = deferModelScanning;
120     }
121 }