1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
33
34
35 public class EbXMLRegistryResponse30 implements EbXMLRegistryResponse {
36 private final RegistryResponseType regResponse;
37
38
39
40
41
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 }