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.*;
/*
* #%L
* HAPI FHIR - Core Library

View File

@ -248,39 +248,42 @@ public class BundleUtil {
for (BundleEntryParts bundleEntryPart : bundleEntryParts) {
IBaseResource resource = bundleEntryPart.getResource();
String resourceId = resource.getIdElement().toVersionless().toString();
resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart);
if (resourceId == null) {
if (bundleEntryPart.getFullUrl() != null) {
resourceId = bundleEntryPart.getFullUrl();
if (resource != null) {
String resourceId = resource.getIdElement().toVersionless().toString();
resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart);
if (resourceId == null) {
if (bundleEntryPart.getFullUrl() != null) {
resourceId = bundleEntryPart.getFullUrl();
}
}
color.put(resourceId, WHITE);
}
color.put(resourceId, WHITE);
}
for (BundleEntryParts bundleEntryPart : bundleEntryParts) {
IBaseResource resource = bundleEntryPart.getResource();
String resourceId = resource.getIdElement().toVersionless().toString();
resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart);
if (resourceId == null) {
if (bundleEntryPart.getFullUrl() != null) {
resourceId = bundleEntryPart.getFullUrl();
}
}
List<ResourceReferenceInfo> allResourceReferences = theContext.newTerser().getAllResourceReferences(resource);
String finalResourceId = resourceId;
allResourceReferences
.forEach(refInfo -> {
String referencedResourceId = refInfo.getResourceReference().getReferenceElement().toVersionless().getValue();
if (color.containsKey(referencedResourceId)) {
if (!adjList.containsKey(finalResourceId)) {
adjList.put(finalResourceId, new ArrayList<>());
}
adjList.get(finalResourceId).add(referencedResourceId);
if (resource != null) {
String resourceId = resource.getIdElement().toVersionless().toString();
resourceIdToBundleEntryMap.put(resourceId, bundleEntryPart);
if (resourceId == null) {
if (bundleEntryPart.getFullUrl() != null) {
resourceId = bundleEntryPart.getFullUrl();
}
});
}
List<ResourceReferenceInfo> allResourceReferences = theContext.newTerser().getAllResourceReferences(resource);
String finalResourceId = resourceId;
allResourceReferences
.forEach(refInfo -> {
String referencedResourceId = refInfo.getResourceReference().getReferenceElement().toVersionless().getValue();
if (color.containsKey(referencedResourceId)) {
if (!adjList.containsKey(finalResourceId)) {
adjList.put(finalResourceId, new ArrayList<>());
}
adjList.get(finalResourceId).add(referencedResourceId);
}
});
}
}
for (Map.Entry<String, Integer> entry:color.entrySet()) {

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.util.bundle;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.BundleBuilder;
import ca.uhn.fhir.util.BundleUtil;
import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.r4.model.Bundle;
@ -256,6 +257,15 @@ public class BundleUtilTest {
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
public void testTransactionSorterReturnsDeletesInCorrectProcessingOrder() {
Bundle b = new Bundle();