001package ca.uhn.fhir.rest.gclient; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import java.util.Arrays; 024import java.util.List; 025 026import ca.uhn.fhir.model.primitive.StringDt; 027import ca.uhn.fhir.util.CoverageIgnore; 028 029/** 030 * 031 */ 032public class UriClientParam extends BaseClientParam implements IParam { 033 034 //TODO: handle :above and :below 035 036 private final String myParamName; 037 038 public UriClientParam(String theParamName) { 039 myParamName = theParamName; 040 } 041 042 @Override 043 public String getParamName() { 044 return myParamName; 045 } 046 047 /** 048 * 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". 049 * @param theValue THIS PARAMETER DOES NOT DO ANYTHING - This method was added by accident 050 * 051 * @deprecated theValue does not do anything, use {@link #matches()} instead 052 */ 053 @CoverageIgnore 054 @Deprecated 055 public IUriMatch matches(String theValue) { 056 return new UriMatches(); 057 } 058 059 /** 060 * 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". 061 */ 062 public IUriMatch matches() { 063 return new UriMatches(); 064 } 065 066 public interface IUriMatch { 067 068 /** 069 * Requests that resources be returned which match the given value 070 */ 071 ICriterion<UriClientParam> value(String theValue); 072 073 /** 074 * 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) 075 * where} criteria with the same parameter. 076 */ 077 ICriterion<UriClientParam> values(List<String> theValues); 078 079 /** 080 * Requests that resources be returned which match the given value 081 */ 082 ICriterion<UriClientParam> value(StringDt theValue); 083 084 /** 085 * 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) 086 * where} criteria with the same parameter. 087 */ 088 ICriterion<?> values(String... theValues); 089 090 } 091 092 private class UriMatches implements IUriMatch { 093 @Override 094 public ICriterion<UriClientParam> value(String theValue) { 095 return new StringCriterion<UriClientParam>(getParamName(), theValue); 096 } 097 098 @Override 099 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}