All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.uhn.fhir.rest.gclient.UriClientParam Maven / Gradle / Ivy

There is a newer version: 7.4.5
Show newest version
/*
 * #%L
 * HAPI FHIR - Core Library
 * %%
 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package ca.uhn.fhir.rest.gclient;

import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.util.CoverageIgnore;

import java.util.Arrays;
import java.util.List;

/**
 *
 */
public class UriClientParam extends BaseClientParam implements IParam {

	// TODO: handle :above and :below

	private final String myParamName;

	public UriClientParam(String theParamName) {
		myParamName = theParamName;
	}

	@Override
	public String getParamName() {
		return myParamName;
	}

	/**
	 * 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".
	 * @param theValue THIS PARAMETER DOES NOT DO ANYTHING - This method was added by accident
	 *
	 * @deprecated theValue does not do anything, use {@link #matches()} instead
	 */
	@CoverageIgnore
	@Deprecated
	public IUriMatch matches(String theValue) {
		return new UriMatches();
	}

	/**
	 * 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".
	 */
	public IUriMatch matches() {
		return new UriMatches();
	}

	public interface IUriMatch {

		/**
		 * Requests that resources be returned which match the given value
		 */
		ICriterion value(String theValue);

		/**
		 * 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)
		 * where} criteria with the same parameter.
		 */
		ICriterion values(List theValues);

		/**
		 * Requests that resources be returned which match the given value
		 */
		ICriterion value(StringDt theValue);

		/**
		 * 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)
		 * where} criteria with the same parameter.
		 */
		ICriterion values(String... theValues);
	}

	private class UriMatches implements IUriMatch {
		@Override
		public ICriterion value(String theValue) {
			return new StringCriterion(getParamName(), theValue);
		}

		@Override
		public ICriterion value(StringDt theValue) {
			return new StringCriterion(getParamName(), theValue.getValue());
		}

		@Override
		public ICriterion values(List theValue) {
			return new StringCriterion(getParamName(), theValue);
		}

		@Override
		public ICriterion values(String... theValues) {
			return new StringCriterion(getParamName(), Arrays.asList(theValues));
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy