Skip to content

Commit 1b615b5

Browse files
fil512Ken Stevens
andauthored
expand BundleUtil functions (#7134)
* use ifMatch * spotless * add CanonicalBundleEntry * test passes * fix regression * clean up test * fix test * resolve warnings * changelog * FIXME * brainz! * bump pom version --------- Co-authored-by: Ken Stevens <[email protected]>
1 parent 8e54656 commit 1b615b5

File tree

93 files changed

+922
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+922
-90
lines changed

hapi-deployable-pom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-fhir</artifactId>
8-
<version>8.3.15-SNAPSHOT</version>
8+
<version>8.3.16-SNAPSHOT</version>
99

1010
<relativePath>../pom.xml</relativePath>
1111
</parent>

hapi-fhir-android/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-deployable-pom</artifactId>
8-
<version>8.3.15-SNAPSHOT</version>
8+
<version>8.3.16-SNAPSHOT</version>
99

1010
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
1111
</parent>

hapi-fhir-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-deployable-pom</artifactId>
8-
<version>8.3.15-SNAPSHOT</version>
8+
<version>8.3.16-SNAPSHOT</version>
99

1010
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
1111
</parent>

hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/InterceptorService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public InterceptorService() {
4747
*
4848
* @param theName The name for this registry (useful for troubleshooting)
4949
*/
50-
@Deprecated(since = "8.0.0", forRemoval = true)
5150
public InterceptorService(String theName) {
5251
super(Pointcut.class);
5352
}

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleBuilder.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public UpdateBuilder addTransactionUpdateEntry(IBaseResource theResource, String
225225

226226
IIdType id = getIdTypeForUpdate(theResource);
227227

228-
String fullUrl = id.getValue();
228+
String fullUrl = id.toVersionless().getValue();
229229
String verb = "PUT";
230230
String requestUrl = StringUtils.isBlank(theRequestUrl)
231231
? id.toUnqualifiedVersionless().getValue()
@@ -264,7 +264,7 @@ public void addTransactionUpdateIdOnlyEntry(IBaseResource theResource) {
264264

265265
IIdType id = getIdTypeForUpdate(theResource);
266266
String requestUrl = id.toUnqualifiedVersionless().getValue();
267-
String fullUrl = id.getValue();
267+
String fullUrl = id.toVersionless().getValue();
268268
String httpMethod = "PUT";
269269

270270
addIdOnlyEntry(requestUrl, httpMethod, fullUrl);
@@ -494,16 +494,32 @@ public void addMessageEntry(IBaseResource theResource) {
494494
* @return Returns the new entry.
495495
*/
496496
public IBase addEntry() {
497-
IBase entry = myEntryDef.newInstance();
498-
addEntry(entry);
499-
return entry;
497+
return addEntry(myEntryDef.newInstance());
500498
}
501499

500+
/**
501+
* Add an entry to the bundle.
502+
*
503+
* @param theEntry the entry to add to the bundle.
504+
* @return theEntry
505+
*/
502506
public IBase addEntry(IBase theEntry) {
503507
myEntryChild.getMutator().addValue(myBundle, theEntry);
504508
return theEntry;
505509
}
506510

511+
/**
512+
* Add an entry to the bundle.
513+
*
514+
* @param theEntry the canonical entry to add to the bundle. It will be converted to a FHIR version specific entry before adding.
515+
* @return
516+
*/
517+
public IBase addEntry(CanonicalBundleEntry theEntry) {
518+
IBase bundleEntry = theEntry.toBundleEntry(myContext, myEntryDef.getImplementingClass());
519+
addEntry(bundleEntry);
520+
return bundleEntry;
521+
}
522+
507523
/**
508524
* Creates new search instance for the specified entry.
509525
* Note that this method does not work for DSTU2 model classes, it will only work

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.commons.lang3.Validate;
4444
import org.apache.commons.lang3.tuple.Pair;
4545
import org.hl7.fhir.instance.model.api.IBase;
46+
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
4647
import org.hl7.fhir.instance.model.api.IBaseBinary;
4748
import org.hl7.fhir.instance.model.api.IBaseBundle;
4849
import org.hl7.fhir.instance.model.api.IBaseReference;
@@ -778,6 +779,24 @@ public static <T extends IBaseResource> List<T> toListOfResourcesOfType(
778779
return retVal;
779780
}
780781

782+
@Nonnull
783+
public static List<CanonicalBundleEntry> toListOfCanonicalBundleEntries(
784+
FhirContext theContext, IBaseBundle theBundle) {
785+
List<CanonicalBundleEntry> retVal = new ArrayList<>();
786+
787+
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
788+
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
789+
List<IBase> entries = entryChild.getAccessor().getValues(theBundle);
790+
791+
for (IBase nextEntry : entries) {
792+
CanonicalBundleEntry canonicalEntry =
793+
CanonicalBundleEntry.fromBundleEntry(theContext, (IBaseBackboneElement) nextEntry);
794+
retVal.add(canonicalEntry);
795+
}
796+
797+
return retVal;
798+
}
799+
781800
public static IBase getReferenceInBundle(
782801
@Nonnull FhirContext theFhirContext, @Nonnull String theUrl, @Nullable Object theAppContext) {
783802
if (!(theAppContext instanceof IBaseBundle) || isBlank(theUrl) || theUrl.startsWith("#")) {

0 commit comments

Comments
 (0)