diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
index 3ba302fa0a1..30cc22ebfce 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
@@ -32,6 +32,7 @@ import ca.uhn.fhir.model.primitive.XhtmlDt;
import ca.uhn.fhir.parser.json.JsonLikeValue.ScalarType;
import ca.uhn.fhir.parser.json.JsonLikeValue.ValueType;
import ca.uhn.fhir.util.*;
+import ca.uhn.fhir.util.bundle.BundleUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.tuple.Pair;
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
new file mode 100644
index 00000000000..eda87276f61
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryMutator.java
@@ -0,0 +1,28 @@
+package ca.uhn.fhir.util.bundle;
+
+import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
+import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.util.ParametersUtil;
+import org.hl7.fhir.instance.model.api.IBase;
+import org.hl7.fhir.instance.model.api.IPrimitiveType;
+
+class BundleEntryMutator {
+ private final IBase myEntry;
+ private final BaseRuntimeChildDefinition myRequestChildDef;
+ private final BaseRuntimeElementCompositeDefinition> myRequestChildContentsDef;
+
+ BundleEntryMutator(IBase theEntry, BaseRuntimeChildDefinition theRequestChildDef, BaseRuntimeElementCompositeDefinition> theRequestChildContentsDef) {
+ myEntry = theEntry;
+ myRequestChildDef = theRequestChildDef;
+ myRequestChildContentsDef = theRequestChildContentsDef;
+ }
+
+ void setRequestUrl(FhirContext theFhirContext, String theRequestUrl) {
+ BaseRuntimeChildDefinition requestUrlChildDef = myRequestChildContentsDef.getChildByName("url");
+ IPrimitiveType> url = ParametersUtil.createUri(theFhirContext, theRequestUrl);
+ for (IBase nextRequest : myRequestChildDef.getAccessor().getValues(myEntry)) {
+ requestUrlChildDef.getMutator().addValue(nextRequest, url);
+ }
+ }
+}
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
new file mode 100644
index 00000000000..331e50991f8
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleEntryParts.java
@@ -0,0 +1,35 @@
+package ca.uhn.fhir.util.bundle;
+
+import ca.uhn.fhir.rest.api.RequestTypeEnum;
+import org.hl7.fhir.instance.model.api.IBaseResource;
+
+public class BundleEntryParts {
+ private final RequestTypeEnum myRequestType;
+ private final IBaseResource myResource;
+ private final String myUrl;
+ private final String myConditionalUrl;
+
+ BundleEntryParts(RequestTypeEnum theRequestType, String theUrl, IBaseResource theResource, String theConditionalUrl) {
+ super();
+ myRequestType = theRequestType;
+ myUrl = theUrl;
+ myResource = theResource;
+ myConditionalUrl = theConditionalUrl;
+ }
+
+ public RequestTypeEnum getRequestType() {
+ return myRequestType;
+ }
+
+ public IBaseResource getResource() {
+ return myResource;
+ }
+
+ public String getConditionalUrl() {
+ return myConditionalUrl;
+ }
+
+ public String getUrl() {
+ return myUrl;
+ }
+}
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/bundle/BundleUtil.java
similarity index 75%
rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java
rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/BundleUtil.java
index d51b55dd931..9750f5b8b6e 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/bundle/BundleUtil.java
@@ -1,9 +1,6 @@
-package ca.uhn.fhir.util;
+package ca.uhn.fhir.util.bundle;
-import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
-import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.context.RuntimeResourceDefinition;
+import ca.uhn.fhir.context.*;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import org.apache.commons.lang3.tuple.Pair;
import org.hl7.fhir.instance.model.api.IBase;
@@ -14,6 +11,7 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.function.Consumer;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@@ -42,37 +40,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
*/
public class BundleUtil {
- public static class BundleEntryParts {
- private final RequestTypeEnum myRequestType;
- private final IBaseResource myResource;
- private final String myUrl;
- private final String myConditionalUrl;
-
- BundleEntryParts(RequestTypeEnum theRequestType, String theUrl, IBaseResource theResource, String theConditionalUrl) {
- super();
- myRequestType = theRequestType;
- myUrl = theUrl;
- myResource = theResource;
- myConditionalUrl = theConditionalUrl;
- }
-
- public RequestTypeEnum getRequestType() {
- return myRequestType;
- }
-
- public IBaseResource getResource() {
- return myResource;
- }
-
- public String getConditionalUrl() {
- return myConditionalUrl;
- }
-
- public String getUrl() {
- return myUrl;
- }
- }
-
/**
* @return Returns null
if the link isn't found or has no value
*/
@@ -185,20 +152,26 @@ public class BundleUtil {
* Extract all of the resources from a given bundle
*/
public static List toListOfEntries(FhirContext theContext, IBaseBundle theBundle) {
- List retVal = new ArrayList<>();
- RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
- BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
- List entries = entryChild.getAccessor().getValues(theBundle);
+ EntryListAccumulator entryListAccumulator = new EntryListAccumulator();
+ processEntries(theContext, theBundle, entryListAccumulator);
+ return entryListAccumulator.getList();
+ }
- BaseRuntimeElementCompositeDefinition> entryChildElem = (BaseRuntimeElementCompositeDefinition>) entryChild.getChildByName("entry");
- BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource");
- BaseRuntimeChildDefinition requestChild = entryChildElem.getChildByName("request");
- BaseRuntimeElementCompositeDefinition> requestElem = (BaseRuntimeElementCompositeDefinition>) requestChild.getChildByName("request");
- BaseRuntimeChildDefinition requestUrlChild = requestElem.getChildByName("url");
- BaseRuntimeChildDefinition requestIfNoneExistChild = requestElem.getChildByName("ifNoneExist");
- BaseRuntimeChildDefinition methodChild = requestElem.getChildByName("method");
+ public static void processEntries(FhirContext theContext, IBaseBundle theBundle, Consumer theProcessor) {
+ RuntimeResourceDefinition bundleDef = theContext.getResourceDefinition(theBundle);
+ BaseRuntimeChildDefinition entryChildDef = bundleDef.getChildByName("entry");
+ List entries = entryChildDef.getAccessor().getValues(theBundle);
+
+ BaseRuntimeElementCompositeDefinition> entryChildContentsDef = (BaseRuntimeElementCompositeDefinition>) entryChildDef.getChildByName("entry");
+
+ BaseRuntimeChildDefinition resourceChildDef = entryChildContentsDef.getChildByName("resource");
+ BaseRuntimeChildDefinition requestChildDef = entryChildContentsDef.getChildByName("request");
+ BaseRuntimeElementCompositeDefinition> requestChildContentsDef = (BaseRuntimeElementCompositeDefinition>) requestChildDef.getChildByName("request");
+ BaseRuntimeChildDefinition requestUrlChildDef = requestChildContentsDef.getChildByName("url");
+ BaseRuntimeChildDefinition requestIfNoneExistChildDef = requestChildContentsDef.getChildByName("ifNoneExist");
+ BaseRuntimeChildDefinition methodChildDef = requestChildContentsDef.getChildByName("method");
for (IBase nextEntry : entries) {
IBaseResource resource = null;
@@ -206,15 +179,15 @@ public class BundleUtil {
RequestTypeEnum requestType = null;
String conditionalUrl = null;
- for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) {
- resource = (IBaseResource) next;
+ for (IBase nextResource : resourceChildDef.getAccessor().getValues(nextEntry)) {
+ resource = (IBaseResource) nextResource;
}
- for (IBase nextRequest : requestChild.getAccessor().getValues(nextEntry)) {
- for (IBase nextUrl : requestUrlChild.getAccessor().getValues(nextRequest)) {
+ for (IBase nextRequest : requestChildDef.getAccessor().getValues(nextEntry)) {
+ for (IBase nextUrl : requestUrlChildDef.getAccessor().getValues(nextRequest)) {
url = ((IPrimitiveType>) nextUrl).getValueAsString();
}
- for (IBase nextUrl : methodChild.getAccessor().getValues(nextRequest)) {
- String methodString = ((IPrimitiveType>) nextUrl).getValueAsString();
+ for (IBase nextMethod : methodChildDef.getAccessor().getValues(nextRequest)) {
+ String methodString = ((IPrimitiveType>) nextMethod).getValueAsString();
if (isNotBlank(methodString)) {
requestType = RequestTypeEnum.valueOf(methodString);
}
@@ -227,7 +200,7 @@ public class BundleUtil {
conditionalUrl = url != null && url.contains("?") ? url : null;
break;
case POST:
- List ifNoneExistReps = requestIfNoneExistChild.getAccessor().getValues(nextRequest);
+ List ifNoneExistReps = requestIfNoneExistChildDef.getAccessor().getValues(nextRequest);
if (ifNoneExistReps.size() > 0) {
IPrimitiveType> ifNoneExist = (IPrimitiveType>) ifNoneExistReps.get(0);
conditionalUrl = ifNoneExist.getValueAsString();
@@ -241,11 +214,10 @@ public class BundleUtil {
* All 3 might be null - That's ok because we still want to know the
* order in the original bundle.
*/
- retVal.add(new BundleEntryParts(requestType, url, resource, conditionalUrl));
+ BundleEntryMutator mutator = new BundleEntryMutator(nextEntry, requestChildDef, requestChildContentsDef);
+ ModifiableBundleEntry entry = new ModifiableBundleEntry(new BundleEntryParts(requestType, url, resource, conditionalUrl), mutator);
+ theProcessor.accept(entry);
}
-
-
- return retVal;
}
/**
@@ -278,4 +250,6 @@ public class BundleUtil {
}
return retVal;
}
+
+
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/EntryListAccumulator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/EntryListAccumulator.java
new file mode 100644
index 00000000000..0455a2d0ffd
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/EntryListAccumulator.java
@@ -0,0 +1,18 @@
+package ca.uhn.fhir.util.bundle;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
+class EntryListAccumulator implements Consumer {
+ private final List myList = new ArrayList<>();
+
+ @Override
+ public void accept(ModifiableBundleEntry theModifiableBundleEntry) {
+ myList.add(theModifiableBundleEntry.getBundleEntryParts());
+ }
+
+ public List getList() {
+ return myList;
+ }
+}
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
new file mode 100644
index 00000000000..e717f13e116
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/bundle/ModifiableBundleEntry.java
@@ -0,0 +1,32 @@
+package ca.uhn.fhir.util.bundle;
+
+import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
+import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.util.ParametersUtil;
+import org.hl7.fhir.instance.model.api.IBase;
+import org.hl7.fhir.instance.model.api.IPrimitiveType;
+
+public class ModifiableBundleEntry {
+ private final BundleEntryParts myBundleEntryParts;
+ private final BundleEntryMutator myBundleEntryMutator;
+
+ ModifiableBundleEntry(BundleEntryParts theBundleEntryParts, BundleEntryMutator theBundleEntryMutator) {
+ myBundleEntryParts = theBundleEntryParts;
+ myBundleEntryMutator = theBundleEntryMutator;
+ }
+
+ BundleEntryParts getBundleEntryParts() {
+ return myBundleEntryParts;
+ }
+
+ void setRequestUrl(FhirContext theFhirContext, String theRequestUrl) {
+ myBundleEntryMutator.setRequestUrl(theFhirContext, theRequestUrl);
+ }
+
+ String getRequestUrl() {
+ return myBundleEntryParts.getUrl();
+ }
+
+
+}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/schematron/SchematronBaseValidator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/schematron/SchematronBaseValidator.java
index 137f3dd7ae5..50d503e566b 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/schematron/SchematronBaseValidator.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/schematron/SchematronBaseValidator.java
@@ -23,7 +23,7 @@ package ca.uhn.fhir.validation.schematron;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
-import ca.uhn.fhir.util.BundleUtil;
+import ca.uhn.fhir.util.bundle.BundleUtil;
import ca.uhn.fhir.validation.*;
import com.helger.commons.error.IError;
import com.helger.commons.error.list.IErrorList;
diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/ExampleDataUploader.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/ExampleDataUploader.java
index ab0bebfa720..f169821fa98 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/ExampleDataUploader.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/ExampleDataUploader.java
@@ -35,7 +35,7 @@ import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
import ca.uhn.fhir.rest.client.apache.GZipContentInterceptor;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
-import ca.uhn.fhir.util.BundleUtil;
+import ca.uhn.fhir.util.bundle.BundleUtil;
import ca.uhn.fhir.util.ResourceReferenceInfo;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java
index 330b48cfeb8..c2abfdce8c1 100644
--- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java
+++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java
@@ -22,7 +22,6 @@ package ca.uhn.fhir.rest.client.method;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Reader;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
@@ -37,7 +36,7 @@ import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException;
-import ca.uhn.fhir.util.BundleUtil;
+import ca.uhn.fhir.util.bundle.BundleUtil;
import ca.uhn.fhir.util.ReflectionUtil;
public abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding