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.ihe.xds.core.responses.Severity;
20 import org.openehealth.ipf.commons.ihe.xds.core.responses.Status;
21 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rs.RegistryError;
22 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rs.RegistryResponseType;
23
24 import static org.openehealth.ipf.commons.ihe.xds.core.audit.XdsNonconstructiveDocumentSetRequestAuditDataset.Status.NOT_SUCCESSFUL;
25 import static org.openehealth.ipf.commons.ihe.xds.core.audit.XdsNonconstructiveDocumentSetRequestAuditDataset.Status.SUCCESSFUL;
26
27
28
29
30
31
32
33 public abstract class XdsRemoveDocumentAuditStrategy30 extends XdsNonconstructiveDocumentSetRequestAuditStrategy30 {
34
35 public XdsRemoveDocumentAuditStrategy30(boolean serverSide) {
36 super(serverSide);
37 }
38
39 @Override
40 public XdsNonconstructiveDocumentSetRequestAuditDataset.Status getDefaultDocumentStatus() {
41 return SUCCESSFUL;
42 }
43
44 @Override
45 public boolean enrichAuditDatasetFromResponse(XdsNonconstructiveDocumentSetRequestAuditDataset auditDataset, Object pojo, AuditContext auditContext) {
46 RegistryResponseType response = (RegistryResponseType) pojo;
47 if (Status.FAILURE.getOpcode30().equals(response.getStatus())) {
48 auditDataset.getDocuments().forEach(x -> x.setStatus(NOT_SUCCESSFUL));
49 } else if (Status.PARTIAL_SUCCESS.getOpcode30().equals(response.getStatus()) &&
50 (response.getRegistryErrorList() != null) &&
51 (response.getRegistryErrorList().getRegistryError() != null)) {
52 for (RegistryError error : response.getRegistryErrorList().getRegistryError()) {
53 if (Severity.ERROR.getOpcode30().equals(error.getSeverity())) {
54 auditDataset.getDocuments().stream()
55 .filter(document -> error.getCodeContext().contains(document.getDocumentUniqueId()))
56 .findAny()
57 .ifPresent(document -> document.setStatus(NOT_SUCCESSFUL));
58 }
59 }
60 }
61 return true;
62 }
63
64 }