From 705735b9c08c82e5c2eda46e81bb0acf7f2140c7 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Tue, 3 Mar 2020 13:29:10 -0500 Subject: [PATCH] review feedback: javadoc --- .../java/ca/uhn/fhir/jpa/dao/SearchBuilder.java | 4 ++-- .../jpa/searchparam/MatchUrlServiceTest.java | 8 ++++---- ...tanceHelper.java => Dstu3DistanceHelper.java} | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) rename hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/{DistanceHelper.java => Dstu3DistanceHelper.java} (74%) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index 75d6eca09b2..008b0a8fe7e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -40,7 +40,7 @@ import ca.uhn.fhir.jpa.model.search.StorageProcessingMessage; import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; -import ca.uhn.fhir.jpa.searchparam.util.DistanceHelper; +import ca.uhn.fhir.jpa.searchparam.util.Dstu3DistanceHelper; import ca.uhn.fhir.jpa.util.*; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.IResource; @@ -163,7 +163,7 @@ public class SearchBuilder implements ISearchBuilder { // For DSTU3, pull out near-distance first so when it comes time to evaluate near, we already know the distance if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU3) { - DistanceHelper.setNearDistance(myResourceType, theParams); + Dstu3DistanceHelper.setNearDistance(myResourceType, theParams); } /* diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java index 8d37227f734..6ee336af59c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.jpa.config.TestDstu3Config; import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; -import ca.uhn.fhir.jpa.searchparam.util.DistanceHelper; +import ca.uhn.fhir.jpa.searchparam.util.Dstu3DistanceHelper; import ca.uhn.fhir.rest.param.QuantityParam; import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.util.TestUtil; @@ -59,7 +59,7 @@ public class MatchUrlServiceTest extends BaseJpaTest { Location.SP_NEAR + "=1000.0:2000.0" + "&" + Location.SP_NEAR_DISTANCE + "=" + kmDistance + "|http://unitsofmeasure.org|km", ourCtx.getResourceDefinition("Location")); - DistanceHelper.setNearDistance(Location.class, map); + Dstu3DistanceHelper.setNearDistance(Location.class, map); QuantityParam nearDistanceParam = map.getNearDistanceParam(); assertEquals(1, map.size()); @@ -76,7 +76,7 @@ public class MatchUrlServiceTest extends BaseJpaTest { "&" + Location.SP_NEAR_DISTANCE + "=2|http://unitsofmeasure.org|km", ourCtx.getResourceDefinition("Location")); - DistanceHelper.setNearDistance(Location.class, map); + Dstu3DistanceHelper.setNearDistance(Location.class, map); fail(); } catch (IllegalArgumentException e) { @@ -93,7 +93,7 @@ public class MatchUrlServiceTest extends BaseJpaTest { "," + "2|http://unitsofmeasure.org|km", ourCtx.getResourceDefinition("Location")); - DistanceHelper.setNearDistance(Location.class, map); + Dstu3DistanceHelper.setNearDistance(Location.class, map); fail(); } catch (IllegalArgumentException e) { diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/DistanceHelper.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java similarity index 74% rename from hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/DistanceHelper.java rename to hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java index f66e4a8b122..950e8b1fcfa 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/DistanceHelper.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java @@ -9,7 +9,15 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import java.util.List; -public class DistanceHelper { + +/** + * In DSTU3, the near-distance search parameter is separate from near. In this utility method, + * we search for near-distance search parameters and if we find any, remove them from the list + * of search parameters and store it in a dedicated field in {@link SearchParameterMap}. This is so that + * when the "near" search parameter is processed, we have access to this near-distance value. + * This requires at most one near-distance parameter. If more are found, we throw an {@link IllegalArgumentException}. + */ +public class Dstu3DistanceHelper { public static void setNearDistance(Class theResourceType, SearchParameterMap theParams) { if (theResourceType == Location.class && theParams.containsKey(Location.SP_NEAR_DISTANCE)) { List> paramAndList = theParams.get(Location.SP_NEAR_DISTANCE); @@ -38,7 +46,7 @@ public class DistanceHelper { ReferenceParam referenceParam = (ReferenceParam) param; if (Location.SP_NEAR_DISTANCE.equals(referenceParam.getChain())) { if (retval != null) { - throw new IllegalArgumentException("Only one " + ca.uhn.fhir.model.dstu2.resource.Location.SP_NEAR_DISTANCE + " parameter may be present"); + throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present"); } else { retval = referenceParam; orParamToRemove = param; @@ -64,14 +72,14 @@ public class DistanceHelper { return null; } if (theParamAndList.size() > 1) { - throw new IllegalArgumentException("Only one " + ca.uhn.fhir.model.dstu2.resource.Location.SP_NEAR_DISTANCE + " parameter may be present"); + throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present"); } List paramOrList = theParamAndList.get(0); if (paramOrList.isEmpty()) { return null; } if (paramOrList.size() > 1) { - throw new IllegalArgumentException("Only one " + ca.uhn.fhir.model.dstu2.resource.Location.SP_NEAR_DISTANCE + " parameter may be present"); + throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present"); } return (QuantityParam) paramOrList.get(0); }