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.GetByIdAndCodesQuery;
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 GetByIdAndCodesQuery}.
26   * @param <T>
27   *          the actual query type that is transformed by an extending subclass.
28   * @author Jens Riemschneider
29   */
30  public abstract class GetByIDAndCodesQueryTransformer<T extends GetByIdAndCodesQuery> extends AbstractStoredQueryTransformer<T> {
31      private final QueryParameter formatCodeParam;
32      private final QueryParameter confCodeParam;
33      private final QueryParameter confCodeSchemeParam;
34      private final QueryParameter uniqueIdParam;
35      private final QueryParameter uuidParam; 
36      
37      /**
38       * Constructs the transformer.
39       * @param uuidParam
40       *          the parameter name of the UUID parameter.
41       * @param uniqueIdParam
42       *          the parameter name of the unique ID parameter.
43       * @param formatCodeParam
44       *          the parameter name of the format code.
45       * @param formatCodeSchemeParam
46       *          the parameter name of the format code scheme.
47       * @param confCodeParam
48       *          the parameter name of the confidentiality code.
49       * @param confCodeSchemeParam
50       *          the parameter name of the confidentiality code scheme.
51       */
52      public GetByIDAndCodesQueryTransformer(QueryParameter uuidParam, QueryParameter uniqueIdParam, QueryParameter formatCodeParam, QueryParameter formatCodeSchemeParam, QueryParameter confCodeParam, QueryParameter confCodeSchemeParam) {
53          notNull(uniqueIdParam, "uniqueIdParam cannot be null");
54          notNull(uuidParam, "uuidParam cannot be null");        
55          notNull(formatCodeParam, "formatCodeParam cannot be null");
56          notNull(formatCodeSchemeParam, "formatCodeSchemeParam cannot be null");        
57          notNull(confCodeParam, "confCodeParam cannot be null");
58          notNull(confCodeSchemeParam, "confCodeSchemeParam cannot be null");
59          
60          this.formatCodeParam = formatCodeParam;
61          this.confCodeParam = confCodeParam;
62          this.confCodeSchemeParam = confCodeSchemeParam;
63          this.uniqueIdParam = uniqueIdParam;
64          this.uuidParam = uuidParam;
65      }
66  
67      /**
68       * Transforms the query into its ebXML representation.
69       * <p>
70       * Does not perform any transformation if one of the parameters is <code>null</code>. 
71       * @param query
72       *          the query. Can be <code>null</code>.
73       * @param ebXML
74       *          the ebXML representation. Can be <code>null</code>.
75       */
76      public void toEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
77          if (query == null || ebXML == null) {
78              return;
79          }
80  
81          super.toEbXML(query,  ebXML);
82  
83          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
84  
85          slots.fromCode(formatCodeParam, query.getFormatCodes());
86          slots.fromCode(confCodeParam, query.getConfidentialityCodes());
87          slots.fromString(uuidParam, query.getUuid());
88          slots.fromString(uniqueIdParam, query.getUniqueId());
89      }
90  
91      /**
92       * Transforms the ebXML representation of a query into a query object.
93       * <p>
94       * Does not perform any transformation if one of the parameters is <code>null</code>. 
95       * @param query
96       *          the query. Can be <code>null</code>.
97       * @param ebXML
98       *          the ebXML representation. Can be <code>null</code>.
99       */
100     public void fromEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
101         if (query == null || ebXML == null) {
102             return;
103         }
104 
105         super.fromEbXML(query, ebXML);
106 
107         QuerySlotHelper slots = new QuerySlotHelper(ebXML);
108         
109         query.setFormatCodes(slots.toCodeList(formatCodeParam));
110         query.setConfidentialityCodes(slots.toCodeQueryList(confCodeParam, confCodeSchemeParam));
111         query.setUniqueId(slots.toString(uniqueIdParam));
112         query.setUuid(slots.toString(uuidParam));
113     }
114 
115 }