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 static org.apache.commons.lang3.Validate.notNull;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLNonconstructiveDocumentSetRequest;
24  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.RetrieveDocumentSetRequestType.DocumentRequest;
25  import org.openehealth.ipf.commons.ihe.xds.core.requests.DocumentReference;
26  
27  /**
28   * The ebXML 3.0 version of the {@link EbXMLNonconstructiveDocumentSetRequest}.
29   * @author Jens Riemschneider
30   */
31  public class EbXMLNonconstructiveDocumentSetRequest30<T extends RetrieveDocumentSetRequestType> implements EbXMLNonconstructiveDocumentSetRequest {
32      private final T request;
33  
34      /**
35       * Constructs a request by wrapping the given ebXML 3.0 object.
36       * @param request
37       *          the object to wrap.
38       */
39      public EbXMLNonconstructiveDocumentSetRequest30(T request) {
40          notNull(request, "request cannot be null");
41          this.request = request;
42      }
43      
44      @Override
45      public T getInternal() {
46          return request;
47      }
48  
49      @Override
50      public List<DocumentReference> getDocuments() {
51          List<DocumentReference> docs = new ArrayList<>();
52          for (DocumentRequest documentRequest : request.getDocumentRequest()) {
53              DocumentReference doc = new DocumentReference();
54              doc.setDocumentUniqueId(documentRequest.getDocumentUniqueId());
55              doc.setHomeCommunityId(documentRequest.getHomeCommunityId());
56              doc.setRepositoryUniqueId(documentRequest.getRepositoryUniqueId());
57              docs.add(doc);
58          }
59          return docs;
60      }
61  
62      @Override
63      public void setDocuments(List<DocumentReference> documents) {
64          request.getDocumentRequest().clear();
65          if (documents != null) {
66              for (DocumentReference doc : documents) {
67                  DocumentRequest documentRequest = new DocumentRequest();
68                  documentRequest.setDocumentUniqueId(doc.getDocumentUniqueId());
69                  documentRequest.setHomeCommunityId(doc.getHomeCommunityId());
70                  documentRequest.setRepositoryUniqueId(doc.getRepositoryUniqueId());
71                  request.getDocumentRequest().add(documentRequest);
72              }
73          }
74      }
75  }