1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.platform.camel.ihe.atna.util;
18
19 import org.apache.camel.impl.DefaultComponent;
20 import org.openehealth.ipf.commons.audit.AuditContext;
21 import org.openehealth.ipf.commons.audit.AuditException;
22 import org.openehealth.ipf.commons.core.config.ContextFacade;
23
24 import java.util.Collection;
25 import java.util.Map;
26
27
28
29
30 public abstract class AuditConfiguration {
31
32 public static AuditContext obtainAuditContext(DefaultComponent component, Map<String, Object> parameters) {
33 Boolean audit = component.getAndRemoveParameter(parameters, "audit", Boolean.class, true);
34 AuditContext auditContext = component.resolveAndRemoveReferenceParameter(parameters, "auditContext", AuditContext.class);
35 if (auditContext == null) {
36 if (audit != null && !audit) {
37 auditContext = AuditContext.noAudit();
38 } else {
39 Collection<AuditContext> beans = ContextFacade.getBeans(AuditContext.class);
40 if (beans.size() == 1) {
41 auditContext = beans.iterator().next();
42 } else {
43 throw new AuditException("Must have exactly one bean of type " + AuditContext.class.getName() + ", but was : " + beans.size());
44 }
45 }
46 }
47 return auditContext;
48 }
49
50 }