1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.transform.responses;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19
20 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
21 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryResponse;
22 import org.openehealth.ipf.commons.ihe.xds.core.responses.Response;
23
24
25
26
27
28 public class ResponseTransformer {
29 private final EbXMLFactory factory;
30 private final ErrorInfoListTransformer errorInfoListTransformer;
31
32
33
34
35
36
37 public ResponseTransformer(EbXMLFactory factory) {
38 notNull(factory, "factory cannot be null");
39 this.factory = factory;
40 this.errorInfoListTransformer = new ErrorInfoListTransformer(factory);
41 }
42
43
44
45
46
47
48
49 public EbXMLRegistryResponse toEbXML(Response response) {
50 notNull(response, "response cannot be null");
51
52 EbXMLRegistryResponse ebXML = factory.createRegistryResponse();
53
54 ebXML.setStatus(response.getStatus());
55 if (!response.getErrors().isEmpty()) {
56 ebXML.setErrors(errorInfoListTransformer.toEbXML(response.getErrors()));
57 }
58
59 return ebXML;
60 }
61
62
63
64
65
66
67
68 public Response fromEbXML(EbXMLRegistryResponse ebXML) {
69 notNull(ebXML, "ebXML cannot be null");
70
71 Response response = new Response();
72
73 response.setStatus(ebXML.getStatus());
74 if (!ebXML.getErrors().isEmpty()) {
75 response.setErrors(errorInfoListTransformer.fromEbXML(ebXML.getErrors()));
76 }
77
78 return response;
79 }
80 }