1 /* 2 * Copyright 2017 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.audit.queue; 18 19 import org.openehealth.ipf.commons.audit.AuditContext; 20 import org.openehealth.ipf.commons.audit.model.AuditMessage; 21 22 import java.util.stream.Stream; 23 24 /** 25 * <p> 26 * Abstract base class for message queues that serialize the AuditRecord into a wire format 27 * by using the configured {@link org.openehealth.ipf.commons.audit.marshal.SerializationStrategy SerializationStrategy} 28 * and send it to an ATNA repository using the configured {@link org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol}, 29 * </p> 30 * <p> 31 * There may be other use cases such as forwarding AuditMessages as object into a Camel Route or in-memory storage 32 * or convert them into FHIR AuditEvents. In this case, implement your own {@link AuditMessageQueue}. 33 * </p> 34 * 35 * @author Christian Ohr 36 * @since 3.5 37 */ 38 abstract class AbstractAuditMessageQueue implements AuditMessageQueue { 39 40 @Override 41 public void audit(AuditContext auditContext, AuditMessage... auditMessages) { 42 43 String[] auditRecords = Stream.of(auditMessages) 44 .map(msg -> auditContext.getSerializationStrategy().marshal(msg, false)) 45 .toArray(value -> new String[auditMessages.length]); 46 47 handle(auditContext, auditRecords); 48 } 49 50 protected abstract void handle(AuditContext auditContext, String... auditRecords); 51 52 53 }