added basic or clause support
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@ -7,6 +7,7 @@ nbdist/
|
|||||||
nbactions.xml
|
nbactions.xml
|
||||||
**/nb-configuration.xml
|
**/nb-configuration.xml
|
||||||
.nb-gradle/
|
.nb-gradle/
|
||||||
|
**/faces-config.NavData
|
||||||
|
|
||||||
# ---> Eclipse
|
# ---> Eclipse
|
||||||
.project
|
.project
|
||||||
@ -24,6 +25,11 @@ dependency-reduced-pom.xml
|
|||||||
buildNumber.properties
|
buildNumber.properties
|
||||||
.mvn/timing.properties
|
.mvn/timing.properties
|
||||||
|
|
||||||
|
|
||||||
|
# --> Idea
|
||||||
|
**/.idea
|
||||||
|
**/*.iml
|
||||||
|
|
||||||
# ---> Java
|
# ---> Java
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
@ -178,6 +184,8 @@ sympy-plots-for-*.tex/
|
|||||||
|
|
||||||
# localized versions of JBOSS command line interface
|
# localized versions of JBOSS command line interface
|
||||||
*.local.cli
|
*.local.cli
|
||||||
/source/office-parent/office-web/faces-config.NavData
|
|
||||||
|
|
||||||
|
## project specific
|
||||||
/source/vvh-access-import/src/main/resources/hibernate.cfg.xml
|
/source/vvh-access-import/src/main/resources/hibernate.cfg.xml
|
||||||
/source/office-parent/office-entities/src/main/resources/META-INF/persistence.xml
|
/source/office-parent/office-entities/src/main/resources/META-INF/persistence.xml
|
||||||
|
|||||||
@ -203,8 +203,7 @@ public abstract class CommonAbstractController {
|
|||||||
* updates the audit field of the entity class.
|
* updates the audit field of the entity class.
|
||||||
*
|
*
|
||||||
* @param audit the audit to apply
|
* @param audit the audit to apply
|
||||||
* @param onCreate specifies, whether the the update should be applied for a new entity or not. If yes, then also the createdBy /createdOn fields
|
* @param onCreate specifies, whether the the update should be applied for a new entity or not. If yes, then also the createdBy /createdOn fields are updated. Otherwise these fields are skipped.
|
||||||
* are updated. Otherwise these fields are skipped.
|
|
||||||
* @param changedBy the username to apply
|
* @param changedBy the username to apply
|
||||||
* @return an updated audit object to use for the updated entity.
|
* @return an updated audit object to use for the updated entity.
|
||||||
* @throws ControllerException if the audit object cannot be updated
|
* @throws ControllerException if the audit object cannot be updated
|
||||||
@ -334,8 +333,7 @@ public abstract class CommonAbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes an entity from the database. If the entity implements the {@link EndDateable} interface, the entity is not deleted but marked as deleted
|
* Deletes an entity from the database. If the entity implements the {@link EndDateable} interface, the entity is not deleted but marked as deleted (end date set).
|
||||||
* (end date set).
|
|
||||||
*
|
*
|
||||||
* @param <T> the type of the entity to handle
|
* @param <T> the type of the entity to handle
|
||||||
* @param entity the entity to delete
|
* @param entity the entity to delete
|
||||||
@ -423,8 +421,7 @@ public abstract class CommonAbstractController {
|
|||||||
* @param cb the criteria builder to use
|
* @param cb the criteria builder to use
|
||||||
* @param root the root of the object to search for
|
* @param root the root of the object to search for
|
||||||
* @param filters the filters to apply
|
* @param filters the filters to apply
|
||||||
* @param include if set to true, the filter is used as include filter (equals, in). If set to false, the filter is inverted and used as exclude
|
* @param include if set to true, the filter is used as include filter (equals, in). If set to false, the filter is inverted and used as exclude filter (not equals, not in etc)
|
||||||
* filter (not equals, not in etc)
|
|
||||||
* @return the created filter condition
|
* @return the created filter condition
|
||||||
*/
|
*/
|
||||||
protected <T extends Serializable> Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
|
protected <T extends Serializable> Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
|
||||||
@ -559,6 +556,7 @@ public abstract class CommonAbstractController {
|
|||||||
}
|
}
|
||||||
returnCondition = addFilterCondition(cb, returnCondition, predicate);
|
returnCondition = addFilterCondition(cb, returnCondition, predicate);
|
||||||
} else if (currentFilter.getSearchValue() instanceof Date) {
|
} else if (currentFilter.getSearchValue() instanceof Date) {
|
||||||
|
// TODO - support Date, LocaleDate, LocalTime, LocalDateTime, ZoneDateTime
|
||||||
Date searchValue = (Date) currentFilter.getSearchValue();
|
Date searchValue = (Date) currentFilter.getSearchValue();
|
||||||
Predicate predicate;
|
Predicate predicate;
|
||||||
Path<Date> datePath = root.<Date>get(currentFilter.getFieldName());
|
Path<Date> datePath = root.<Date>get(currentFilter.getFieldName());
|
||||||
@ -615,6 +613,20 @@ public abstract class CommonAbstractController {
|
|||||||
throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + "not support for searchValue " + searchValue);
|
throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + "not support for searchValue " + searchValue);
|
||||||
}
|
}
|
||||||
returnCondition = addFilterCondition(cb, returnCondition, predicate);
|
returnCondition = addFilterCondition(cb, returnCondition, predicate);
|
||||||
|
} else if (currentFilter.getSearchValue() instanceof List) {
|
||||||
|
List<Object> searchValues = (List) currentFilter.getSearchValue();
|
||||||
|
Predicate predicate = null;
|
||||||
|
if (!searchValues.isEmpty()) {
|
||||||
|
for (Object obj : searchValues) {
|
||||||
|
SearchFilter sf = new DefaultSearchFilter(currentFilter.getFieldName(), currentFilter.getComparator(), obj);
|
||||||
|
List<SearchFilter> localFilterList = new ArrayList<>();
|
||||||
|
localFilterList.add(sf);
|
||||||
|
Predicate localPredicate = getFilterCondition(null, cb, root, localFilterList);
|
||||||
|
predicate = orFilterCondition(cb, predicate, localPredicate);
|
||||||
|
}
|
||||||
|
returnCondition = addFilterCondition(cb, returnCondition, predicate);
|
||||||
|
}
|
||||||
|
// Path
|
||||||
} else {
|
} else {
|
||||||
throw new ControllerException(ControllerException.INTERNAL_ERROR, "Filter for " + currentFilter.getSearchValue().getClass().getSimpleName() + " not yet implemented");
|
throw new ControllerException(ControllerException.INTERNAL_ERROR, "Filter for " + currentFilter.getSearchValue().getClass().getSimpleName() + " not yet implemented");
|
||||||
}
|
}
|
||||||
@ -643,6 +655,26 @@ public abstract class CommonAbstractController {
|
|||||||
return filterCondition;
|
return filterCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a filter condition to an existing condition
|
||||||
|
*
|
||||||
|
* @param cb the builder to use
|
||||||
|
* @param filterCondition the existing filter condition
|
||||||
|
* @param orCondition the condition to add to the existing condition.
|
||||||
|
* @return an updated filter condition.
|
||||||
|
*/
|
||||||
|
protected Predicate orFilterCondition(CriteriaBuilder cb, Predicate filterCondition, Predicate orCondition) {
|
||||||
|
if (orCondition == null) {
|
||||||
|
return filterCondition;
|
||||||
|
}
|
||||||
|
if (filterCondition == null) {
|
||||||
|
filterCondition = orCondition;
|
||||||
|
} else {
|
||||||
|
filterCondition = cb.or(filterCondition, orCondition);
|
||||||
|
}
|
||||||
|
return filterCondition;
|
||||||
|
}
|
||||||
|
|
||||||
private <T extends Serializable> Path<String> getPathElement(Root<T> root, Map.Entry<String, Object> filter) {
|
private <T extends Serializable> Path<String> getPathElement(Root<T> root, Map.Entry<String, Object> filter) {
|
||||||
String[] pathElements = StringUtils.split(filter.getKey(), '.');
|
String[] pathElements = StringUtils.split(filter.getKey(), '.');
|
||||||
Path<String> path = null;
|
Path<String> path = null;
|
||||||
@ -670,8 +702,7 @@ public abstract class CommonAbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns null, if the list is empty or null itself.Returns the one element if there is exactly one element in the list. Otherwise an exception is
|
* returns null, if the list is empty or null itself.Returns the one element if there is exactly one element in the list. Otherwise an exception is thrown
|
||||||
* thrown
|
|
||||||
*
|
*
|
||||||
* @param <T> the type of the entity to handle
|
* @param <T> the type of the entity to handle
|
||||||
* @param entityList the list to validate
|
* @param entityList the list to validate
|
||||||
|
|||||||
@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.db;
|
package de.muehlencord.shared.db;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||||
@ -24,11 +28,22 @@ public class DefaultSearchFilter implements SearchFilter {
|
|||||||
private final String fieldName;
|
private final String fieldName;
|
||||||
private final Comparator comparator;
|
private final Comparator comparator;
|
||||||
private final Object searchValue;
|
private final Object searchValue;
|
||||||
|
private final Operator operator;
|
||||||
|
|
||||||
public DefaultSearchFilter(String fieldName, Comparator comparator, Object fieldValue) {
|
public DefaultSearchFilter(String fieldName, Comparator comparator, Object fieldValue) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
this.comparator = comparator;
|
this.comparator = comparator;
|
||||||
this.searchValue = fieldValue;
|
this.searchValue = fieldValue;
|
||||||
|
this.operator = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultSearchFilter(String fieldName, Comparator comparator, Operator operator, Object... fieldValue) {
|
||||||
|
this.fieldName = fieldName;
|
||||||
|
this.comparator = comparator;
|
||||||
|
List<Object> searchValues = new ArrayList();
|
||||||
|
searchValues.addAll(Arrays.asList(fieldValue));
|
||||||
|
this.searchValue = searchValues;
|
||||||
|
this.operator = operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,8 +61,8 @@ public class DefaultSearchFilter implements SearchFilter {
|
|||||||
return searchValue;
|
return searchValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Operator getOperator() {
|
||||||
|
return operator;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
db/src/main/java/de/muehlencord/shared/db/Operator.java
Normal file
26
db/src/main/java/de/muehlencord/shared/db/Operator.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package de.muehlencord.shared.db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||||
|
*/
|
||||||
|
public enum Operator {
|
||||||
|
|
||||||
|
AND, OR;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user