1 /*
2 * Copyright 2009 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 lombok.extern.slf4j.Slf4j;
19 import org.openehealth.ipf.commons.xml.XsdValidator;
20 import org.openhealthtools.ihe.atna.auditor.events.AuditEventMessage;
21
22 import static org.openehealth.ipf.commons.xml.XmlUtils.source;
23
24 /**
25 * Mocked sender implementation for ATNA audit records.
26 * Records the messages to allow verification in tests and, optionally,
27 * validates them against the schema from DICOM Part 15 Appendix A.5.1.
28 *
29 * @author Jens Riemschneider
30 * @deprecated
31 */
32 @Slf4j
33 public class MockedSender extends AbstractMockedAuditSender<AuditEventMessage> {
34
35 private static final String NEW_VALIDATION_SCHEMA = "/atna2.xsd";
36 XsdValidator validator = new XsdValidator();
37
38 public MockedSender() {
39 super(true);
40 }
41
42 public MockedSender(boolean needValidation) {
43 super(needValidation);
44 }
45
46 @Override
47 public void sendAuditEvent(AuditEventMessage[] msg) throws Exception {
48 for (AuditEventMessage message : msg) {
49 String s = message.toString();
50 log.debug(s);
51 if (needValidation) {
52 validator.validate(source(s), NEW_VALIDATION_SCHEMA);
53 }
54 messages.add(message);
55 }
56 }
57
58 }