From 94d6b15db9e89e8dec532e6bc741a5e06c6e5e02 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Thu, 3 Jun 2021 18:45:49 -0400 Subject: [PATCH] _filter searchparam should not appear in cap stmt if disabled (#2706) * issue reproduced and fixed * changelog * cleanup --- ...-filter-searchparam-capability-statement.yaml | 5 +++++ .../provider/JpaCapabilityStatementProvider.java | 5 +++++ ...rverCapabilityStatementProviderJpaR4Test.java | 16 +++++++++++----- .../ServerCapabilityStatementProvider.java | 14 ++++++++++++-- 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2706-filter-searchparam-capability-statement.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2706-filter-searchparam-capability-statement.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2706-filter-searchparam-capability-statement.yaml new file mode 100644 index 00000000000..264c27ef4df --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2706-filter-searchparam-capability-statement.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 2695 +title: "The _filter search parameter was incorrectly included in the server capability statement if it was disabled +on the server. This has been corrected." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaCapabilityStatementProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaCapabilityStatementProvider.java index 08c123988cd..818f61f4205 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaCapabilityStatementProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaCapabilityStatementProvider.java @@ -145,4 +145,9 @@ public class JpaCapabilityStatementProvider extends ServerCapabilityStatementPro public void setSystemDao(IFhirSystemDao mySystemDao) { this.mySystemDao = mySystemDao; } + + @Override + protected boolean searchParamEnabled(String theSearchParam) { + return !Constants.PARAM_FILTER.equals(theSearchParam) || myDaoConfig.isFilterParameterEnabled(); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java index 45e93625d7f..f32eb24e324 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java @@ -1,8 +1,9 @@ package ca.uhn.fhir.jpa.provider.r4; +import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.packages.PackageInstallationSpec; -import ca.uhn.fhir.jpa.provider.JpaCapabilityStatementProvider; import ca.uhn.fhir.rest.api.CacheControlDirective; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.provider.ServerCapabilityStatementProvider; import org.hl7.fhir.r4.model.CapabilityStatement; import org.hl7.fhir.r4.model.Enumerations; @@ -12,22 +13,19 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Nonnull; import java.io.IOException; import java.util.List; -import java.util.TreeSet; import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProviderR4Test { @@ -117,6 +115,7 @@ public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProv public void after() throws Exception { super.after(); ourCapabilityStatementProvider.setRestResourceRevIncludesEnabled(ServerCapabilityStatementProvider.DEFAULT_REST_RESOURCE_REV_INCLUDES_ENABLED); + myDaoConfig.setFilterParameterEnabled(new DaoConfig().isFilterParameterEnabled()); } @@ -259,6 +258,13 @@ public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProv )); } + @Test + public void testFilterProperlyReported() { + myDaoConfig.setFilterParameterEnabled(false); + CapabilityStatement cs = myClient.capabilities().ofType(CapabilityStatement.class).execute(); + assertThat(findSearchParams(cs, "Patient", Constants.PARAM_FILTER), hasSize(0)); + } + @Nonnull private List findSupportedProfiles(CapabilityStatement theCapabilityStatement, String theResourceType) { assertEquals(1, theCapabilityStatement.getRest().size()); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ServerCapabilityStatementProvider.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ServerCapabilityStatementProvider.java index d856dfd9598..923bc8f5519 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ServerCapabilityStatementProvider.java @@ -391,8 +391,9 @@ public class ServerCapabilityStatementProvider implements IServerConformanceProv searchParamRegistry = mySearchParamRegistry; searchParams = new HashMap<>(mySearchParamRegistry.getActiveSearchParams(resourceName)); for (Entry nextBuiltInSp : serverConfiguration.getActiveSearchParams(resourceName).entrySet()) { - if (nextBuiltInSp.getKey().startsWith("_") && !searchParams.containsKey(nextBuiltInSp.getKey())) { - searchParams.put(nextBuiltInSp.getKey(), nextBuiltInSp.getValue()); + String key = nextBuiltInSp.getKey(); + if (key.startsWith("_") && !searchParams.containsKey(key) && searchParamEnabled(key)) { + searchParams.put(key, nextBuiltInSp.getValue()); } } } else { @@ -534,6 +535,15 @@ public class ServerCapabilityStatementProvider implements IServerConformanceProv return retVal; } + /** + * + * @param theSearchParam + * @return true if theSearchParam is enabled on this server + */ + protected boolean searchParamEnabled(String theSearchParam) { + return true; + } + private void addSearchMethodIfSearchIsNamedQuery(RequestDetails theRequestDetails, Bindings theBindings, FhirTerser theTerser, Set theOperationNamesAlreadyAdded, IBase theElementToAddTo, SearchMethodBinding theSearchMethodBinding) { if (theSearchMethodBinding.getQueryName() != null) { String queryName = theBindings.getNamedSearchMethodBindingToName().get(theSearchMethodBinding);