From 8a8eb84fe61230fed2302b1ead828f31ae1a8e02 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 23 Mar 2021 18:14:06 -0400 Subject: [PATCH 1/5] Works on #2496, start with failing test --- ...ourceDaoR4SearchCustomSearchParamTest.java | 2 + ...sourceProviderCustomSearchParamR4Test.java | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java index 5e56111fa2d..1287cc05e15 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java @@ -277,6 +277,8 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test } } + + @Test @Disabled public void testCreateInvalidParamInvalidResourceName() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java index 2da45eeda72..f7abb0a9ec8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java @@ -14,6 +14,7 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.gclient.ReferenceClientParam; +import ca.uhn.fhir.rest.gclient.StringClientParam; import ca.uhn.fhir.rest.gclient.TokenClientParam; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.BundleUtil; @@ -31,6 +32,7 @@ import org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResource import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; +import org.hl7.fhir.r4.model.ExplanationOfBenefit; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Observation.ObservationStatus; import org.hl7.fhir.r4.model.Patient; @@ -54,6 +56,8 @@ import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -416,6 +420,59 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide } + + @SuppressWarnings("unused") + @Test + public void testSearchWithCustomParamInvalidDateFormat() { + + SearchParameter dateParameter = new SearchParameter(); + dateParameter.setId("explanationofbenefit-service-date"); + dateParameter.setName("ExplanationOfBenefit_ServiceDate"); + dateParameter.setCode("service-date"); + dateParameter.setDescription("test"); + dateParameter.setUrl("http://integer"); + dateParameter.setStatus(Enumerations.PublicationStatus.ACTIVE); + dateParameter.addBase("ExplanationOfBenefit"); + dateParameter.setType(Enumerations.SearchParamType.DATE); + dateParameter.setExpression("ExplanationOfBenefit.billablePeriod | ExplanationOfBenefit.item.serviced as Date | ExplanationOfBenefit.item.serviced as Period"); + dateParameter.setXpath("f:ExplanationOfBenefit/f:billablePeriod | f:ExplanationOfBenefit/f:item/f:serviced/f:servicedDate | f:ExplanationOfBenefit/f:item/f:serviced/f:servicedPeriod"); + dateParameter.setXpathUsage(SearchParameter.XPathUsageType.NORMAL); + mySearchParameterDao.update(dateParameter); + + mySearchParamRegistry.forceRefresh(); + + IBundleProvider results; + List foundResources; + Bundle result; + + + //Try with builtin SP + try { + myClient + .search() + .forResource(ExplanationOfBenefit.class) + .where(new StringClientParam("created").matchesExactly().value("01-01-2020")) + .returnBundle(Bundle.class) + .execute(); + + } catch (Exception e) { + assertThat(e.getMessage(), is(equalTo("HTTP 400 Bad Request: Invalid date/time format: \"01-01-2020\""))); + } + + //Now with custom SP + try { + myClient + .search() + .forResource(ExplanationOfBenefit.class) + .where(new StringClientParam("service-date").matchesExactly().value("01-01-2020")) + .returnBundle(Bundle.class) + .execute(); + + } catch (Exception e) { + assertThat(e.getMessage(), is(equalTo("HTTP 400 Bad Request: Invalid date/time format: \"01-01-2020\""))); + } + } + /** * See #1300 */ From 6f669f9ccdc343f5615b647bc1c1cb2ef8c24637 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 23 Mar 2021 19:29:22 -0400 Subject: [PATCH 2/5] wip --- .../provider/r4/ResourceProviderCustomSearchParamR4Test.java | 4 ++-- .../server/interceptor/ExceptionHandlingInterceptor.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java index f7abb0a9ec8..991de4e3eca 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java @@ -451,7 +451,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide myClient .search() .forResource(ExplanationOfBenefit.class) - .where(new StringClientParam("created").matchesExactly().value("01-01-2020")) + .where(new StringClientParam("created").matches().value("01-01-2020")) .returnBundle(Bundle.class) .execute(); @@ -464,7 +464,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide myClient .search() .forResource(ExplanationOfBenefit.class) - .where(new StringClientParam("service-date").matchesExactly().value("01-01-2020")) + .where(new StringClientParam("service-date").matches().value("01-01-2020")) .returnBundle(Bundle.class) .execute(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java index 68b6d4225f8..9192543b3eb 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java @@ -107,7 +107,10 @@ public class ExceptionHandlingInterceptor { @Hook(Pointcut.SERVER_PRE_PROCESS_OUTGOING_EXCEPTION) public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException { BaseServerResponseException retVal; - if (theException instanceof DataFormatException) { + //TODO GGG this is _not_ the fix. + if (theException instanceof InternalErrorException && theException.getCause().getCause() instanceof DataFormatException) { + retVal = new InvalidRequestException(theException.getCause().getCause()); + } else if (theException instanceof DataFormatException) { // Wrapping the DataFormatException as an InvalidRequestException so that it gets sent back to the client as a 400 response. retVal = new InvalidRequestException(theException); } else if (!(theException instanceof BaseServerResponseException)) { From a2ab3f55733b6e9d6a78276bd3883c4a66af9fb0 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 23 Mar 2021 19:49:06 -0400 Subject: [PATCH 3/5] rethrow dataformatexception in case of TargetInvocationException --- .../ca/uhn/fhir/rest/server/method/BaseMethodBinding.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java index 611ba8ab0aa..f89ccc8025a 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java @@ -26,6 +26,7 @@ import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; @@ -251,6 +252,9 @@ public abstract class BaseMethodBinding { if (e.getCause() instanceof BaseServerResponseException) { throw (BaseServerResponseException) e.getCause(); } + if (e.getTargetException() instanceof DataFormatException) { + throw (DataFormatException)e.getTargetException(); + } throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } catch (Exception e) { throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); From 8785a518575f896fcb2ba9f79dd26d57094366fc Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 23 Mar 2021 19:50:05 -0400 Subject: [PATCH 4/5] Remove janky interceptor hook --- .../server/interceptor/ExceptionHandlingInterceptor.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java index 9192543b3eb..68b6d4225f8 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java @@ -107,10 +107,7 @@ public class ExceptionHandlingInterceptor { @Hook(Pointcut.SERVER_PRE_PROCESS_OUTGOING_EXCEPTION) public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException { BaseServerResponseException retVal; - //TODO GGG this is _not_ the fix. - if (theException instanceof InternalErrorException && theException.getCause().getCause() instanceof DataFormatException) { - retVal = new InvalidRequestException(theException.getCause().getCause()); - } else if (theException instanceof DataFormatException) { + if (theException instanceof DataFormatException) { // Wrapping the DataFormatException as an InvalidRequestException so that it gets sent back to the client as a 400 response. retVal = new InvalidRequestException(theException); } else if (!(theException instanceof BaseServerResponseException)) { From 8352bc9c018242529ea6e119e24590dbc64b560a Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 25 Mar 2021 10:52:15 -0400 Subject: [PATCH 5/5] Correct the path to the select2 library in the testpage overlay (#2505) * Correct the path to the select2 library in the testpage overlay * Add changelog --- .../uhn/hapi/fhir/changelog/5_4_0/2505-fix-select2-path.yaml | 5 +++++ .../src/main/webapp/WEB-INF/templates/tmpl-head.html | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_4_0/2505-fix-select2-path.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_4_0/2505-fix-select2-path.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_4_0/2505-fix-select2-path.yaml new file mode 100644 index 00000000000..40a7cbd0e46 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_4_0/2505-fix-select2-path.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 2505 +title: "An incorrect path caused the select2 library to fail to load in the HAPI FHIR testpage overlay + modue. Thanks to Ari Ruotsalainen for reporting!" diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-head.html b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-head.html index 8867accc268..8fc426c8bfc 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-head.html +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-head.html @@ -31,8 +31,8 @@ - - + +