View Javadoc
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.xds.core.ebxml.ebxml30;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryError;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryResponse;
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.RegistryErrorList;
23  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rs.RegistryResponseType;
24  
25  import java.util.Collections;
26  import java.util.List;
27  import java.util.stream.Collectors;
28  
29  import static org.apache.commons.lang3.Validate.notNull;
30  
31  /**
32   * The ebXML 3.0 version of the {@link EbXMLRegistryResponse}.
33   * @author Jens Riemschneider
34   */
35  public class EbXMLRegistryResponse30 implements EbXMLRegistryResponse {
36      private final RegistryResponseType regResponse;
37      
38      /**
39       * Constructs the registry response by wrapping the given ebXML 3.0 object.
40       * @param regResponse
41       *          the object to wrap.
42       */
43      public EbXMLRegistryResponse30(RegistryResponseType regResponse) {
44          notNull(regResponse, "regResponse cannot be null");
45          this.regResponse = regResponse;
46      }
47  
48      @Override
49      public void setStatus(Status status) {
50          regResponse.setStatus(Status.getOpcode30(status));
51      }
52      
53      @Override
54      public Status getStatus() {
55          return Status.valueOfOpcode(regResponse.getStatus());
56      }
57      
58      @Override
59      public RegistryResponseType getInternal() {
60          return regResponse;
61      }
62  
63      @Override
64      public List<EbXMLRegistryError> getErrors() {
65          RegistryErrorList list = getInternal().getRegistryErrorList();
66          if (list == null) {
67              return Collections.emptyList();
68          }
69  
70          return list.getRegistryError().stream()
71                  .map(EbXMLRegistryError30::new)
72                  .collect(Collectors.toList());
73      }
74  
75      @Override
76      public void setErrors(List<EbXMLRegistryError> errors) {
77          RegistryErrorList value = EbXMLFactory30.RS_FACTORY.createRegistryErrorList();
78          getInternal().setRegistryErrorList(value);
79          List<RegistryError> list = value.getRegistryError();
80          list.addAll(errors.stream()
81                  .map(error -> ((EbXMLRegistryError30) error).getInternal())
82                  .collect(Collectors.toList()));
83      }
84  }