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  
17  package org.openehealth.ipf.commons.ihe.fhir;
18  
19  import ca.uhn.fhir.model.primitive.InstantDt;
20  import ca.uhn.fhir.rest.api.server.IBundleProvider;
21  import org.hl7.fhir.instance.model.api.IBaseResource;
22  
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  /**
28   * Base class of a {@link IBundleProvider} delegating to a {@link RequestConsumer} instance
29   */
30  public abstract class AbstractBundleProvider implements IBundleProvider {
31  
32      private final RequestConsumer consumer;
33      private Object payload;
34      private Map<String, Object> headers;
35  
36      public AbstractBundleProvider(RequestConsumer consumer, Object payload, Map<String, Object> headers) {
37          this.consumer = consumer;
38          this.payload = payload;
39          this.headers = headers;
40      }
41  
42      @Override
43      public InstantDt getPublished() {
44          return InstantDt.withCurrentTime();
45      }
46  
47      @Override
48      public Integer preferredPageSize() {
49          return null;
50      }
51  
52      protected List<IBaseResource> obtainResources(Object payload, Map<String, Object> parameters) {
53          return consumer.handleBundleRequest(payload, parameters);
54      }
55  
56      protected RequestConsumer getConsumer() {
57          return consumer;
58      }
59  
60      /**
61       * @return a copy of the original query parameters
62       */
63      protected Map<String, Object> getHeaders() {
64          return new HashMap<>(headers);
65      }
66  
67      protected Object getPayload() {
68          return payload;
69      }
70  
71      @Override
72      public String getUuid() {
73          return null;
74      }
75  }