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.commons.ihe.core.atna; 17 18 import org.openehealth.ipf.commons.audit.AuditContext; 19 import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; 20 21 import java.util.Map; 22 23 /** 24 * ATNA audit strategy base for transactions. This strategy is accompanied with a 25 * dedicated subclass of {@link AuditDataset} containing the data for the audit record. 26 * 27 * @author Christian Ohr 28 * @since 3.1 29 */ 30 public interface AuditStrategy<T extends AuditDataset> { 31 32 /** 33 * Creates a new audit dataset instance. 34 */ 35 T createAuditDataset(); 36 37 /** 38 * Enriches the given audit dataset with transaction-specific 39 * contents of the request message and Camel exchange. 40 * 41 * @param auditDataset audit dataset to be enriched. 42 * @param request {@link Object} representing the request. 43 * @param parameters additional parameters 44 */ 45 T enrichAuditDatasetFromRequest(T auditDataset, Object request, Map<String, Object> parameters); 46 47 48 /** 49 * Enriches the given audit dataset with transaction-specific 50 * contents of the response message. 51 * 52 * @param auditDataset audit dataset to be enriched. 53 * @param response {@link Object} representing the responded resource. 54 * @return true if response indicates success, false otherwise 55 */ 56 default boolean enrichAuditDatasetFromResponse(T auditDataset, Object response) { 57 return enrichAuditDatasetFromResponse(auditDataset, response, null); 58 } 59 60 /** 61 * Enriches the given audit dataset with transaction-specific 62 * contents of the response message. 63 * 64 * @param auditDataset audit dataset to be enriched. 65 * @param response {@link Object} representing the responded resource. 66 * @param auditContext audit context, if relevant 67 * @return true if response indicates success, false otherwise 68 */ 69 boolean enrichAuditDatasetFromResponse(T auditDataset, Object response, AuditContext auditContext); 70 71 72 /** 73 * Performs the actual ATNA audit. 74 * 75 * @param auditContext audit context used for auditing 76 * @param auditDataset Collected audit dataset. 77 */ 78 void doAudit(AuditContext auditContext, T auditDataset); 79 80 81 /** 82 * Determines whether the given response finalizes the interaction 83 * and thus the ATNA auditing should be finalized as well. 84 * <p> 85 * Per default always returns <code>true</code>. 86 * 87 * @param response response in transaction-specific format (POJO, XML string, etc.). 88 * @return <code>true</code> when this response finalizes the interaction. 89 */ 90 boolean isAuditableResponse(Object response); 91 92 /** 93 * Determines which event outcome corresponds with the provided response POJO 94 * 95 * @param response POJO 96 * @return event outcome code 97 */ 98 EventOutcomeIndicator getEventOutcomeIndicator(Object response); 99 100 /** 101 * Determines which event outcome description corresponds with the provided response POJO 102 * 103 * @param response POJO 104 * @return event outcome description 105 */ 106 String getEventOutcomeDescription(Object response); 107 }