diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index fa4b228bb78..1b14c098e87 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -133,8 +133,6 @@ public abstract class BaseHapiFhirDao extends BaseStora @Autowired protected ISearchCoordinatorSvc mySearchCoordinatorSvc; @Autowired - protected ISearchParamRegistry mySerarchParamRegistry; - @Autowired protected ITermReadSvc myTerminologySvc; @Autowired protected IResourceHistoryTableDao myResourceHistoryTableDao; @@ -142,8 +140,7 @@ public abstract class BaseHapiFhirDao extends BaseStora protected IResourceTableDao myResourceTableDao; @Autowired protected IResourceTagDao myResourceTagDao; - @Autowired - protected ISearchParamRegistry mySearchParamRegistry; + @Autowired protected DeleteConflictService myDeleteConflictService; @Autowired @@ -1528,4 +1525,5 @@ public abstract class BaseHapiFhirDao extends BaseStora "Resource with ID " + theEntity.getIdDt().getIdPart() + " exists but it is not of type " + theResourceName + ", found resource of type " + theEntity.getResourceType()); } } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index 804ecd56017..6c8407107fe 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -22,7 +22,6 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; -import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.delete.DeleteConflictList; @@ -39,16 +38,12 @@ import ca.uhn.fhir.jpa.util.ExpungeOutcome; import ca.uhn.fhir.jpa.util.JpaInterceptorBroadcaster; import ca.uhn.fhir.jpa.util.jsonpatch.JsonPatchUtils; import ca.uhn.fhir.jpa.util.xmlpatch.XmlPatchUtils; -import ca.uhn.fhir.model.api.IQueryParameterAnd; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.param.ParameterUtil; -import ca.uhn.fhir.rest.param.QualifierDetails; import ca.uhn.fhir.rest.server.exceptions.*; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; -import ca.uhn.fhir.rest.server.method.SearchMethodBinding; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.ObjectUtil; import ca.uhn.fhir.util.OperationOutcomeUtil; @@ -1151,38 +1146,6 @@ public abstract class BaseHapiFhirResourceDao extends B return retVal; } - @Transactional(propagation = Propagation.SUPPORTS) - @Override - public void translateRawParameters(Map> theSource, SearchParameterMap theTarget) { - if (theSource == null || theSource.isEmpty()) { - return; - } - - Map searchParams = mySerarchParamRegistry.getActiveSearchParams(getResourceName()); - - Set paramNames = theSource.keySet(); - for (String nextParamName : paramNames) { - QualifierDetails qualifiedParamName = SearchMethodBinding.extractQualifiersFromParameterName(nextParamName); - RuntimeSearchParam param = searchParams.get(qualifiedParamName.getParamName()); - if (param == null) { - String msg = getContext().getLocalizer().getMessageSanitized(BaseHapiFhirResourceDao.class, "invalidSearchParameter", qualifiedParamName.getParamName(), new TreeSet<>(searchParams.keySet())); - throw new InvalidRequestException(msg); - } - - // Should not be null since the check above would have caught it - RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(myResourceName); - RuntimeSearchParam paramDef = mySearchParamRegistry.getSearchParamByName(resourceDef, qualifiedParamName.getParamName()); - - for (String nextValue : theSource.get(nextParamName)) { - QualifiedParamList qualifiedParam = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(qualifiedParamName.getWholeQualifier(), nextValue); - List paramList = Collections.singletonList(qualifiedParam); - IQueryParameterAnd parsedParam = ParameterUtil.parseQueryParams(getContext(), paramDef, nextParamName, paramList); - theTarget.add(qualifiedParamName.getParamName(), parsedParam); - } - - } - } - @Override public DaoMethodOutcome update(T theResource) { return update(theResource, null, null); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java index b845ea07598..1fa8df75b65 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java @@ -21,19 +21,24 @@ package ca.uhn.fhir.jpa.dao; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.RuntimeResourceDefinition; +import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.jpa.util.JpaInterceptorBroadcaster; -import ca.uhn.fhir.rest.api.server.IPreResourceAccessDetails; -import ca.uhn.fhir.rest.api.server.IPreResourceShowDetails; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.api.server.SimplePreResourceAccessDetails; -import ca.uhn.fhir.rest.api.server.SimplePreResourceShowDetails; +import ca.uhn.fhir.model.api.IQueryParameterAnd; +import ca.uhn.fhir.rest.api.QualifiedParamList; +import ca.uhn.fhir.rest.api.server.*; +import ca.uhn.fhir.rest.param.ParameterUtil; +import ca.uhn.fhir.rest.param.QualifierDetails; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.method.SearchMethodBinding; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.FhirTerser; @@ -44,20 +49,23 @@ import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.InstantType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Set; +import java.util.*; import static ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.OO_SEVERITY_ERROR; import static ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.OO_SEVERITY_INFO; import static org.apache.commons.lang3.StringUtils.defaultString; -import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; public abstract class BaseStorageDao { + @Autowired + protected ISearchParamRegistry mySearchParamRegistry; /** * May be overridden by subclasses to validate resources prior to storage @@ -203,4 +211,36 @@ public abstract class BaseStorageDao { */ protected abstract FhirContext getContext(); + + @Transactional(propagation = Propagation.SUPPORTS) + public void translateRawParameters(Map> theSource, SearchParameterMap theTarget) { + if (theSource == null || theSource.isEmpty()) { + return; + } + + Map searchParams = mySearchParamRegistry.getActiveSearchParams(getResourceName()); + + Set paramNames = theSource.keySet(); + for (String nextParamName : paramNames) { + QualifierDetails qualifiedParamName = SearchMethodBinding.extractQualifiersFromParameterName(nextParamName); + RuntimeSearchParam param = searchParams.get(qualifiedParamName.getParamName()); + if (param == null) { + String msg = getContext().getLocalizer().getMessageSanitized(BaseHapiFhirResourceDao.class, "invalidSearchParameter", qualifiedParamName.getParamName(), new TreeSet<>(searchParams.keySet())); + throw new InvalidRequestException(msg); + } + + // Should not be null since the check above would have caught it + RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(getResourceName()); + RuntimeSearchParam paramDef = mySearchParamRegistry.getSearchParamByName(resourceDef, qualifiedParamName.getParamName()); + + for (String nextValue : theSource.get(nextParamName)) { + QualifiedParamList qualifiedParam = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(qualifiedParamName.getWholeQualifier(), nextValue); + List paramList = Collections.singletonList(qualifiedParam); + IQueryParameterAnd parsedParam = ParameterUtil.parseQueryParams(getContext(), paramDef, nextParamName, paramList); + theTarget.add(qualifiedParamName.getParamName(), parsedParam); + } + + } + } + }