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  
17  package org.openehealth.ipf.commons.ihe.core.atna;
18  
19  import lombok.AccessLevel;
20  import lombok.Getter;
21  import org.openehealth.ipf.commons.audit.AuditContext;
22  import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
23  import org.openehealth.ipf.commons.audit.model.AuditMessage;
24  
25  import java.util.Map;
26  
27  /**
28   * @since 3.1
29   */
30  public abstract class AuditStrategySupport<T extends AuditDataset> implements AuditStrategy<T> {
31  
32      @Getter(AccessLevel.PROTECTED)
33      private final boolean serverSide;
34  
35  
36      /**
37       * @param serverSide <code>true</code> when this strategy is a server-side one;
38       *                   <code>false</code> otherwise.
39       */
40      protected AuditStrategySupport(boolean serverSide) {
41          this.serverSide = serverSide;
42      }
43  
44  
45      @Override
46      public void doAudit(AuditContext auditContext, T auditDataset) {
47          auditContext.audit(makeAuditMessage(auditContext, auditDataset));
48      }
49  
50      /**
51       * Constructs an {@link AuditMessage} from a provided {@link AuditDataset}
52       *
53       * @param auditContext audit context
54       * @param auditDataset audit dataset
55       * @return audit message
56       */
57      public abstract AuditMessage[] makeAuditMessage(AuditContext auditContext, T auditDataset);
58  
59  
60      @Override
61      public T enrichAuditDatasetFromRequest(T auditDataset, Object request, Map<String, Object> parameters) {
62          return auditDataset;
63      }
64  
65      @Override
66      public boolean enrichAuditDatasetFromResponse(T auditDataset, Object response, AuditContext auditContext) {
67          return true;
68      }
69  
70  
71      @Override
72      public EventOutcomeIndicator getEventOutcomeIndicator(Object response) {
73          return null;
74      }
75  
76      @Override
77      public String getEventOutcomeDescription(Object response) {
78          return null;
79      }
80  
81      @Override
82      public boolean isAuditableResponse(Object response) {
83          return true;
84      }
85  
86  }