This commit is contained in:
Ken Stevens 2020-01-23 18:49:09 -05:00
parent 3e28047f78
commit 99949629a8
13 changed files with 86 additions and 109 deletions

View File

@ -39,7 +39,6 @@ abstract class BasePredicateBuilder {
final String myResourceName;
final SearchParameterMap myParams;
// FIXME KHS autowire with lookup
BasePredicateBuilder(SearchBuilder theSearchBuilder) {
myCallingDao = theSearchBuilder.getCallingDao();
myBuilder = theSearchBuilder.getBuilder();

View File

@ -0,0 +1,15 @@
package ca.uhn.fhir.jpa.dao.predicate;
import ca.uhn.fhir.model.api.IQueryParameterType;
import javax.annotation.Nullable;
import javax.persistence.criteria.Predicate;
import java.util.List;
public interface IPredicateBuilder {
@Nullable
Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation);
}

View File

@ -36,72 +36,47 @@ public class PredicateBuilder {
}
void addPredicateCoords(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
// FIXME KHS consolidate these predicate builders (e.g. all these mathods should have the same name)
myPredicateBuilderCoords.addPredicateCoords(theResourceName, theParamName, theNextAnd);
}
private void addPredicateDate(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderDate.addPredicateDate(theResourceName, theParamName, theNextAnd, null);
myPredicateBuilderCoords.addPredicate(theResourceName, theParamName, theNextAnd);
}
Predicate addPredicateDate(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd, SearchFilterParser.CompareOperation theOperation) {
return myPredicateBuilderDate.addPredicateDate(theResourceName, theParamName, theNextAnd, theOperation);
}
private void addPredicateNumber(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderNumber.addPredicateNumber(theResourceName, theParamName, theNextAnd, null);
return myPredicateBuilderDate.addPredicate(theResourceName, theParamName, theNextAnd, theOperation);
}
Predicate addPredicateNumber(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd, SearchFilterParser.CompareOperation theOperation) {
return myPredicateBuilderNumber.addPredicateNumber(theResourceName, theParamName, theNextAnd, theOperation);
}
private void addPredicateQuantity(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderQuantity.addPredicateQuantity(theResourceName, theParamName, theNextAnd, null);
return myPredicateBuilderNumber.addPredicate(theResourceName, theParamName, theNextAnd, theOperation);
}
Predicate addPredicateQuantity(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd, SearchFilterParser.CompareOperation theOperation) {
return myPredicateBuilderQuantity.addPredicateQuantity(theResourceName, theParamName, theNextAnd, theOperation);
}
private Predicate addPredicateReference(String theResourceName, String theParamName, List<? extends IQueryParameterType> theList, RequestDetails theRequest) {
return myPredicateBuilderReference.addPredicateReference(theResourceName, theParamName, theList, null, theRequest);
return myPredicateBuilderQuantity.addPredicate(theResourceName, theParamName, theNextAnd, theOperation);
}
void addPredicateString(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderString.addPredicateString(theResourceName, theParamName, theNextAnd, SearchFilterParser.CompareOperation.sw);
myPredicateBuilderString.addPredicate(theResourceName, theParamName, theNextAnd, SearchFilterParser.CompareOperation.sw);
}
Predicate addPredicateString(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd, SearchFilterParser.CompareOperation theOperation) {
return myPredicateBuilderString.addPredicateString(theResourceName, theParamName, theNextAnd, theOperation);
return myPredicateBuilderString.addPredicate(theResourceName, theParamName, theNextAnd, theOperation);
}
void addPredicateTag(List<List<IQueryParameterType>> theAndOrParams, String theParamName) {
myPredicateBuilderTag.addPredicateTag(theAndOrParams, theParamName);
}
private void addPredicateToken(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderToken.addPredicateToken(theResourceName, theParamName, theNextAnd, null);
}
Predicate addPredicateToken(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd, SearchFilterParser.CompareOperation theOperation) {
return myPredicateBuilderToken.addPredicateToken(theResourceName, theParamName, theNextAnd, theOperation);
}
private void addPredicateUri(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderUri.addPredicateUri(theResourceName, theParamName, theNextAnd, SearchFilterParser.CompareOperation.eq);
return myPredicateBuilderToken.addPredicate(theResourceName, theParamName, theNextAnd, theOperation);
}
Predicate addPredicateUri(String theResourceName, String theName, List<? extends IQueryParameterType> theSingletonList, SearchFilterParser.CompareOperation theOperation) {
return myPredicateBuilderUri.addPredicateUri(theResourceName, theName, theSingletonList, theOperation);
return myPredicateBuilderUri.addPredicate(theResourceName, theName, theSingletonList, theOperation);
}
public void searchForIdsWithAndOr(String theResourceName, String theNextParamName, List<List<IQueryParameterType>> theAndOrParams, RequestDetails theRequest) {
myPredicateBuilderReference.searchForIdsWithAndOr(theResourceName, theNextParamName, theAndOrParams, theRequest);
}
Subquery<Long> createLinkSubquery(boolean theFoundChainMatch, String theParameterName, String theTargetResourceType, ArrayList<IQueryParameterType> theOrValues, RequestDetails theRequest) {
return myPredicateBuilderReference.createLinkSubquery(theFoundChainMatch, theParameterName, theTargetResourceType, theOrValues, theRequest);
Subquery<Long> createLinkSubquery(String theParameterName, String theTargetResourceType, ArrayList<IQueryParameterType> theOrValues, RequestDetails theRequest) {
return myPredicateBuilderReference.createLinkSubquery(true, theParameterName, theTargetResourceType, theOrValues, theRequest);
}
Predicate createResourceLinkPathPredicate(String theTargetResourceType, String theParamReference, Join<ResourceTable, ResourceLink> theJoin) {

View File

@ -28,7 +28,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
@Component
@Scope("prototype")
public class PredicateBuilderCoords extends BasePredicateBuilder {
public class PredicateBuilderCoords extends BasePredicateBuilder implements IPredicateBuilder {
PredicateBuilderCoords(SearchBuilder theSearchBuilder) {
super(theSearchBuilder);
@ -89,8 +89,8 @@ public class PredicateBuilderCoords extends BasePredicateBuilder {
} else if (distanceKm < 0.0) {
throw new IllegalArgumentException("Invalid " + Location.SP_NEAR_DISTANCE + " parameter '" + distanceKm + "' must be >= 0.0");
} else {
Double latitudeDegrees = Double.valueOf(latitudeValue);
Double longitudeDegrees = Double.valueOf(longitudeValue);
double latitudeDegrees = Double.parseDouble(latitudeValue);
double longitudeDegrees = Double.parseDouble(longitudeValue);
Point northPoint = CoordCalculator.findTarget(latitudeDegrees, longitudeDegrees, 0.0, distanceKm);
Point eastPoint = CoordCalculator.findTarget(latitudeDegrees, longitudeDegrees, 90.0, distanceKm);
@ -110,9 +110,11 @@ public class PredicateBuilderCoords extends BasePredicateBuilder {
return combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, theFrom, singleCode);
}
public Predicate addPredicateCoords(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation theOperation) {
Join<ResourceTable, ResourceIndexedSearchParamCoords> join = createJoin(SearchBuilderJoinEnum.COORDS, theParamName);
if (theList.get(0).getMissing() != null) {

View File

@ -23,17 +23,18 @@ import java.util.List;
@Component
@Scope("prototype")
public class PredicateBuilderDate extends BasePredicateBuilder {
public class PredicateBuilderDate extends BasePredicateBuilder implements IPredicateBuilder {
private static final Logger ourLog = LoggerFactory.getLogger(PredicateBuilderDate.class);
PredicateBuilderDate(SearchBuilder theSearchBuilder) {
super(theSearchBuilder);
}
public Predicate addPredicateDate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
Join<ResourceTable, ResourceIndexedSearchParamDate> join = createJoin(SearchBuilderJoinEnum.DATE, theParamName);

View File

@ -20,17 +20,18 @@ import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
@Component
@Scope("prototype")
class PredicateBuilderNumber extends BasePredicateBuilder {
class PredicateBuilderNumber extends BasePredicateBuilder implements IPredicateBuilder {
private static final Logger ourLog = LoggerFactory.getLogger(PredicateBuilderNumber.class);
PredicateBuilderNumber(SearchBuilder theSearchBuilder) {
super(theSearchBuilder);
}
public Predicate addPredicateNumber(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
Join<ResourceTable, ResourceIndexedSearchParamNumber> join = createJoin(SearchBuilderJoinEnum.NUMBER, theParamName);

View File

@ -21,16 +21,18 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
@Component
@Scope("prototype")
class PredicateBuilderQuantity extends BasePredicateBuilder {
class PredicateBuilderQuantity extends BasePredicateBuilder implements IPredicateBuilder {
PredicateBuilderQuantity(SearchBuilder theSearchBuilder) {
super(theSearchBuilder);
}
Predicate addPredicateQuantity(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
Join<ResourceTable, ResourceIndexedSearchParamQuantity> join = createJoin(SearchBuilderJoinEnum.QUANTITY, theParamName);
if (theList.get(0).getMissing() != null) {

View File

@ -59,11 +59,12 @@ class PredicateBuilderReference extends BasePredicateBuilder {
/**
* Add reference predicate to the current search
*/
Predicate addPredicateReference(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation,
RequestDetails theRequest) {
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation,
RequestDetails theRequest) {
assert theParamName.contains(".") == false;
@ -438,7 +439,7 @@ class PredicateBuilderReference extends BasePredicateBuilder {
break;
case REFERENCE:
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
addPredicateReference(theResourceName, theParamName, nextAnd, null, theRequest);
addPredicate(theResourceName, theParamName, nextAnd, null, theRequest);
}
break;
case STRING:
@ -597,7 +598,7 @@ class PredicateBuilderReference extends BasePredicateBuilder {
String chain = (theFilter.getParamPath().getNext() != null) ? theFilter.getParamPath().getNext().toString() : null;
String value = theFilter.getValue();
ReferenceParam referenceParam = new ReferenceParam(resourceType, chain, value);
return addPredicateReference(theResourceName, paramName, Collections.singletonList(referenceParam), operation, theRequest);
return addPredicate(theResourceName, paramName, Collections.singletonList(referenceParam), operation, theRequest);
} else if (typeEnum == RestSearchParameterTypeEnum.QUANTITY) {
return myPredicateBuilder.addPredicateQuantity(theResourceName, theFilter.getParamPath().getName(), Collections.singletonList(new QuantityParam(theFilter.getValue())), theFilter.getOperation());
} else if (typeEnum == RestSearchParameterTypeEnum.COMPOSITE) {
@ -786,7 +787,7 @@ class PredicateBuilderReference extends BasePredicateBuilder {
orValues.addAll(next.getValuesAsQueryTokens());
}
Subquery<Long> subQ = myPredicateBuilder.createLinkSubquery(true, parameterName, targetResourceType, orValues, theRequest);
Subquery<Long> subQ = myPredicateBuilder.createLinkSubquery(parameterName, targetResourceType, orValues, theRequest);
Join<ResourceTable, ResourceLink> join = myQueryRoot.join("myResourceLinksAsTarget", JoinType.LEFT);
Predicate pathPredicate = myPredicateBuilder.createResourceLinkPathPredicate(targetResourceType, paramReference, join);

View File

@ -37,9 +37,10 @@ class PredicateBuilderResourceId extends BasePredicateBuilder {
super(theSearchBuilder);
}
@Nullable
Predicate addPredicateResourceId(List<List<IQueryParameterType>> theValues, String theResourceName, SearchFilterParser.CompareOperation theOperation, RequestDetails theRequest) {
Predicate nextPredicate = createPredicateResourceId(myQueryRoot.getRoot(), theResourceName, theValues, theOperation, theRequest);
Predicate nextPredicate = createPredicate(myQueryRoot.getRoot(), theResourceName, theValues, theOperation, theRequest);
if (nextPredicate != null) {
myQueryRoot.addPredicate(nextPredicate);
@ -50,7 +51,7 @@ class PredicateBuilderResourceId extends BasePredicateBuilder {
}
@Nullable
private Predicate createPredicateResourceId(Root<ResourceTable> theRoot, String theResourceName, List<List<IQueryParameterType>> theValues, SearchFilterParser.CompareOperation theOperation, RequestDetails theRequest) {
private Predicate createPredicate(Root<ResourceTable> theRoot, String theResourceName, List<List<IQueryParameterType>> theValues, SearchFilterParser.CompareOperation theOperation, RequestDetails theRequest) {
Predicate nextPredicate = null;
Set<ResourcePersistentId> allOrPids = null;

View File

@ -22,16 +22,17 @@ import java.util.List;
@Component
@Scope("prototype")
class PredicateBuilderString extends BasePredicateBuilder {
class PredicateBuilderString extends BasePredicateBuilder implements IPredicateBuilder {
PredicateBuilderString(SearchBuilder theSearchBuilder) {
super(theSearchBuilder);
}
Predicate addPredicateString(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
Join<ResourceTable, ResourceIndexedSearchParamString> join = createJoin(SearchBuilderJoinEnum.STRING, theParamName);

View File

@ -61,29 +61,6 @@ class PredicateBuilderTag extends BasePredicateBuilder {
}
}
/*
* We have a parameter of ResourceType?_tag:not=foo This means match resources that don't have the given tag(s)
*/
if (notTags.isEmpty() == false) {
// CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
// CriteriaQuery<Long> cq = builder.createQuery(Long.class);
// Root<ResourceTable> from = cq.from(ResourceTable.class);
// cq.select(from.get("myId").as(Long.class));
//
// Subquery<Long> subQ = cq.subquery(Long.class);
// Root<ResourceTag> subQfrom = subQ.from(ResourceTag.class);
// subQ.select(subQfrom.get("myResourceId").as(Long.class));
// Predicate subQname = builder.equal(subQfrom.get("myParamName"), theParamName);
// Predicate subQtype = builder.equal(subQfrom.get("myResourceType"), myResourceName);
// subQ.where(builder.and(subQtype, subQname));
//
// List<Predicate> predicates = new ArrayList<Predicate>();
// predicates.add(builder.not(builder.in(from.get("myId")).value(subQ)));
// predicates.add(builder.equal(from.get("myResourceType"), myResourceName));
// predicates.add(builder.isNull(from.get("myDeleted")));
// createPredicateResourceId(builder, cq, predicates, from.get("myId").as(Long.class));
}
for (List<? extends IQueryParameterType> nextAndParams : theList) {
boolean haveTags = false;
for (IQueryParameterType nextParamUncasted : nextAndParams) {

View File

@ -31,7 +31,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
@Component
@Scope("prototype")
class PredicateBuilderToken extends BasePredicateBuilder {
class PredicateBuilderToken extends BasePredicateBuilder implements IPredicateBuilder {
@Autowired
private ITermReadSvc myTerminologySvc;
@Autowired
@ -43,10 +43,11 @@ class PredicateBuilderToken extends BasePredicateBuilder {
myPredicateBuilder = thePredicateBuilder;
}
Predicate addPredicateToken(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
if (theList.get(0).getMissing() != null) {
Join<ResourceTable, ResourceIndexedSearchParamToken> join = createJoin(SearchBuilderJoinEnum.TOKEN, theParamName);
@ -178,19 +179,19 @@ class PredicateBuilderToken extends BasePredicateBuilder {
// System only
List<VersionIndependentConcept> systemOnlyCodes = sortedCodesList.stream().filter(t -> isBlank(t.getCode())).collect(Collectors.toList());
if (!systemOnlyCodes.isEmpty()) {
retVal.add(addPredicateToken(theResourceName, theParamName, theBuilder, theFrom, systemOnlyCodes, modifier, SearchBuilderTokenModeEnum.SYSTEM_ONLY));
retVal.add(addPredicate(theResourceName, theParamName, theBuilder, theFrom, systemOnlyCodes, modifier, SearchBuilderTokenModeEnum.SYSTEM_ONLY));
}
// Code only
List<VersionIndependentConcept> codeOnlyCodes = sortedCodesList.stream().filter(t -> t.getSystem() == null).collect(Collectors.toList());
if (!codeOnlyCodes.isEmpty()) {
retVal.add(addPredicateToken(theResourceName, theParamName, theBuilder, theFrom, codeOnlyCodes, modifier, SearchBuilderTokenModeEnum.VALUE_ONLY));
retVal.add(addPredicate(theResourceName, theParamName, theBuilder, theFrom, codeOnlyCodes, modifier, SearchBuilderTokenModeEnum.VALUE_ONLY));
}
// System and code
List<VersionIndependentConcept> systemAndCodeCodes = sortedCodesList.stream().filter(t -> isNotBlank(t.getCode()) && t.getSystem() != null).collect(Collectors.toList());
if (!systemAndCodeCodes.isEmpty()) {
retVal.add(addPredicateToken(theResourceName, theParamName, theBuilder, theFrom, systemAndCodeCodes, modifier, SearchBuilderTokenModeEnum.SYSTEM_AND_VALUE));
retVal.add(addPredicate(theResourceName, theParamName, theBuilder, theFrom, systemAndCodeCodes, modifier, SearchBuilderTokenModeEnum.SYSTEM_AND_VALUE));
}
return retVal;
@ -240,7 +241,7 @@ class PredicateBuilderToken extends BasePredicateBuilder {
}
}
private Predicate addPredicateToken(String theResourceName, String theParamName, CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamToken> theFrom, List<VersionIndependentConcept> theTokens, TokenParamModifier theModifier, SearchBuilderTokenModeEnum theTokenMode) {
private Predicate addPredicate(String theResourceName, String theParamName, CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamToken> theFrom, List<VersionIndependentConcept> theTokens, TokenParamModifier theModifier, SearchBuilderTokenModeEnum theTokenMode) {
if (myDontUseHashesForSearch) {
final Path<String> systemExpression = theFrom.get("mySystem");
final Path<String> valueExpression = theFrom.get("myValue");

View File

@ -22,7 +22,7 @@ import java.util.List;
@Component
@Scope("prototype")
class PredicateBuilderUri extends BasePredicateBuilder {
class PredicateBuilderUri extends BasePredicateBuilder implements IPredicateBuilder {
private static final Logger ourLog = LoggerFactory.getLogger(PredicateBuilderUri.class);
@Autowired
private IResourceIndexedSearchParamUriDao myResourceIndexedSearchParamUriDao;
@ -31,10 +31,11 @@ class PredicateBuilderUri extends BasePredicateBuilder {
super(theSearchBuilder);
}
Predicate addPredicateUri(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
@Override
public Predicate addPredicate(String theResourceName,
String theParamName,
List<? extends IQueryParameterType> theList,
SearchFilterParser.CompareOperation operation) {
Join<ResourceTable, ResourceIndexedSearchParamUri> join = createJoin(SearchBuilderJoinEnum.URI, theParamName);