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.transform.requests.query;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
19  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetByUuidQuery;
20  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
21  
22  import static org.apache.commons.lang3.Validate.notNull;
23  
24  /**
25   * Base class of transformers for {@link GetByUuidQuery}.
26   * @param <T>
27   *          type of the query.
28   * @author Jens Riemschneider
29   */
30  public abstract class GetByUUIDQueryTransformer<T extends GetByUuidQuery> extends AbstractStoredQueryTransformer<T> {
31      private final QueryParameter uuidParam;
32      
33      /**
34       * Constructs the transformer.
35       * @param uuidParam
36       *          the parameter name of the UUID parameter.
37       */
38      protected GetByUUIDQueryTransformer(QueryParameter uuidParam) {
39          notNull(uuidParam, "uuidParam cannot be null");
40          this.uuidParam = uuidParam;
41      }
42  
43      /**
44       * Transforms the query into its ebXML representation.
45       * <p>
46       * Does not perform any transformation if one of the parameters is <code>null</code>. 
47       * @param query
48       *          the query. Can be <code>null</code>.
49       * @param ebXML
50       *          the ebXML representation. Can be <code>null</code>.
51       */
52      public void toEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
53          if (query == null || ebXML == null) {
54              return;
55          }
56  
57          super.toEbXML(query, ebXML);
58  
59          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
60          slots.fromStringList(uuidParam, query.getUuids());
61  
62          toEbXML(query, slots);
63      }
64  
65      /**
66       * Transforms the ebXML representation of a query into a query object.
67       * <p>
68       * Does not perform any transformation if one of the parameters is <code>null</code>. 
69       * @param query
70       *          the query. Can be <code>null</code>.
71       * @param ebXML
72       *          the ebXML representation. Can be <code>null</code>.
73       */
74     public void fromEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
75          if (query == null || ebXML == null) {
76              return;
77          }
78  
79          super.fromEbXML(query, ebXML);
80  
81          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
82          query.setUuids(slots.toStringList(uuidParam));
83  
84          fromEbXML(query, slots);
85      }
86  
87      /**
88       * Called by {@link #toEbXML(GetByUuidQuery, EbXMLAdhocQueryRequest)} to
89       * transform slots.
90       * @param query
91       *          the query to transform.
92       * @param slots
93       *          the slots to be filled.
94       */
95      protected void toEbXML(T query, QuerySlotHelper slots) {}
96  
97      /**
98       * Called by {@link #fromEbXML(GetByUuidQuery, EbXMLAdhocQueryRequest)} to
99       * transform slots.
100      * @param query
101      *          the target query.
102      * @param slots
103      *          the slots to transform.
104      */
105     protected void fromEbXML(T query, QuerySlotHelper slots) {}
106 }