Refactor search param registry

This commit is contained in:
James Agnew 2017-03-18 19:36:10 -04:00
parent 01e1566886
commit 72f682d81e
4 changed files with 23 additions and 6 deletions

View File

@ -53,6 +53,16 @@ public abstract class BaseSearchParamRegistry implements ISearchParamRegistry {
// nothing by default // nothing by default
} }
@Override
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
RuntimeSearchParam retVal = null;
Map<String, RuntimeSearchParam> params = getActiveSearchParams().get(theResourceName);
if (params != null) {
retVal = params.get(theParamName);
}
return retVal;
}
@Override @Override
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() { public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
return myBuiltInSearchParams; return myBuiltInSearchParams;

View File

@ -32,4 +32,9 @@ public interface ISearchParamRegistry {
Map<String,RuntimeSearchParam> getActiveSearchParams(String theResourceName); Map<String,RuntimeSearchParam> getActiveSearchParams(String theResourceName);
/**
* @return Returns {@literal null} if no match
*/
RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName);
} }

View File

@ -41,7 +41,6 @@ import org.apache.commons.lang3.tuple.Pair;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionCallback;
@ -96,7 +95,7 @@ public class SearchBuilder {
private IFulltextSearchSvc mySearchDao; private IFulltextSearchSvc mySearchDao;
private Search mySearchEntity; private Search mySearchEntity;
private ISearchResultDao mySearchResultDao; private ISearchResultDao mySearchResultDao;
private ISearchParamRegistry mySerarchParamRegistry; private ISearchParamRegistry mySearchParamRegistry;
private IHapiTerminologySvc myTerminologySvc; private IHapiTerminologySvc myTerminologySvc;
@ -111,7 +110,7 @@ public class SearchBuilder {
myResourceIndexedSearchParamUriDao = theResourceIndexedSearchParamUriDao; myResourceIndexedSearchParamUriDao = theResourceIndexedSearchParamUriDao;
myForcedIdDao = theForcedIdDao; myForcedIdDao = theForcedIdDao;
myTerminologySvc = theTerminologySvc; myTerminologySvc = theTerminologySvc;
mySerarchParamRegistry = theSearchParamRegistry; mySearchParamRegistry = theSearchParamRegistry;
} }
private void addPredicateComposite(RuntimeSearchParam theParamDef, List<? extends IQueryParameterType> theNextAnd) { private void addPredicateComposite(RuntimeSearchParam theParamDef, List<? extends IQueryParameterType> theNextAnd) {
@ -1816,7 +1815,6 @@ public class SearchBuilder {
doInitializeSearch(); doInitializeSearch();
// RuntimeResourceDefinition resourceDef = myContext.getResourceDefinition(myResourceType); // RuntimeResourceDefinition resourceDef = myContext.getResourceDefinition(myResourceType);
Map<String, RuntimeSearchParam> searchParams = mySerarchParamRegistry.getActiveSearchParams(myResourceName);
for (Entry<String, List<List<? extends IQueryParameterType>>> nextParamEntry : params.entrySet()) { for (Entry<String, List<List<? extends IQueryParameterType>>> nextParamEntry : params.entrySet()) {
String nextParamName = nextParamEntry.getKey(); String nextParamName = nextParamEntry.getKey();
@ -1871,7 +1869,7 @@ public class SearchBuilder {
} else { } else {
RuntimeSearchParam nextParamDef = searchParams.get(nextParamName); RuntimeSearchParam nextParamDef = mySearchParamRegistry.getActiveSearchParam(myResourceName, nextParamName);
if (nextParamDef != null) { if (nextParamDef != null) {
switch (nextParamDef.getParamType()) { switch (nextParamDef.getParamType()) {
case DATE: case DATE:

View File

@ -2,7 +2,6 @@ package ca.uhn.fhir.jpa.dao.dstu3;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -63,6 +62,11 @@ public class SearchParamExtractorDstu3Test {
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() { public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
throw new UnsupportedOperationException();
}
}; };
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(ourCtx, ourValidationSupport, searchParamRegistry); SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(ourCtx, ourValidationSupport, searchParamRegistry);