From 571386046d853f81a6a13c4a39cc70da93baaabd Mon Sep 17 00:00:00 2001 From: Joern Muehlencord Date: Thu, 24 Oct 2019 11:12:39 +0100 Subject: [PATCH] started to add string filter support --- .../shared/db/CommonAbstractController.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java b/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java index 80cdff2..65981cd 100644 --- a/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java +++ b/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java @@ -430,8 +430,8 @@ public abstract class CommonAbstractController { } if (currentFilter.getFieldName() == null) { throw new ControllerException(ControllerException.INTERNAL_ERROR, "Fieldname must not be null"); - } - + } + Path path = getPathElement(root, currentFilter); if (currentFilter.getSearchValue() == null) { @@ -442,16 +442,33 @@ public abstract class CommonAbstractController { break; case NOT_EQUAL: predicate = cb.isNotNull(path); - break; default: throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + " not supported for searchValue null"); } 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 { - throw new ControllerException (ControllerException.INTERNAL_ERROR, "Not yet implemented"); + throw new ControllerException(ControllerException.INTERNAL_ERROR, "Not yet implemented"); } } // for all filters - + return returnCondition; }