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 a736284937b..d48969ae5ca 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 @@ -233,7 +233,7 @@ public class BundleUtil { * All 3 might be null - That's ok because we still want to know the * order in the original bundle. */ - BundleEntryMutator mutator = new BundleEntryMutator(nextEntry, requestChildDef, requestChildContentsDef); + BundleEntryMutator mutator = new BundleEntryMutator(theContext, nextEntry, requestChildDef, requestChildContentsDef, entryChildContentsDef); ModifiableBundleEntry entry = new ModifiableBundleEntry(new BundleEntryParts(fullUrl, requestType, url, resource, conditionalUrl), mutator); theProcessor.accept(entry); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryMutator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryMutator.java index 8dabd2e6763..30cba478e07 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryMutator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryMutator.java @@ -31,11 +31,15 @@ public class BundleEntryMutator { private final IBase myEntry; private final BaseRuntimeChildDefinition myRequestChildDef; private final BaseRuntimeElementCompositeDefinition myRequestChildContentsDef; + private final FhirContext myFhirContext; + private final BaseRuntimeElementCompositeDefinition myEntryDefinition; - public BundleEntryMutator(IBase theEntry, BaseRuntimeChildDefinition theRequestChildDef, BaseRuntimeElementCompositeDefinition theRequestChildContentsDef) { + public BundleEntryMutator(FhirContext theFhirContext, IBase theEntry, BaseRuntimeChildDefinition theRequestChildDef, BaseRuntimeElementCompositeDefinition theChildContentsDef, BaseRuntimeElementCompositeDefinition theEntryDefinition) { + myFhirContext = theFhirContext; myEntry = theEntry; myRequestChildDef = theRequestChildDef; - myRequestChildContentsDef = theRequestChildContentsDef; + myRequestChildContentsDef = theChildContentsDef; + myEntryDefinition = theEntryDefinition; } void setRequestUrl(FhirContext theFhirContext, String theRequestUrl) { @@ -45,4 +49,13 @@ public class BundleEntryMutator { requestUrlChildDef.getMutator().addValue(nextRequest, url); } } + + @SuppressWarnings("unchecked") + public void setFullUrl(String theFullUrl) { + IPrimitiveType value = (IPrimitiveType) myFhirContext.getElementDefinition("uri").newInstance(); + value.setValue(theFullUrl); + + BaseRuntimeChildDefinition fullUrlChild = myEntryDefinition.getChildByName("fullUrl"); + fullUrlChild.getMutator().setValue(myEntry, value); + } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryParts.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryParts.java index 7bc9ecfa456..5d698cec7b3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryParts.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryParts.java @@ -58,4 +58,5 @@ public class BundleEntryParts { public String getUrl() { return myUrl; } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/ModifiableBundleEntry.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/ModifiableBundleEntry.java index 0b02176cd2d..04bb506fd11 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/ModifiableBundleEntry.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/ModifiableBundleEntry.java @@ -51,4 +51,8 @@ public class ModifiableBundleEntry { public IBaseResource getResource() { return myBundleEntryParts.getResource(); } + + public void setFullUrl(String theFullUrl) { + myBundleEntryMutator.setFullUrl(theFullUrl); + } } diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/bundle/BundleUtilTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/bundle/BundleUtilTest.java index 5801947ab06..b27b77aec2c 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/bundle/BundleUtilTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/bundle/BundleUtilTest.java @@ -65,10 +65,23 @@ public class BundleUtilTest { } @Test - public void testProcessEntries() { + public void testProcessEntriesSetRequestUrl() { + Bundle bundle = new Bundle(); + bundle.setType(Bundle.BundleType.TRANSACTION); + bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.POST).setUrl("Patient"); + + Consumer consumer = e -> e.setFullUrl("http://hello/Patient/123"); + BundleUtil.processEntries(ourCtx, bundle, consumer); + + assertEquals("http://hello/Patient/123", bundle.getEntryFirstRep().getFullUrl()); + } + + @Test + public void testProcessEntriesSetFullUrl() { Bundle bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.GET).setUrl("Observation"); + Consumer consumer = e -> e.setRequestUrl(ourCtx, e.getRequestUrl() + "?foo=bar"); BundleUtil.processEntries(ourCtx, bundle, consumer); assertEquals("Observation?foo=bar", bundle.getEntryFirstRep().getRequest().getUrl());