Merge pull request #2877 from hapifhir/2876-npe-mdm-resource-util

NPE in MdmResourceUtil
This commit is contained in:
Tadgh 2021-08-10 08:13:19 -04:00 committed by GitHub
commit 3edb59475c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 6 deletions

View File

@ -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."

View File

@ -69,6 +69,9 @@ public class ChangelogFilesTest {
// this one is optional
fieldNames.remove("backport");
// this one is optional
fieldNames.remove("jira");
assertThat("Invalid element in " + next + ": " + fieldNames, fieldNames, empty());
if (haveIssue) {

View File

@ -76,19 +76,19 @@ public final class MdmResourceUtil {
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) {
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) {
return theResource.getMeta().getTag().stream().filter(tag -> tag.getSystem().equalsIgnoreCase(theSystem)).findFirst();
private static Optional<? extends IBaseCoding> getTagWithSystem(IBaseResource theResource, @Nonnull String theSystem) {
return theResource.getMeta().getTag().stream().filter(tag -> theSystem.equalsIgnoreCase(tag.getSystem())).findFirst();
}
public static void removeTagWithSystem(IBaseResource theResource, String theSystem) {
theResource.getMeta().getTag().removeIf(tag -> tag.getSystem().equalsIgnoreCase(theSystem));
public static void removeTagWithSystem(IBaseResource theResource, @Nonnull String theSystem) {
theResource.getMeta().getTag().removeIf(tag -> theSystem.equalsIgnoreCase(tag.getSystem()));
}
/**

View File

@ -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)));
}
}