use of org.entando.entando.web.common.model.FilterOperator in project entando-core by entando.
the class FilterUtils method filterBoolean.
public static boolean filterBoolean(Filter filter, boolean value) {
FilterOperator operator = getFilterOperator(filter);
boolean result = false;
for (boolean filterValue : getTypedAllowedValues(filter, v -> Boolean.parseBoolean(v.toLowerCase()))) {
switch(operator) {
case EQUAL:
case LIKE:
result |= value == filterValue;
break;
case NOT_EQUAL:
result |= value != filterValue;
break;
default:
throw new UnsupportedOperationException(getUnsupportedOperatorMessage(filter));
}
}
return result;
}
use of org.entando.entando.web.common.model.FilterOperator in project entando-core by entando.
the class FilterUtils method filterDouble.
private static boolean filterDouble(Filter filter, List<Double> filterValues, double value) {
FilterOperator operator = getFilterOperator(filter);
boolean result = false;
for (double filterValue : filterValues) {
switch(operator) {
case EQUAL:
case LIKE:
result |= value == filterValue;
break;
case NOT_EQUAL:
result |= value != filterValue;
break;
case GREATER:
result |= value >= filterValue;
break;
case LOWER:
result |= value <= filterValue;
break;
default:
throw new UnsupportedOperationException(getUnsupportedOperatorMessage(filter));
}
}
return result;
}
use of org.entando.entando.web.common.model.FilterOperator in project entando-core by entando.
the class AbstractPaginationValidator method validateRestListRequest.
public void validateRestListRequest(RestListRequest listRequest, Class<?> type) {
this.checkDefaultSortField(listRequest);
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(listRequest, "listRequest");
if (listRequest.getPage() < 1) {
bindingResult.reject(ERRCODE_PAGE_INVALID, new Object[] {}, "pagination.page.invalid");
throw new ValidationGenericException(bindingResult);
}
if (listRequest.getPageSize() < 0) {
bindingResult.reject(ERRCODE_PAGE_SIZE_INVALID, new Object[] {}, "pagination.page.size.invalid");
} else if (listRequest.getPage() > 1 && listRequest.getPageSize() == 0) {
bindingResult.reject(ERRCODE_NO_ITEM_ON_PAGE, new String[] { String.valueOf(listRequest.getPage()) }, "pagination.item.empty");
throw new ResourceNotFoundException(bindingResult);
}
if (null == type) {
return;
}
if (!isValidField(listRequest.getSort(), type)) {
bindingResult.reject(ERRCODE_SORTING_INVALID, new Object[] { listRequest.getSort() }, "sorting.sort.invalid");
}
if (listRequest.getFilters() != null) {
List<String> attributes = Arrays.asList(listRequest.getFilters()).stream().filter(filter -> filter.getEntityAttr() == null).map(filter -> filter.getAttributeName()).filter(attr -> !isValidField(attr, type)).collect(Collectors.toList());
if (attributes.size() > 0) {
bindingResult.reject(ERRCODE_FILTERING_ATTR_INVALID, new Object[] { attributes.get(0) }, "filtering.filter.attr.name.invalid");
}
if (Arrays.stream(FilterOperator.values()).map(FilterOperator::getValue).noneMatch(op -> Arrays.stream(listRequest.getFilters()).map(Filter::getOperator).anyMatch(op::equals))) {
bindingResult.reject(ERRCODE_FILTERING_OP_INVALID, new Object[] {}, "filtering.filter.operation.invalid");
}
Arrays.stream(listRequest.getFilters()).filter(f -> getDateFilterKeys().contains(f.getAttribute())).forEach(f -> {
try {
SimpleDateFormat sdf = new SimpleDateFormat(SystemConstants.API_DATE_FORMAT);
sdf.parse(f.getValue());
} catch (ParseException ex) {
bindingResult.reject(ERRCODE_FILTERING_OP_INVALID, new Object[] { f.getValue(), f.getAttribute() }, "filtering.filter.date.format.invalid");
}
});
}
if (!Arrays.asList(directions).contains(listRequest.getDirection())) {
bindingResult.reject(ERRCODE_DIRECTION_INVALID, new Object[] {}, "sorting.direction.invalid");
}
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
}
use of org.entando.entando.web.common.model.FilterOperator in project entando-core by entando.
the class FilterUtils method filterString.
public static boolean filterString(Filter filter, String value) {
FilterOperator operator = getFilterOperator(filter);
if (value == null) {
return false;
}
boolean result = false;
for (String filterValue : getFilterValues(filter)) {
switch(operator) {
case EQUAL:
result |= value.equals(filterValue);
break;
case NOT_EQUAL:
result |= !value.equals(filterValue);
break;
case LIKE:
result |= value.toLowerCase().contains(filterValue.toLowerCase());
break;
case GREATER:
result |= value.compareTo(filterValue) >= 0;
break;
case LOWER:
result |= value.compareTo(filterValue) <= 0;
break;
default:
throw new UnsupportedOperationException(getUnsupportedOperatorMessage(filter));
}
}
return result;
}
Aggregations