changed toListOfResources to send IBaseResource as Type instead of null
This commit is contained in:
parent
a5e7ea16ae
commit
7f45660a15
|
@ -190,7 +190,7 @@ public class BundleUtil {
|
|||
* Extract all of the resources from a given bundle
|
||||
*/
|
||||
public static List<IBaseResource> toListOfResources(FhirContext theContext, IBaseBundle theBundle) {
|
||||
return toListOfResourcesOfType(theContext, theBundle, null);
|
||||
return toListOfResourcesOfType(theContext, theBundle, IBaseResource.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,36 +209,36 @@ public class BundleUtil {
|
|||
BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource");
|
||||
for (IBase nextEntry : entries) {
|
||||
for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) {
|
||||
if (!theTypeToInclude.isAssignableFrom(next.getClass())) {
|
||||
continue;
|
||||
}
|
||||
if (theTypeToInclude.isAssignableFrom(next.getClass())) {
|
||||
retVal.add((T) next);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static class BundleEntryParts
|
||||
{
|
||||
public static class BundleEntryParts {
|
||||
private final RequestTypeEnum myRequestType;
|
||||
private final IBaseResource myResource;
|
||||
private final String myUrl;
|
||||
|
||||
BundleEntryParts(RequestTypeEnum theRequestType, String theUrl, IBaseResource theResource) {
|
||||
super();
|
||||
myRequestType = theRequestType;
|
||||
myUrl = theUrl;
|
||||
myResource = theResource;
|
||||
}
|
||||
|
||||
public RequestTypeEnum getRequestType() {
|
||||
return myRequestType;
|
||||
}
|
||||
|
||||
public IBaseResource getResource() {
|
||||
return myResource;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return myUrl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@ package ca.uhn.fhir.util;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BundleUtilTest {
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forR4();
|
||||
|
@ -38,6 +41,17 @@ public class BundleUtilTest {
|
|||
Assert.assertEquals(null, BundleUtil.getTotal(ourCtx, b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toListOfResourcesOfTypeTest() {
|
||||
Bundle bundle = new Bundle();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
bundle.addEntry(new Bundle.BundleEntryComponent().setResource(new Patient()));
|
||||
}
|
||||
List<Patient> list = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class);
|
||||
Assert.assertEquals(5, list.size());
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
|
Loading…
Reference in New Issue