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 f50b9367810..a98aa6faecb 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 @@ -1292,16 +1292,6 @@ public class SearchBuilder implements ISearchBuilder { private Predicate addPredicateCoords(String theResourceName, String theParamName, List theList) { - return addPredicateCoords(theResourceName, - theParamName, - theList, - null); - } - - private Predicate addPredicateCoords(String theResourceName, - String theParamName, - List theList, - SearchFilterParser.CompareOperation operation) { Join join = createJoin(JoinEnum.COORDS, theParamName); if (theList.get(0).getMissing() != null) { @@ -1316,8 +1306,8 @@ public class SearchBuilder implements ISearchBuilder { theResourceName, theParamName, myBuilder, - join, - operation); + join + ); codePredicates.add(singleCode); } @@ -2082,24 +2072,14 @@ public class SearchBuilder implements ISearchBuilder { String theResourceName, String theParamName, CriteriaBuilder theBuilder, - From theFrom, - SearchFilterParser.CompareOperation operation) { - // FIXME KHS - + From theFrom) { String latitudeValue; String longitudeValue; - BigDecimal valueValue; - - // FIXME KHS test - if (operation != null) { - throw new IllegalArgumentException("Operators not supported for Coordinate searches: " + operation.toString()); - } if (theParam instanceof TokenParam) { TokenParam param = (TokenParam) theParam; String value = param.getValue(); String[] parts = value.split(":"); - // FIXME KHS test if (parts.length != 2) { throw new IllegalArgumentException("Invalid position format '" + value + "'. Required format is 'latitude:longitude'"); } @@ -2119,7 +2099,6 @@ public class SearchBuilder implements ISearchBuilder { latitudePredicate = theBuilder.equal(theFrom.get("myLatitude"), latitudeValue); longitudePredicate = theBuilder.equal(theFrom.get("myLongitude"), longitudeValue); } else { - // FIXME KHS suppress hash Double distance = distanceParam.getValue().doubleValue(); if (distance < 0.0) { throw new IllegalArgumentException("Invalid " + Location.SP_NEAR_DISTANCE + " parameter '" + distance + "' must be >= 0.0"); @@ -2288,8 +2267,6 @@ public class SearchBuilder implements ISearchBuilder { */ final TypedQuery query = myEntityManager.createQuery(outerQuery); - // FIXME KHS query - if (theMaximumResults != null) { query.setMaxResults(theMaximumResults); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java index fb6b1a715b7..87469cab62e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java @@ -83,8 +83,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 { }; retVal.setDriver(new org.h2.Driver()); - // FIXME KHS - retVal.setUrl("jdbc:h2:file:./target/testdb_dstu3"); + retVal.setUrl("jdbc:h2:mem:testdb_dstu3"); retVal.setMaxWaitMillis(10000); retVal.setUsername(""); retVal.setPassword(""); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index 9c81def77c3..1556b47ae9c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -37,6 +37,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; @@ -3515,11 +3516,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Location loc = new Location(); double latitude = 1000.0; double longitude = 2000.0; - double offset = 50.0; Location.LocationPositionComponent position = new Location.LocationPositionComponent().setLatitude(latitude).setLongitude(longitude); loc.setPosition(position); String locId = myLocationDao.create(loc).getId().toUnqualifiedVersionless().getValue(); + double offset = 50.0; SearchParameterMap map = myMatchUrlService.translateMatchUrl( "Location?" + Location.SP_NEAR + "=" + (latitude + offset) + ":" + (longitude - offset) + @@ -3530,6 +3531,39 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { assertThat(ids, contains(locId)); } + @Test + public void testBadCoordsFormat() { + assertInvalidNearFormat("1:2:3"); + assertInvalidNearFormat("1:"); + assertInvalidNearFormat(":"); + assertInvalidNearFormat(""); + } + + private void assertInvalidNearFormat(String theCoords) { + SearchParameterMap map = new SearchParameterMap(); + map.add(Location.SP_NEAR, new TokenParam(theCoords)); + map.setLoadSynchronous(true); + try { + myLocationDao.search(map); + fail(); + } catch (InvalidDataAccessApiUsageException e) { + assertEquals("Invalid position format '" + theCoords + "'. Required format is 'latitude:longitude'", e.getCause().getMessage()); + } + } + + @Test + public void testNearMissingLat() { + SearchParameterMap map = new SearchParameterMap(); + map.add(Location.SP_NEAR, new TokenParam(":2")); + map.setLoadSynchronous(true); + try { + myLocationDao.search(map); + fail(); + } catch (InvalidDataAccessApiUsageException e) { + assertEquals("Invalid position format ':2'. Both latitude and longitude must be provided.", e.getCause().getMessage()); + } + } + private String toStringMultiline(List theResults) { StringBuilder b = new StringBuilder(); for (Object next : theResults) {