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