View Javadoc
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  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   * Basis for Strategy pattern implementation for ATNA Auditing
29   * in ebXML 3.0-based XDS transactions related to removal of Documents.
30   *
31   * @author Dmytro Rud
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  }