From 7cde945281890ce34023a1e954a24503f2741809 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 29 Jun 2020 17:10:33 -0400 Subject: [PATCH] Work on seed bundles --- .../ca/uhn/fhir/rest/param/ParameterUtil.java | 7 +++ .../resthook/RestHookTestR4Test.java | 1 + .../fhir/jpa/searchparam/MatchUrlService.java | 54 +++++++++++++++++-- ...scriptionDeliveringRestHookSubscriber.java | 2 +- .../rest/server/method/IncludeParameter.java | 23 ++++---- 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java index 086c6d9e624..8d6a9d8a6d4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java @@ -9,6 +9,7 @@ import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IntegerDt; import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.param.binder.QueryParameterAndBinder; @@ -386,4 +387,10 @@ public class ParameterUtil { return b.toString(); } + /** + * Returns true if the value is :iterate or :recurse (the former name of :iterate) for an _include parameter + */ + public static boolean isIncludeIterate(String theQualifier) { + return Constants.PARAM_INCLUDE_QUALIFIER_RECURSE.equals(theQualifier) || Constants.PARAM_INCLUDE_QUALIFIER_ITERATE.equals(theQualifier); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java index f9099ce9317..5779c884cef 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java @@ -1018,6 +1018,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { { Subscription subscription = newSubscription("Observation?", "application/json"); subscription.addExtension(JpaConstants.EXT_SUBSCRIPTION_PAYLOAD_SEARCH_RESULT, new StringType("Observation?_id=${matched_resource_id}&_include=*")); + ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(subscription)); MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); mySubscriptionIds.add(methodOutcome.getId()); waitForActivatedSubscriptionCount(1); diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/MatchUrlService.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/MatchUrlService.java index 6ef228f30c1..45ed8c78fd7 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/MatchUrlService.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/MatchUrlService.java @@ -26,6 +26,7 @@ import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.model.api.IQueryParameterAnd; import ca.uhn.fhir.model.api.IQueryParameterType; +import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; @@ -50,7 +51,7 @@ public class MatchUrlService { @Autowired private ISearchParamRegistry mySearchParamRegistry; - public SearchParameterMap translateMatchUrl(String theMatchUrl, RuntimeResourceDefinition theResourceDefinition) { + public SearchParameterMap translateMatchUrl(String theMatchUrl, RuntimeResourceDefinition theResourceDefinition, Flag... theFlags) { SearchParameterMap paramMap = new SearchParameterMap(); List parameters = translateMatchUrl(theMatchUrl); @@ -79,6 +80,13 @@ public class MatchUrlService { for (String nextParamName : nameToParamLists.keySet()) { List paramList = nameToParamLists.get(nextParamName); + + if (theFlags != null && theFlags.length > 0) { + for (Flag next : theFlags) { + next.process(nextParamName, paramList, paramMap); + } + } + if (Constants.PARAM_LASTUPDATED.equals(nextParamName)) { if (paramList != null && paramList.size() > 0) { if (paramList.size() > 2) { @@ -131,8 +139,8 @@ public class MatchUrlService { return UrlUtil.translateMatchUrl(theMatchUrl); } - private IQueryParameterAnd newInstanceAnd(String theParamType) { - Class clazz = ResourceMetaParams.RESOURCE_META_AND_PARAMS.get(theParamType); + private IQueryParameterAnd newInstanceAnd(String theParamType) { + Class> clazz = ResourceMetaParams.RESOURCE_META_AND_PARAMS.get(theParamType); return ReflectionUtil.newInstance(clazz); } @@ -140,4 +148,44 @@ public class MatchUrlService { Class clazz = ResourceMetaParams.RESOURCE_META_PARAMS.get(theParamType); return ReflectionUtil.newInstance(clazz); } + + public abstract static class Flag { + + /** + * Constructor + */ + Flag() { + // nothing + } + + abstract void process(String theParamName, List theValues, SearchParameterMap theMapToPopulate); + + } + + /** + * Indicates that the parser should process _include and _revinclude (by default these are not handled) + */ + public static Flag processIncludes() { + return new Flag() { + + @Override + void process(String theParamName, List theValues, SearchParameterMap theMapToPopulate) { + if (Constants.PARAM_INCLUDE.equals(theParamName)) { + for (QualifiedParamList nextQualifiedList : theValues) { + for (String nextValue : nextQualifiedList) { + theMapToPopulate.addInclude(new Include(nextValue, ParameterUtil.isIncludeIterate(nextQualifiedList.getQualifier()))); + } + } + } else if (Constants.PARAM_REVINCLUDE.equals(theParamName)) { + for (QualifiedParamList nextQualifiedList : theValues) { + for (String nextValue : nextQualifiedList) { + theMapToPopulate.addInclude(new Include(nextValue, ParameterUtil.isIncludeIterate(nextQualifiedList.getQualifier()))); + } + } + } + + } + }; + } + } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/resthook/SubscriptionDeliveringRestHookSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/resthook/SubscriptionDeliveringRestHookSubscriber.java index f4032eb709e..e63efa6e0c3 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/resthook/SubscriptionDeliveringRestHookSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/resthook/SubscriptionDeliveringRestHookSubscriber.java @@ -100,7 +100,7 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe Map valueMap = new HashMap<>(1); valueMap.put("matched_resource_id", thePayloadResource.getIdElement().toUnqualifiedVersionless().getValue()); payloadUrl = new StringSubstitutor(valueMap).replace(payloadUrl); - SearchParameterMap payloadSearchMap = myMatchUrlService.translateMatchUrl(payloadUrl, resourceDefinition); + SearchParameterMap payloadSearchMap = myMatchUrlService.translateMatchUrl(payloadUrl, resourceDefinition, MatchUrlService.processIncludes()); payloadSearchMap.setLoadSynchronous(true); IBundleProvider searchResults = dao.search(payloadSearchMap); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java index 2dfc38d4fc7..2d91ec631b7 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java @@ -20,14 +20,6 @@ package ca.uhn.fhir.rest.server.method; * #L% */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; @@ -35,9 +27,18 @@ import ca.uhn.fhir.rest.annotation.IncludeParam; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + class IncludeParameter extends BaseQueryParameter { private Set myAllow; @@ -142,7 +143,7 @@ class IncludeParameter extends BaseQueryParameter { } String qualifier = nextParamList.getQualifier(); - boolean recurse = Constants.PARAM_INCLUDE_QUALIFIER_RECURSE.equals(qualifier) || Constants.PARAM_INCLUDE_QUALIFIER_ITERATE.equals(qualifier); + boolean iterate = ParameterUtil.isIncludeIterate(qualifier); String value = nextParamList.get(0); if (myAllow != null && !myAllow.isEmpty()) { @@ -157,10 +158,10 @@ class IncludeParameter extends BaseQueryParameter { if (mySpecType == String.class) { return value; } - return new Include(value, recurse); + return new Include(value, iterate); } - retValCollection.add(new Include(value, recurse)); + retValCollection.add(new Include(value, iterate)); } return retValCollection;