001package ca.uhn.fhir.rest.server.util; 002 003/*- 004 * #%L 005 * HAPI FHIR - Server Framework 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 ca.uhn.fhir.context.FhirContext; 024import ca.uhn.fhir.context.RuntimeResourceDefinition; 025import ca.uhn.fhir.context.RuntimeSearchParam; 026import ca.uhn.fhir.context.phonetic.IPhoneticEncoder; 027import ca.uhn.fhir.i18n.Msg; 028import org.apache.commons.lang3.Validate; 029 030import javax.annotation.Nonnull; 031import javax.annotation.Nullable; 032import java.util.ArrayList; 033import java.util.List; 034import java.util.Set; 035 036public class FhirContextSearchParamRegistry implements ISearchParamRegistry { 037 038 039 private final List<RuntimeSearchParam> myExtraSearchParams = new ArrayList<>(); 040 private final FhirContext myCtx; 041 042 /** 043 * Constructor 044 */ 045 public FhirContextSearchParamRegistry(@Nonnull FhirContext theCtx) { 046 Validate.notNull(theCtx, "theCtx must not be null"); 047 myCtx = theCtx; 048 } 049 050 @Override 051 public void forceRefresh() { 052 // nothing 053 } 054 055 @Override 056 public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) { 057 return getActiveSearchParams(theResourceName).get(theParamName); 058 } 059 060 @Override 061 public ResourceSearchParams getActiveSearchParams(String theResourceName) { 062 ResourceSearchParams retval = new ResourceSearchParams(theResourceName); 063 RuntimeResourceDefinition nextResDef = myCtx.getResourceDefinition(theResourceName); 064 for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) { 065 retval.put(nextSp.getName(), nextSp); 066 } 067 068 for (RuntimeSearchParam next : myExtraSearchParams) { 069 retval.put(next.getName(), next); 070 } 071 072 return retval; 073 } 074 075 public void addSearchParam(RuntimeSearchParam theSearchParam) { 076 myExtraSearchParams.add(theSearchParam); 077 } 078 079 @Override 080 public List<RuntimeSearchParam> getActiveComboSearchParams(String theResourceName, Set<String> theParamNames) { 081 throw new UnsupportedOperationException(Msg.code(2066)); 082 } 083 084 @Nullable 085 @Override 086 public RuntimeSearchParam getActiveSearchParamByUrl(String theUrl) { 087 throw new UnsupportedOperationException(Msg.code(2067)); 088 } 089 090 @Override 091 public List<RuntimeSearchParam> getActiveComboSearchParams(String theResourceName) { 092 throw new UnsupportedOperationException(Msg.code(2068)); 093 } 094 095 @Override 096 public void requestRefresh() { 097 // nothing 098 } 099 100 @Override 101 public void setPhoneticEncoder(IPhoneticEncoder thePhoneticEncoder) { 102 // nothing 103 } 104}