1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.audit;
17
18 import org.openehealth.ipf.commons.audit.AuditContext;
19 import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
20 import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport;
21 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryError;
22 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryResponse;
23 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLRegistryResponse30;
24 import org.openehealth.ipf.commons.ihe.xds.core.responses.Severity;
25 import org.openehealth.ipf.commons.ihe.xds.core.responses.Status;
26 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rs.RegistryResponseType;
27
28
29
30
31
32
33 public abstract class XdsAuditStrategy<T extends XdsAuditDataset> extends AuditStrategySupport<T> {
34
35
36
37
38
39
40
41 public XdsAuditStrategy(boolean serverSide) {
42 super(serverSide);
43 }
44
45
46
47
48
49
50
51 private static EventOutcomeIndicator getEventOutcomeCodeFromRegistryResponse(EbXMLRegistryResponse response) {
52 try {
53 if (response.getStatus() == Status.SUCCESS) {
54 return EventOutcomeIndicator.Success;
55 }
56 if (response.getErrors().isEmpty()) {
57 return EventOutcomeIndicator.SeriousFailure;
58 }
59
60 for (EbXMLRegistryError error : response.getErrors()) {
61 if (error.getSeverity() == Severity.ERROR) {
62 return EventOutcomeIndicator.SeriousFailure;
63 }
64 }
65 return EventOutcomeIndicator.MinorFailure;
66 } catch (Exception e) {
67 return EventOutcomeIndicator.SeriousFailure;
68 }
69 }
70
71 private static String getEventOutcomeDescriptionFromRegistryResponse(EbXMLRegistryResponse response) {
72 if (response.getErrors().isEmpty()) {
73 return null;
74 }
75 for (EbXMLRegistryError error : response.getErrors()) {
76 if (error.getSeverity() == Severity.ERROR) {
77 return error.getCodeContext();
78 }
79 }
80 return response.getErrors().get(0).getCodeContext();
81 }
82
83
84 @Override
85 public EventOutcomeIndicator getEventOutcomeIndicator(Object pojo) {
86 RegistryResponseType response = (RegistryResponseType) pojo;
87 EbXMLRegistryResponse ebXML = new EbXMLRegistryResponse30(response);
88 return getEventOutcomeCodeFromRegistryResponse(ebXML);
89 }
90
91 @Override
92 public String getEventOutcomeDescription(Object pojo) {
93 RegistryResponseType response = (RegistryResponseType) pojo;
94 EbXMLRegistryResponse ebXML = new EbXMLRegistryResponse30(response);
95 return getEventOutcomeDescriptionFromRegistryResponse(ebXML);
96 }
97
98 @Override
99 public boolean enrichAuditDatasetFromResponse(T auditDataset, Object response, AuditContext auditContext) {
100 EventOutcomeIndicator outcomeCodes = getEventOutcomeIndicator(response);
101 auditDataset.setEventOutcomeIndicator(outcomeCodes);
102 auditDataset.setEventOutcomeDescription(getEventOutcomeDescription(response));
103 return outcomeCodes == EventOutcomeIndicator.Success;
104 }
105
106 }