Merge pull request #2877 from hapifhir/2876-npe-mdm-resource-util
NPE in MdmResourceUtil
This commit is contained in:
commit
3edb59475c
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 2876
|
||||||
|
jira: SMILE-1006
|
||||||
|
backport: 5.5.0
|
||||||
|
title: "Fixed a bug wherein an NPE could be thrown by the MDM module interceptor if an incoming resource had a tag with no system."
|
|
@ -69,6 +69,9 @@ public class ChangelogFilesTest {
|
||||||
// this one is optional
|
// this one is optional
|
||||||
fieldNames.remove("backport");
|
fieldNames.remove("backport");
|
||||||
|
|
||||||
|
// this one is optional
|
||||||
|
fieldNames.remove("jira");
|
||||||
|
|
||||||
assertThat("Invalid element in " + next + ": " + fieldNames, fieldNames, empty());
|
assertThat("Invalid element in " + next + ": " + fieldNames, fieldNames, empty());
|
||||||
|
|
||||||
if (haveIssue) {
|
if (haveIssue) {
|
||||||
|
|
|
@ -76,19 +76,19 @@ public final class MdmResourceUtil {
|
||||||
return theBaseResource.getMeta().getTag(theSystem, theCode) != null;
|
return theBaseResource.getMeta().getTag(theSystem, theCode) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean resourceHasTagWithSystem(IBaseResource theBaseResource, String theSystem) {
|
private static boolean resourceHasTagWithSystem(IBaseResource theBaseResource, @Nonnull String theSystem) {
|
||||||
if (theBaseResource == null) {
|
if (theBaseResource == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return theBaseResource.getMeta().getTag().stream().anyMatch(tag -> tag.getSystem().equalsIgnoreCase(theSystem));
|
return theBaseResource.getMeta().getTag().stream().anyMatch(tag -> theSystem.equalsIgnoreCase(tag.getSystem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<? extends IBaseCoding> getTagWithSystem(IBaseResource theResource, String theSystem) {
|
private static Optional<? extends IBaseCoding> getTagWithSystem(IBaseResource theResource, @Nonnull String theSystem) {
|
||||||
return theResource.getMeta().getTag().stream().filter(tag -> tag.getSystem().equalsIgnoreCase(theSystem)).findFirst();
|
return theResource.getMeta().getTag().stream().filter(tag -> theSystem.equalsIgnoreCase(tag.getSystem())).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeTagWithSystem(IBaseResource theResource, String theSystem) {
|
public static void removeTagWithSystem(IBaseResource theResource, @Nonnull String theSystem) {
|
||||||
theResource.getMeta().getTag().removeIf(tag -> tag.getSystem().equalsIgnoreCase(theSystem));
|
theResource.getMeta().getTag().removeIf(tag -> theSystem.equalsIgnoreCase(tag.getSystem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package ca.uhn.fhir.mdm.util;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r4.model.Organization;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
class MdmResourceUtilTest {
|
||||||
|
|
||||||
|
//See https://github.com/hapifhir/hapi-fhir/issues/2876
|
||||||
|
@Test
|
||||||
|
public void testNoNpeOnTagWithNoSystem() {
|
||||||
|
//Given
|
||||||
|
Organization organization = new Organization();
|
||||||
|
organization.getMeta().addTag(null, "Some Code", "Some Display");
|
||||||
|
|
||||||
|
boolean hasGoldenRecordTag = MdmResourceUtil.hasGoldenRecordSystemTag(organization);
|
||||||
|
|
||||||
|
assertThat(hasGoldenRecordTag, is(equalTo(false)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue