use of eu.bcvsolutions.idm.core.api.exception.FilterNotSupportedException in project CzechIdMng by bcvsolutions.
the class DefaultFilterManager method toPredicates.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Predicate> toPredicates(Root<? extends BaseEntity> root, CriteriaQuery<?> query, CriteriaBuilder builder, DataFilter filter) {
List<Predicate> predicates = new ArrayList<>();
if (filter == null) {
// empty filter - builders cannot be found
return predicates;
}
//
Class<? extends BaseEntity> entityClass = root.getJavaType();
Set<String> filterProperties = filter.getData().keySet();
for (String filterProperty : filterProperties) {
FilterKey key = new FilterKey(entityClass, filterProperty);
FilterBuilder filterBuilder = getBuilder(key);
//
if (filterBuilder == null) {
if (ignoredFilterProperties.contains(filterProperty) || filterProperty.startsWith(String.format("%s:", CoreModule.MODULE_ID))) {
LOG.trace("Pageable or internal property [{}] will be ignored by filters.", filterProperty);
continue;
}
if (CollectionUtils.isEmpty(filter.getData().get(filterProperty))) {
LOG.trace("Filter property [{}] is empty and will be ignored by filters.", filterProperty);
continue;
}
// check property is processed by service
if (// by service definition
!getRegisteredServiceFilters().containsKey(key) && !getRegisteredFilters(entityClass, filter.getClass()).containsKey(key)) {
// by filter instance
FilterNotSupportedException ex = new FilterNotSupportedException(key);
//
if (configurationService.getBooleanValue(PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, DEFAULT_CHECK_SUPPORTED_FILTER_ENABLED)) {
// throw exception otherwise => unrecognized filter is not supported
throw ex;
} else {
// log exception only
ExceptionUtils.log(LOG, ex);
}
}
LOG.trace("Filter property [{}] for entity [{}] will by processed directly by service predicates.", filterProperty, entityClass.getSimpleName());
continue;
}
Predicate predicate = filterBuilder.getPredicate(root, query, builder, filter);
if (predicate != null) {
predicates.add(predicate);
}
}
//
return predicates;
}
Aggregations