Minor refactoring for readability

This commit is contained in:
Tadgh 2020-03-06 14:22:31 -08:00
parent b299d0b63f
commit aca4bcfaad
2 changed files with 30 additions and 36 deletions

View File

@ -166,15 +166,8 @@ public class SearchBuilder implements ISearchBuilder {
Dstu3DistanceHelper.setNearDistance(myResourceType, theParams);
}
/*
* Check if there is a unique key associated with the set
* of parameters passed in
*/
boolean couldBeEligibleForCompositeUniqueSpProcessing =
myDaoConfig.isUniqueIndexesEnabled() &&
myParams.getEverythingMode() == null &&
myParams.isAllParametersHaveNoModifier();
if (couldBeEligibleForCompositeUniqueSpProcessing) {
// Attempt to lookup via composite unique key.
if (isCompositeUniqueSpCandidate()) {
attemptCompositeUniqueSpProcessing(theParams, theRequest);
}
@ -187,6 +180,16 @@ public class SearchBuilder implements ISearchBuilder {
}
/**
* A search is a candidate for Composite Unique SP if unique indexes are enabled, we are not in
* @return
*/
private boolean isCompositeUniqueSpCandidate() {
return myDaoConfig.isUniqueIndexesEnabled() &&
myParams.getEverythingMode() == null &&
myParams.isAllParametersHaveNoModifier();
}
@Override
public Iterator<Long> createCountQuery(SearchParameterMap theParams, String theSearchUuid, RequestDetails theRequest) {
init(theParams, theSearchUuid);

View File

@ -18,6 +18,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ -455,45 +456,35 @@ public class SearchParameterMap implements Serializable {
return b.toString();
}
public void clean() {
for (Map.Entry<String, List<List<IQueryParameterType>>> nextParamEntry : this.entrySet()) {
String nextParamName = nextParamEntry.getKey();
List<List<IQueryParameterType>> andOrParams = nextParamEntry.getValue();
clean(nextParamName, andOrParams);
cleanParameter(nextParamName, andOrParams);
}
}
/*
* Filter out
* Given a particular named parameter, e.g. `name`, iterate over AndOrParams and remove any which are empty.
*/
private void clean(String theParamName, List<List<IQueryParameterType>> theAndOrParams) {
for (int andListIdx = 0; andListIdx < theAndOrParams.size(); andListIdx++) {
List<? extends IQueryParameterType> nextOrList = theAndOrParams.get(andListIdx);
private void cleanParameter(String theParamName, List<List<IQueryParameterType>> theAndOrParams) {
theAndOrParams
.forEach(
orList -> {
List<IQueryParameterType> emptyParameters = orList.stream()
.filter(nextOr -> nextOr.getMissing() == null)
.filter(nextOr -> nextOr instanceof QuantityParam)
.filter(nextOr -> isBlank(((QuantityParam) nextOr).getValueAsString()))
.collect(Collectors.toList());
for (int orListIdx = 0; orListIdx < nextOrList.size(); orListIdx++) {
IQueryParameterType nextOr = nextOrList.get(orListIdx);
boolean hasNoValue = false;
if (nextOr.getMissing() != null) {
continue;
}
if (nextOr instanceof QuantityParam) {
if (isBlank(((QuantityParam) nextOr).getValueAsString())) {
hasNoValue = true;
}
}
if (hasNoValue) {
ourLog.debug("Ignoring empty parameter: {}", theParamName);
nextOrList.remove(orListIdx);
orListIdx--;
orList.removeAll(emptyParameters);
}
}
if (nextOrList.isEmpty()) {
theAndOrParams.remove(andListIdx);
andListIdx--;
}
}
);
theAndOrParams.removeIf(List::isEmpty);
}
public void setNearDistanceParam(QuantityParam theQuantityParam) {