use of org.jowidgets.cap.common.api.filter.IFilter in project jo-client-platform by jo-source.
the class AbstractSimpleBeanReader method read.
@Override
public final List<BEAN_TYPE> read(final List<? extends IBeanKey> parentBeans, final IFilter filter, final List<? extends ISort> sortedProperties, final int firstRow, final int maxRows, final PARAM_TYPE parameter, final IExecutionCallback executionCallback) {
final IFilter decoratedFilter = getDecoratedFilter(filter);
if (decoratedFilter == null && (sortedProperties == null || sortedProperties.size() == 0)) {
return getBeans(parentBeans, parameter, firstRow, maxRows, executionCallback);
} else {
final List<BEAN_TYPE> beans = getBeans(parentBeans, parameter, firstRow, maxRows, executionCallback);
ArrayList<IBeanDto> result = createBeanDtos(beans, executionCallback);
if (decoratedFilter != null) {
result = CapServiceToolkit.beanDtoCollectionFilter().filter(result, decoratedFilter, executionCallback);
}
if (sortedProperties != null && sortedProperties.size() > 0) {
result = collectionSorter.sort(result, sortedProperties, executionCallback);
}
if (result.size() >= firstRow) {
return createBeansSubList(result, firstRow, Math.min(firstRow + maxRows, result.size()), executionCallback);
} else {
return Collections.emptyList();
}
}
}
use of org.jowidgets.cap.common.api.filter.IFilter in project jo-client-platform by jo-source.
the class BooleanFilterImpl method toString.
@Override
public String toString() {
final StringBuilder result = new StringBuilder();
if (filters.size() > 0) {
int effectiveSize = 0;
if (inverted) {
result.append("not (");
}
for (final IFilter filter : filters) {
result.append('(');
result.append(filter.toString());
result.append(')');
effectiveSize = result.length();
result.append(' ');
result.append(operator.getLabel());
result.append(' ');
}
result.setLength(effectiveSize);
if (inverted) {
result.append(')');
}
}
return result.toString();
}
use of org.jowidgets.cap.common.api.filter.IFilter in project jo-client-platform by jo-source.
the class FilterUtil method hasLessOrEqualResults.
public static IMaybe<Boolean> hasLessOrEqualResults(final IBooleanFilter oldFilter, final IBooleanFilter newFilter) {
Assert.paramNotNull(oldFilter, "oldFilter");
Assert.paramNotNull(newFilter, "newFilter");
if (oldFilter.equals(newFilter)) {
return new Some<Boolean>(Boolean.TRUE);
} else if (oldFilter.getOperator() == BooleanOperator.OR && newFilter.getOperator() == BooleanOperator.OR) {
final HashSet<IFilter> oldFilterChildren = new HashSet<IFilter>(oldFilter.getFilters());
final HashSet<IFilter> newFilterChildren = new HashSet<IFilter>(newFilter.getFilters());
// test if all conditions of the new filter are part of the old filter
for (final IFilter newFilterChild : newFilter.getFilters()) {
if (oldFilterChildren.remove(newFilterChild)) {
newFilterChildren.remove(newFilterChild);
}
}
if (newFilterChildren.size() == 0) {
// all conditions of the new filter are part of the old filter
return new Some<Boolean>(Boolean.TRUE);
} else if (oldFilterChildren.size() == 1 && newFilterChildren.size() == 1) {
// they differ by one condition, so check this condition
return (hasLessOrEqualResults(oldFilterChildren.iterator().next(), newFilterChildren.iterator().next()));
} else {
// TODO add more complex tests here
return Nothing.getInstance();
}
} else if (oldFilter.getOperator() == BooleanOperator.AND && newFilter.getOperator() == BooleanOperator.AND) {
final HashSet<IFilter> oldFilterChildren = new HashSet<IFilter>(oldFilter.getFilters());
final HashSet<IFilter> newFilterChildren = new HashSet<IFilter>(newFilter.getFilters());
// test if all conditions of the old filter are part of the new filter
for (final IFilter newFilterChild : newFilter.getFilters()) {
if (newFilterChildren.remove(newFilterChild)) {
oldFilterChildren.remove(newFilterChild);
}
}
if (oldFilterChildren.size() == 0) {
// all conditions of the old filter are part of the new filter
return new Some<Boolean>(Boolean.TRUE);
} else if (oldFilterChildren.size() == 1 && newFilterChildren.size() == 1) {
// they differ by one condition, so check this condition
return (hasLessOrEqualResults(oldFilterChildren.iterator().next(), newFilterChildren.iterator().next()));
} else {
// TODO add more complex tests here
return Nothing.getInstance();
}
} else {
// if operators changed, it is not predictable
return Nothing.getInstance();
}
}
use of org.jowidgets.cap.common.api.filter.IFilter in project jo-client-platform by jo-source.
the class CriteriaQueryCreator method fillQuery.
@SuppressWarnings("unchecked")
private Root<?> fillQuery(final CriteriaQuery<?> query, final CriteriaBuilder criteriaBuilder, final Class<?> persistenceClass, final List<? extends IBeanKey> parentBeanKeys, final IFilter filter, final PARAM_TYPE parameter) {
final Root<?> bean = query.from(persistenceClass);
final List<Predicate> predicates = new LinkedList<Predicate>();
final List<Object> parentIds = new LinkedList<Object>();
if (parentBeanKeys != null) {
for (final IBeanKey parentBeanKey : parentBeanKeys) {
parentIds.add(parentBeanKey.getId());
}
}
for (final IPredicateCreator<PARAM_TYPE> predicateCreator : predicateCreators) {
final Predicate predicate = predicateCreator.createPredicate(criteriaBuilder, bean, query, (List<IBeanKey>) parentBeanKeys, parentIds, parameter);
if (predicate != null) {
predicates.add(predicate);
}
}
for (final IFilter customFilter : filters) {
predicates.add(createFilterPredicate(criteriaBuilder, bean, query, customFilter, parameter));
}
if (filter != null) {
predicates.add(createFilterPredicate(criteriaBuilder, bean, query, filter, parameter));
}
query.where(predicates.toArray(new Predicate[predicates.size()]));
return bean;
}
use of org.jowidgets.cap.common.api.filter.IFilter in project jo-client-platform by jo-source.
the class UiFilterFactoryImpl method convert.
@Override
public IFilter convert(final IUiFilter uiFilter) {
if (uiFilter instanceof IUiBooleanFilter) {
final IUiBooleanFilter uiBooleanFilter = (IUiBooleanFilter) uiFilter;
final List<IFilter> filters = new LinkedList<IFilter>();
for (final IUiFilter uiF : uiBooleanFilter.getFilters()) {
filters.add(convert(uiF));
}
return CapCommonToolkit.filterFactory().booleanFilter(uiBooleanFilter.getOperator(), filters);
} else if (uiFilter instanceof IUiArithmeticFilter<?>) {
final IUiArithmeticFilter<?> uiArithmeticFilter = (IUiArithmeticFilter<?>) uiFilter;
final IArithmeticFilterBuilder arithmeticFilterBuilder = CapCommonToolkit.filterFactory().arithmeticFilterBuilder();
arithmeticFilterBuilder.setInverted(uiArithmeticFilter.isInverted());
arithmeticFilterBuilder.setOperator(uiArithmeticFilter.getOperator());
arithmeticFilterBuilder.setParameters(uiArithmeticFilter.getParameters());
arithmeticFilterBuilder.setPropertyName(uiArithmeticFilter.getPropertyName());
return arithmeticFilterBuilder.build();
} else if (uiFilter instanceof IUiArithmeticPropertyFilter<?>) {
final IUiArithmeticPropertyFilter<?> uiArithmeticPropertyFilter = (IUiArithmeticPropertyFilter<?>) uiFilter;
final IArithmeticPropertyFilterBuilder arithmeticPropertyFilterBuilder = CapCommonToolkit.filterFactory().arithmeticPropertyFilterBuilder();
arithmeticPropertyFilterBuilder.setInverted(uiArithmeticPropertyFilter.isInverted());
arithmeticPropertyFilterBuilder.setPropertyName(uiArithmeticPropertyFilter.getPropertyName());
arithmeticPropertyFilterBuilder.setOperator(uiArithmeticPropertyFilter.getOperator());
arithmeticPropertyFilterBuilder.setRightHandPropertyNames(uiArithmeticPropertyFilter.getRightHandPropertyNames());
return arithmeticPropertyFilterBuilder.build();
} else if (uiFilter instanceof IUiCustomFilter<?>) {
final IUiCustomFilter<?> uiCustomFilter = (IUiCustomFilter<?>) uiFilter;
final ICustomFilterBuilder customFilterBuilder = CapCommonToolkit.filterFactory().customFilterBuilder();
customFilterBuilder.setFilterType(uiCustomFilter.getFilterType());
customFilterBuilder.setInverted(uiCustomFilter.isInverted());
customFilterBuilder.setOperator(uiCustomFilter.getOperator());
customFilterBuilder.setPropertyName(uiCustomFilter.getPropertyName());
customFilterBuilder.setValue(uiCustomFilter.getValue());
return customFilterBuilder.build();
} else {
throw new IllegalStateException("Cannot convert unkown filter class '" + uiFilter.getClass().getName() + "'.");
}
}
Aggregations