diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java index f0872b62287..54be26ee52b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java @@ -25,6 +25,7 @@ import ca.uhn.fhir.context.BaseRuntimeElementDefinition; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.PatchTypeEnum; @@ -588,6 +589,16 @@ public class BundleUtil { return retVal; } + public static void setSearchModeMetadata(FhirContext theContext, IBaseBundle theBundle) { + List searchBundleEntryParts = getSearchBundleEntryParts(theContext, theBundle); + searchBundleEntryParts.forEach(searchBundleEntryPart -> { + IBaseResource resource = searchBundleEntryPart.getResource(); + if (resource != null) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, searchBundleEntryPart.getSearchMode()); + } + }); + } + private static SearchBundleEntryParts getSearchBundleEntryParts( BaseRuntimeChildDefinition fullUrlChildDef, BaseRuntimeChildDefinition resourceChildDef, diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java index 364a3283dda..38933276b58 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java @@ -132,7 +132,6 @@ import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.ICallable; import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.UrlUtil; -import ca.uhn.fhir.util.bundle.SearchBundleEntryParts; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -584,7 +583,7 @@ public class GenericClient extends BaseClient implements IGenericClient { myLastRequest = theInvocation.asHttpRequest(getServerBase(), theParams, getEncoding(), myPrettyPrint); } - Z resp = invokeClient( + return invokeClient( myContext, theHandler, theInvocation, @@ -596,18 +595,6 @@ public class GenericClient extends BaseClient implements IGenericClient { myCacheControlDirective, myCustomAcceptHeaderValue, myCustomHeaderValues); - - if (resp instanceof IBaseBundle) { - List searchBundleEntryParts = - BundleUtil.getSearchBundleEntryParts(getFhirContext(), (IBaseBundle) resp); - searchBundleEntryParts.forEach(searchBundleEntryPart -> { - IBaseResource resource = searchBundleEntryPart.getResource(); - if (resource != null) { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, searchBundleEntryPart.getSearchMode()); - } - }); - } - return resp; } protected IBaseResource parseResourceBody(String theResourceBody) { @@ -2211,7 +2198,13 @@ public class GenericClient extends BaseClient implements IGenericClient { myContext, myResourceName, params, resourceId, myCompartmentName, mySearchStyle); } - return (OUTPUT) invoke(params, binding, invocation); + OUTPUT invoke = (OUTPUT) invoke(params, binding, invocation); + + if (invoke instanceof IBaseBundle) { + BundleUtil.setSearchModeMetadata(myContext, (IBaseBundle) invoke); + } + + return invoke; } @Override