View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import ca.uhn.fhir.model.primitive.StringDt;
27  import ca.uhn.fhir.util.CoverageIgnore;
28  
29  /**
30   *
31   */
32  public class UriClientParam extends BaseClientParam  implements IParam {
33  
34  	//TODO: handle :above and :below
35  	
36  	private final String myParamName;
37  
38  	public UriClientParam(String theParamName) {
39  		myParamName = theParamName;
40  	}
41  
42  	@Override
43  	public String getParamName() {
44  		return myParamName;
45  	}
46  
47  	/**
48  	 * The string matches the given value (servers will often, but are not required to) implement this as a left match, meaning that a value of "smi" would match "smi" and "smith".
49  	 * @param theValue THIS PARAMETER DOES NOT DO ANYTHING - This method was added by accident
50  	 * 
51  	 * @deprecated theValue does not do anything, use {@link #matches()} instead
52  	 */
53  	@CoverageIgnore
54  	@Deprecated
55  	public IUriMatch matches(String theValue) {
56  		return new UriMatches();
57  	}
58  
59  	/**
60  	 * The string matches the given value (servers will often, but are not required to) implement this as a left match, meaning that a value of "smi" would match "smi" and "smith".
61  	 */
62  	public IUriMatch matches() {
63  		return new UriMatches();
64  	}
65  
66  	public interface IUriMatch {
67  
68  		/**
69  		 * Requests that resources be returned which match the given value
70  		 */
71  		ICriterion<UriClientParam> value(String theValue);
72  
73  		/**
74  		 * Requests that resources be returned which match ANY of the given values (this is an OR search). Note that to specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion)
75  		 * where} criteria with the same parameter.
76  		 */
77  		ICriterion<UriClientParam> values(List<String> theValues);
78  
79  		/**
80  		 * Requests that resources be returned which match the given value
81  		 */
82  		ICriterion<UriClientParam> value(StringDt theValue);
83  
84  		/**
85  		 * Requests that resources be returned which match ANY of the given values (this is an OR search). Note that to specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion)
86  		 * where} criteria with the same parameter.
87  		 */
88  		ICriterion<?> values(String... theValues);
89  
90  	}
91  
92  	private class UriMatches implements IUriMatch {
93  		@Override
94  		public ICriterion<UriClientParam> value(String theValue) {
95  			return new StringCriterion<UriClientParam>(getParamName(), theValue);
96  		}
97  
98  		@Override
99  		public ICriterion<UriClientParam> value(StringDt theValue) {
100 			return new StringCriterion<UriClientParam>(getParamName(), theValue.getValue());
101 		}
102 
103 		@Override
104 		public ICriterion<UriClientParam> values(List<String> theValue) {
105 			return new StringCriterion<UriClientParam>(getParamName(), theValue);
106 		}
107 
108 		@Override
109 		public ICriterion<?> values(String... theValues) {
110 			return new StringCriterion<UriClientParam>(getParamName(), Arrays.asList(theValues));
111 		}
112 
113 	}
114 
115 }