View Javadoc
1   /*
2    * Copyright 2015 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.platform.camel.ihe.mllp.custom;
17  
18  import lombok.Setter;
19  import org.apache.camel.CamelContext;
20  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategy;
21  import org.openehealth.ipf.commons.ihe.hl7v2.Hl7v2TransactionConfiguration;
22  import org.openehealth.ipf.commons.ihe.hl7v2.NakFactory;
23  import org.openehealth.ipf.commons.ihe.hl7v2.audit.MllpAuditDataset;
24  import org.openehealth.ipf.platform.camel.ihe.mllp.core.MllpTransactionComponent;
25  import org.openehealth.ipf.platform.camel.ihe.mllp.core.MllpTransactionEndpointConfiguration;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.util.Map;
30  
31  /**
32   * Component for custom MLLP components. The HL7v2 configuration as well as the ATNA audit strategies must be
33   * provided as endpoint parameters "hl7TransactionConfig", "clientAuditStrategy", and "serverAuditStrategy".
34   *
35   * @author Christian Ohr
36   */
37  public class CustomMllpComponent<AuditDatasetType extends MllpAuditDataset> extends MllpTransactionComponent<AuditDatasetType> {
38  
39      private static final Logger LOG = LoggerFactory.getLogger(CustomMllpComponent.class);
40  
41      @Setter
42      private Hl7v2TransactionConfiguration<AuditDatasetType> transactionConfiguration;
43  
44      public CustomMllpComponent() {
45          super(null);
46      }
47  
48      public CustomMllpComponent(CamelContext camelContext) {
49          super(camelContext, null);
50      }
51  
52      @Override
53      protected MllpTransactionEndpointConfiguration createConfig(String uri, Map<String, Object> parameters) throws Exception {
54          MllpTransactionEndpointConfiguration transactionConfig = super.createConfig(uri, parameters);
55          Hl7v2TransactionConfiguration configuration = resolveAndRemoveReferenceParameter(parameters, "hl7TransactionConfig", Hl7v2TransactionConfiguration.class);
56          if (this.transactionConfiguration == null) {
57              if (configuration == null) {
58                  throw new IllegalArgumentException("Must provide hl7TransactionConfig attribute with custom MLLP component");
59              } else {
60                  this.transactionConfiguration = configuration;
61              }
62          } else {
63              if (configuration != null) {
64                  throw new IllegalArgumentException("Must not override preconfigured hl7TransactionConfig in custom MLLP component");
65              }
66          }
67          if (transactionConfig.isAudit() && getClientAuditStrategy() == null) {
68              throw new IllegalArgumentException("Consumer or Producer require ATNA audit, but no clientAuditStrategy is defined for custom MLLP component");
69          }
70          if (transactionConfig.isAudit() && getServerAuditStrategy() == null) {
71              throw new IllegalArgumentException("Consumer or Producer require ATNA audit, but no serverAuditStrategy is defined for custom MLLP component");
72          }
73          return transactionConfig;
74      }
75  
76      @Override
77      public Hl7v2TransactionConfiguration<AuditDatasetType> getHl7v2TransactionConfiguration() {
78          return transactionConfiguration;
79      }
80  
81      @Override
82      public AuditStrategy<AuditDatasetType> getClientAuditStrategy() {
83          return transactionConfiguration.getClientAuditStrategy();
84      }
85  
86      @Override
87      public AuditStrategy<AuditDatasetType> getServerAuditStrategy() {
88          return transactionConfiguration.getServerAuditStrategy();
89      }
90  
91      @Override
92      public NakFactory<AuditDatasetType> getNakFactory() {
93          return new NakFactory(transactionConfiguration);
94      }
95  
96  }