View Javadoc
1   /*
2    * Copyright 2013 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 lombok.experimental.Delegate;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRemoveMetadataRequest;
20  import org.openehealth.ipf.commons.ihe.xds.core.metadata.ObjectReference;
21  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.lcm.RemoveObjectsRequest;
22  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.AdhocQueryType;
23  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ObjectRefListType;
24  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ObjectRefType;
25  
26  import java.util.ArrayList;
27  import java.util.Collections;
28  import java.util.List;
29  
30  import static org.apache.commons.lang3.Validate.notNull;
31  
32  /**
33   * Encapsulation of {@link RemoveObjectsRequest}
34   * @author Boris Stanojevic
35   */
36  public class EbXMLRemoveMetadataRequest30 implements EbXMLRemoveMetadataRequest {
37      private final RemoveObjectsRequest removeObjectsRequest;
38  
39      /**
40       * Constructs a request by wrapping the given ebXML 3.0 object.
41       * @param removeObjectsRequest
42       *          the object to wrap.
43       */
44      public EbXMLRemoveMetadataRequest30(RemoveObjectsRequest removeObjectsRequest) {
45          notNull(removeObjectsRequest, "removeObjectsRequest cannot be null");
46          this.removeObjectsRequest = removeObjectsRequest;
47      }
48  
49      @Override
50      public void setReferences(List<ObjectReference> references) {
51          ObjectRefListType list = removeObjectsRequest.getObjectRefList();
52          if (list != null) {
53              list.getObjectRef().clear();
54          } else {
55              removeObjectsRequest.setObjectRefList(new ObjectRefListType());
56          }
57          if (references != null) {
58              for (ObjectReference reference : references) {
59                  ObjectRefType referenceType = new ObjectRefType();
60                  referenceType.setHome(reference.getHome());
61                  referenceType.setId(reference.getId());
62                  removeObjectsRequest.getObjectRefList().getObjectRef().add(referenceType);
63              }
64          }
65      }
66  
67      @Override
68      public List<ObjectReference> getReferences() {
69          ObjectRefListType list = removeObjectsRequest.getObjectRefList();
70          if (list == null) {
71              return Collections.emptyList();
72          }
73          List<ObjectReference> objectReferenceList = new ArrayList<>();
74          for (ObjectRefType objRefType: list.getObjectRef()){
75              ObjectReference ref = new ObjectReference(objRefType.getId(), objRefType.getHome());
76              objectReferenceList.add(ref);
77          }
78          return objectReferenceList;
79      }
80  
81      @Override
82      public String getDeletionScope() {
83          return removeObjectsRequest.getDeletionScope();
84      }
85  
86      @Override
87      public void setDeletionScope(String deletionScope) {
88          removeObjectsRequest.setDeletionScope(deletionScope);
89      }
90  
91      /**
92       * Implements the {@link org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlotList} interface
93       * by delegating the calls to a "proper" slot list.
94       */
95      @Delegate
96      private EbXMLSlotList30 getSlotList() {
97          return new EbXMLSlotList30(getAdhocQuery().getSlot());
98      }
99  
100     @Override
101     public void setSql(String sql) {
102         //noop
103     }
104 
105     @Override
106     public String getSql() {
107         return null;
108     }
109 
110     @Override
111     public void setReturnType(String returnType) {
112         //noop
113     }
114 
115     @Override
116     public String getReturnType() {
117         return null;
118     }
119 
120     private AdhocQueryType getAdhocQuery(){
121         if (removeObjectsRequest.getAdhocQuery() == null){
122             removeObjectsRequest.setAdhocQuery(new AdhocQueryType());
123         }
124         return removeObjectsRequest.getAdhocQuery();
125     }
126 
127     @Override
128     public void setId(String id) {
129         getAdhocQuery().setId(id);
130     }
131 
132     @Override
133     public String getId() {
134         return getAdhocQuery().getId();
135     }
136 
137     @Override
138     public void setHome(String homeCommunityID) {
139         getAdhocQuery().setHome(homeCommunityID);
140     }
141 
142     @Override
143     public String getHome() {
144         return getAdhocQuery().getHome();
145     }
146 
147     @Override
148     public RemoveObjectsRequest getInternal() {
149         return removeObjectsRequest;
150     }
151 }