1 /*
2 * Copyright 2012 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.transform.requests;
17
18 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
19 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRetrieveImagingDocumentSetRequest;
20 import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveImagingDocumentSet;
21
22 import static org.apache.commons.lang3.Validate.notNull;
23
24 /**
25 * Transforms between a {@link EbXMLRetrieveImagingDocumentSetRequest} and its ebXML representation.
26 *
27 * @author Clay Sebourn
28 */
29 public class RetrieveImagingDocumentSetRequestTransformer
30 {
31 private final EbXMLFactory factory;
32
33 /**
34 * Constructs the transformer
35 * @param factory
36 * factory for version independent ebXML objects.
37 */
38 public RetrieveImagingDocumentSetRequestTransformer(EbXMLFactory factory) {
39 notNull(factory, "factory cannot be null");
40 this.factory = factory;
41 }
42
43 /**
44 * Transforms the request into its ebXML representation.
45 * @param request The request. Can be <code>null</code>.
46 * @return the ebXML representation. <code>null</code> if the input was <code>null</code>.
47 */
48 public EbXMLRetrieveImagingDocumentSetRequest toEbXML(RetrieveImagingDocumentSet request) {
49 if (request == null) {
50 return null;
51 }
52
53 EbXMLRetrieveImagingDocumentSetRequest ebXML = factory.createRetrieveImagingDocumentSetRequest();
54 ebXML.setRetrieveStudies(request.getRetrieveStudies());
55 ebXML.setTransferSyntaxUIDList(request.getTransferSyntaxIds());
56 return ebXML;
57 }
58
59 /**
60 * Transforms the ebXML representation into a request.
61 * @param ebXML The ebXML representation. Can be <code>null</code>.
62 * @return the request. <code>null</code> if the input was <code>null</code>.
63 */
64 public RetrieveImagingDocumentSet fromEbXML(EbXMLRetrieveImagingDocumentSetRequest ebXML) {
65 if (ebXML == null) {
66 return null;
67 }
68
69 RetrieveImagingDocumentSet request = new RetrieveImagingDocumentSet();
70 request.getRetrieveStudies().addAll(ebXML.getRetrieveStudies());
71 request.getTransferSyntaxIds().addAll(ebXML.getTransferSyntaxUIDList());
72 return request;
73 }
74 }