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.xds.dispatch;
17  
18  import lombok.extern.slf4j.Slf4j;
19  import org.apache.cxf.jaxws.context.WebServiceContextImpl;
20  import org.openehealth.ipf.commons.audit.AuditContext;
21  import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
22  import org.openehealth.ipf.commons.audit.model.AuditMessage;
23  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport;
24  import org.openehealth.ipf.commons.ihe.xds.chxcmu.ChXcmuServerAuditStrategy;
25  import org.openehealth.ipf.commons.ihe.xds.core.audit.XdsAuditDataset;
26  import org.openehealth.ipf.commons.ihe.xds.core.audit.XdsAuditStrategy;
27  import org.openehealth.ipf.commons.ihe.xds.iti18.Iti18AuditStrategy;
28  import org.openehealth.ipf.commons.ihe.xds.iti38.Iti38AuditStrategy;
29  import org.openehealth.ipf.commons.ihe.xds.iti39.Iti39ServerAuditStrategy;
30  import org.openehealth.ipf.commons.ihe.xds.iti41.Iti41ServerAuditStrategy;
31  import org.openehealth.ipf.commons.ihe.xds.iti42.Iti42ServerAuditStrategy;
32  import org.openehealth.ipf.commons.ihe.xds.iti43.Iti43ServerAuditStrategy;
33  import org.openehealth.ipf.commons.ihe.xds.iti51.Iti51AuditStrategy;
34  import org.openehealth.ipf.commons.ihe.xds.iti57.Iti57ServerAuditStrategy;
35  import org.openehealth.ipf.commons.ihe.xds.iti61.Iti61ServerAuditStrategy;
36  import org.openehealth.ipf.commons.ihe.xds.iti62.Iti62AuditStrategy;
37  import org.openehealth.ipf.commons.ihe.xds.iti63.Iti63AuditStrategy;
38  import org.openehealth.ipf.commons.ihe.xds.iti80.Iti80ServerAuditStrategy;
39  import org.openehealth.ipf.commons.ihe.xds.iti86.Iti86AuditStrategy;
40  import org.openehealth.ipf.commons.ihe.xds.rad69.Rad69ServerAuditStrategy;
41  import org.openehealth.ipf.commons.ihe.xds.rad75.Rad75ServerAuditStrategy;
42  
43  import javax.xml.namespace.QName;
44  import javax.xml.ws.handler.MessageContext;
45  import java.util.HashMap;
46  import java.util.Map;
47  
48  /**
49   * Audit strategy which wraps a set of transaction-specific audit strategies and dispatches
50   * calls to one of them depending of which WSDL operation is currently being processed.
51   *
52   * @author Dmytro Rud
53   */
54  @Slf4j
55  public class DispatchAuditStrategy<T extends XdsAuditDataset> extends AuditStrategySupport<T> {
56  
57      private final Map<QName, XdsAuditStrategy<? extends XdsAuditDataset>> map;
58  
59      public DispatchAuditStrategy(Map<QName, XdsAuditStrategy<? extends XdsAuditDataset>> additionalMappings) {
60          super(true);
61          map = new HashMap<>();
62          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRegistry_RegistryStoredQuery"),
63                  new Iti18AuditStrategy(true));
64          map.put(new QName("urn:ihe:iti:xds-b:2007", "RespondingGateway_CrossGatewayQuery"),
65                  new Iti38AuditStrategy(true));
66          map.put(new QName("urn:ihe:iti:xds-b:2007", "RespondingGateway_CrossGatewayRetrieve"),
67                  new Iti39ServerAuditStrategy());
68          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_ProvideAndRegisterDocumentSet-b"),
69                  new Iti41ServerAuditStrategy());
70          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRegistry_RegisterDocumentSet-b"),
71                  new Iti42ServerAuditStrategy());
72          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_RetrieveDocumentSet"),
73                  new Iti43ServerAuditStrategy());
74          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRegistry_MultiPatientStoredQuery"),
75                  new Iti51AuditStrategy(true));
76          map.put(new QName("urn:ihe:iti:xds-b:2010", "DocumentRegistry_UpdateDocumentSet"),
77                  new Iti57ServerAuditStrategy());
78          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRegistry_RegisterOnDemandDocumentEntry"),
79                  new Iti61ServerAuditStrategy());
80          map.put(new QName("urn:ihe:iti:xds-b:2010", "DocumentRegistry_DeleteDocumentSet"),
81                  new Iti62AuditStrategy(true));
82          map.put(new QName("urn:ihe:iti:xds-b:2007", "RespondingGateway_CrossGatewayFetch"),
83                  new Iti63AuditStrategy(true));
84          map.put(new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_CrossGatewayDocumentProvide"),
85                  new Iti80ServerAuditStrategy());
86          map.put(new QName("urn:ihe:iti:rmd:2017", "DocumentRepository_RemoveDocuments"),
87                  new Iti86AuditStrategy(true));
88          map.put(new QName("urn:ihe:rad:xdsi-b:2009", "DocumentRepository_RetrieveImagingDocumentSet"),
89                  new Rad69ServerAuditStrategy());
90          map.put(new QName("urn:ihe:rad:xdsi-b:2009", "RespondingGateway_CrossGatewayRetrieveImagingDocumentSet"),
91                  new Rad75ServerAuditStrategy());
92          map.put(new QName("urn:ihe:iti:xcmu:2017", "RespondingGateway_CrossGatewayUpdateDocumentSet"),
93                  new ChXcmuServerAuditStrategy());
94          if (additionalMappings != null) {
95              map.putAll(additionalMappings);
96          }
97      }
98  
99      @Override
100     public T createAuditDataset() {
101         XdsAuditStrategy<? extends XdsAuditDataset> strategy = getAuditStrategy();
102         return (strategy != null) ? (T)strategy.createAuditDataset() : null;
103     }
104 
105     @Override
106     public T enrichAuditDatasetFromRequest(T auditDataset, Object request, Map<String, Object> parameters ) {
107         XdsAuditStrategy<T> strategy = (XdsAuditStrategy<T>)getAuditStrategy();
108         if (strategy != null) {
109             return strategy.enrichAuditDatasetFromRequest(auditDataset, request, parameters);
110         }
111         return null;
112     }
113 
114     @Override
115     public boolean enrichAuditDatasetFromResponse(T auditDataset, Object response, AuditContext auditContext) {
116         XdsAuditStrategy<T> strategy = (XdsAuditStrategy<T>)getAuditStrategy();
117         if (strategy != null) {
118             return strategy.enrichAuditDatasetFromResponse(auditDataset, response, auditContext);
119         }
120         return false;
121     }
122 
123     @Override
124     public void doAudit(AuditContext auditContext, T auditDataset) {
125         XdsAuditStrategy<T> strategy = (XdsAuditStrategy<T>)getAuditStrategy();
126         if (strategy != null) {
127             strategy.doAudit(auditContext, auditDataset);
128         }
129     }
130 
131     @Override
132     public AuditMessage[] makeAuditMessage(AuditContext auditContext, T auditDataset) {
133         XdsAuditStrategy<T> strategy = (XdsAuditStrategy<T>)getAuditStrategy();
134         return (strategy != null) ? strategy.makeAuditMessage(auditContext, auditDataset) : null;
135     }
136 
137     @Override
138     public EventOutcomeIndicator getEventOutcomeIndicator(Object response) {
139         XdsAuditStrategy<? extends XdsAuditDataset> strategy = getAuditStrategy();
140         return (strategy != null) ? strategy.getEventOutcomeIndicator(response) : null;
141     }
142 
143     private XdsAuditStrategy<? extends XdsAuditDataset> getAuditStrategy() {
144         MessageContext messageContext = new WebServiceContextImpl().getMessageContext();
145         if ("GET".equals(messageContext.get(MessageContext.HTTP_REQUEST_METHOD))) {
146             return null;
147         }
148         if (! messageContext.containsKey(MessageContext.WSDL_OPERATION)) {
149             return null;
150         }
151 
152         QName operationName = (QName) messageContext.get(MessageContext.WSDL_OPERATION);
153         XdsAuditStrategy<? extends XdsAuditDataset> auditStrategy = map.get(operationName);
154         if (auditStrategy == null) {
155             log.debug("No strategy could be found for operation {}", operationName);
156         } else {
157             log.debug("Found strategy {} for operation {}", auditStrategy.getClass().getCanonicalName(), operationName);
158         }
159         return auditStrategy;
160     } 
161 }