From 1faf77dcc8394929377fdf7da378a005a8e2b495 Mon Sep 17 00:00:00 2001 From: Luke deGruchy Date: Thu, 30 Mar 2023 12:51:17 -0400 Subject: [PATCH] Fix error message for bad $mdm-link-history input and handle comma-delimited input (#4701) * Fix error message for bad $mdm-link-history input and handle comma-delimited input. * Code review feedback: filter out null objects in the stream. --- ...ror-messge-and-comma-delimited-inputs.yaml | 5 +++++ .../fhir/mdm/provider/BaseMdmProvider.java | 20 ++++++++++++++----- .../MdmLinkHistoryProviderDstu3Plus.java | 4 ++-- 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4700-mdm-link-history-error-messge-and-comma-delimited-inputs.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4700-mdm-link-history-error-messge-and-comma-delimited-inputs.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4700-mdm-link-history-error-messge-and-comma-delimited-inputs.yaml new file mode 100644 index 00000000000..5451276a03d --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4700-mdm-link-history-error-messge-and-comma-delimited-inputs.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 4700 +title: "When querying $mdm-link-history with no inputs, the error message is mislaeading. Also, $mdm-link-history cannot handle comma-delimited inputs. + Both issues are now fixed." diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/BaseMdmProvider.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/BaseMdmProvider.java index cea40b6571e..b878cf8ad69 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/BaseMdmProvider.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/BaseMdmProvider.java @@ -41,8 +41,11 @@ import org.springframework.data.domain.Page; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Collection; +import java.util.Objects; import java.util.stream.Collectors; @@ -74,7 +77,7 @@ public abstract class BaseMdmProvider { private void validateBothCannotBeNullOrEmpty(String theFirstName, List> theFirstList, String theSecondName, List> theSecondList) { if ((theFirstList == null || theFirstList.isEmpty()) && (theSecondList == null || theSecondList.isEmpty())) { - throw new InvalidRequestException(Msg.code(2292) + "both ["+theFirstName+"] and ["+theSecondName+"] cannot be null or empty"); + throw new InvalidRequestException(Msg.code(2292) + "Please include either ["+theFirstName+"]s, ["+theSecondName+"]s, or both in your search inputs."); } } @@ -123,10 +126,17 @@ public abstract class BaseMdmProvider { } @Nonnull - protected List convertToStringsIfNotNull(List> thePrimitiveTypeStrings) { - return thePrimitiveTypeStrings == null - ? Collections.emptyList() - : thePrimitiveTypeStrings.stream().map(this::extractStringOrNull).collect(Collectors.toUnmodifiableList()); + protected List convertToStringsIncludingCommaDelimitedIfNotNull(List> thePrimitiveTypeStrings) { + if (thePrimitiveTypeStrings == null) { + return Collections.emptyList(); + } + + return thePrimitiveTypeStrings.stream() + .map(this::extractStringOrNull) + .filter(Objects::nonNull) + .map(input -> Arrays.asList(input.split(","))) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableList()); } protected String extractStringOrNull(IPrimitiveType theString) { diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/MdmLinkHistoryProviderDstu3Plus.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/MdmLinkHistoryProviderDstu3Plus.java index 06018d3585a..d8121176a55 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/MdmLinkHistoryProviderDstu3Plus.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/provider/MdmLinkHistoryProviderDstu3Plus.java @@ -53,8 +53,8 @@ public class MdmLinkHistoryProviderDstu3Plus extends BaseMdmProvider { ServletRequestDetails theRequestDetails) { validateMdmLinkHistoryParameters(theMdmGoldenResourceIds, theResourceIds); - final List goldenResourceIdsToUse = convertToStringsIfNotNull(theMdmGoldenResourceIds); - final List resourceIdsToUse = convertToStringsIfNotNull(theResourceIds); + final List goldenResourceIdsToUse = convertToStringsIncludingCommaDelimitedIfNotNull(theMdmGoldenResourceIds); + final List resourceIdsToUse = convertToStringsIncludingCommaDelimitedIfNotNull(theResourceIds); final IBaseParameters retVal = ParametersUtil.newInstance(myFhirContext);