started to add string filter support

This commit is contained in:
2019-10-24 11:12:39 +01:00
parent 103b8348d0
commit 571386046d

View File

@ -430,8 +430,8 @@ public abstract class CommonAbstractController {
} }
if (currentFilter.getFieldName() == null) { if (currentFilter.getFieldName() == null) {
throw new ControllerException(ControllerException.INTERNAL_ERROR, "Fieldname must not be null"); throw new ControllerException(ControllerException.INTERNAL_ERROR, "Fieldname must not be null");
} }
Path<String> path = getPathElement(root, currentFilter); Path<String> path = getPathElement(root, currentFilter);
if (currentFilter.getSearchValue() == null) { if (currentFilter.getSearchValue() == null) {
@ -442,16 +442,33 @@ public abstract class CommonAbstractController {
break; break;
case NOT_EQUAL: case NOT_EQUAL:
predicate = cb.isNotNull(path); predicate = cb.isNotNull(path);
break;
default: default:
throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + " not supported for searchValue null"); throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + " not supported for searchValue null");
} }
returnCondition = addFilterCondition(cb, returnCondition, predicate); returnCondition = addFilterCondition(cb, returnCondition, predicate);
} else if (currentFilter.getSearchValue() instanceof String) {
String searchValue = (String) currentFilter.getSearchValue();
String wildCard = "%";
Predicate predicate;
switch (currentFilter.getComparator()) {
case EQUAL:
predicate = cb.equal(path, searchValue);
break;
case NOT_EQUAL:
predicate = cb.notEqual(path, searchValue);
break;
case CONTAINS:
String likeValue = wildCard + searchValue.toUpperCase(Locale.US) + wildCard;
predicate = cb.like(cb.upper(path), likeValue, '\\');
break;
default:
throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + "not support for searchValue " + searchValue);
}
} else { } else {
throw new ControllerException (ControllerException.INTERNAL_ERROR, "Not yet implemented"); throw new ControllerException(ControllerException.INTERNAL_ERROR, "Not yet implemented");
} }
} // for all filters } // for all filters
return returnCondition; return returnCondition;
} }