Handle sorting entries which contain no resources

This commit is contained in:
Tadgh 2021-04-26 22:24:47 -04:00
parent 798e960bb8
commit a5e734fec8
3 changed files with 41 additions and 26 deletions

View File

@ -10,6 +10,8 @@ import java.util.concurrent.ConcurrentHashMap;
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.*;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * HAPI FHIR - Core Library

View File

@ -248,6 +248,7 @@ public class BundleUtil {
for (BundleEntryParts bundleEntryPart : bundleEntryParts) { for (BundleEntryParts bundleEntryPart : bundleEntryParts) {
IBaseResource resource = bundleEntryPart.getResource(); IBaseResource resource = bundleEntryPart.getResource();
if (resource != null) {
String resourceId = resource.getIdElement().toVersionless().toString(); String resourceId = resource.getIdElement().toVersionless().toString();
resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart); resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart);
if (resourceId == null) { if (resourceId == null) {
@ -257,11 +258,12 @@ public class BundleUtil {
} }
color.put(resourceId, WHITE); color.put(resourceId, WHITE);
}
} }
for (BundleEntryParts bundleEntryPart : bundleEntryParts) { for (BundleEntryParts bundleEntryPart : bundleEntryParts) {
IBaseResource resource = bundleEntryPart.getResource(); IBaseResource resource = bundleEntryPart.getResource();
if (resource != null) {
String resourceId = resource.getIdElement().toVersionless().toString(); String resourceId = resource.getIdElement().toVersionless().toString();
resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart); resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart);
if (resourceId == null) { if (resourceId == null) {
@ -282,6 +284,7 @@ public class BundleUtil {
} }
}); });
} }
}
for (Map.Entry<String, Integer> entry:color.entrySet()) { for (Map.Entry<String, Integer> entry:color.entrySet()) {
if (entry.getValue() == WHITE) { if (entry.getValue() == WHITE) {

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.util.bundle; package ca.uhn.fhir.util.bundle;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.BundleBuilder;
import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.BundleUtil;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle;
@ -256,6 +257,15 @@ public class BundleUtilTest {
assertThat(entry.get(6).getRequest().getMethod(), is(equalTo(GET))); assertThat(entry.get(6).getRequest().getMethod(), is(equalTo(GET)));
} }
@Test
public void testBundleSortsCanHandlesDeletesThatContainNoResources() {
Patient p = new Patient();
p.setId("Patient/123");
BundleBuilder builder = new BundleBuilder(ourCtx);
builder.addTransactionDeleteEntry(p);
BundleUtil.sortEntriesIntoProcessingOrder(ourCtx, builder.getBundle());
}
@Test @Test
public void testTransactionSorterReturnsDeletesInCorrectProcessingOrder() { public void testTransactionSorterReturnsDeletesInCorrectProcessingOrder() {
Bundle b = new Bundle(); Bundle b = new Bundle();