Search in sources :

Example 6 with IFilter

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();
        }
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IFilter(org.jowidgets.cap.common.api.filter.IFilter)

Example 7 with IFilter

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();
}
Also used : IFilter(org.jowidgets.cap.common.api.filter.IFilter)

Example 8 with IFilter

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();
    }
}
Also used : Some(org.jowidgets.util.maybe.Some) IFilter(org.jowidgets.cap.common.api.filter.IFilter) HashSet(java.util.HashSet)

Example 9 with IFilter

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;
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilter(org.jowidgets.cap.common.api.filter.IFilter) LinkedList(java.util.LinkedList) Predicate(javax.persistence.criteria.Predicate)

Example 10 with IFilter

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() + "'.");
    }
}
Also used : IArithmeticFilterBuilder(org.jowidgets.cap.common.api.filter.IArithmeticFilterBuilder) IUiArithmeticPropertyFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter) IUiCustomFilter(org.jowidgets.cap.ui.api.filter.IUiCustomFilter) IUiBooleanFilter(org.jowidgets.cap.ui.api.filter.IUiBooleanFilter) LinkedList(java.util.LinkedList) ICustomFilterBuilder(org.jowidgets.cap.common.api.filter.ICustomFilterBuilder) IFilter(org.jowidgets.cap.common.api.filter.IFilter) IUiFilter(org.jowidgets.cap.ui.api.filter.IUiFilter) IArithmeticPropertyFilterBuilder(org.jowidgets.cap.common.api.filter.IArithmeticPropertyFilterBuilder) IUiArithmeticFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)

Aggregations

IFilter (org.jowidgets.cap.common.api.filter.IFilter)10 LinkedList (java.util.LinkedList)3 IUiFilter (org.jowidgets.cap.ui.api.filter.IUiFilter)3 Predicate (javax.persistence.criteria.Predicate)2 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)2 IBooleanFilterBuilder (org.jowidgets.cap.common.api.filter.IBooleanFilterBuilder)2 IUiFilterFactory (org.jowidgets.cap.ui.api.filter.IUiFilterFactory)2 HashSet (java.util.HashSet)1 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)1 UniqueConstraintViolationException (org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)1 IArithmeticFilterBuilder (org.jowidgets.cap.common.api.filter.IArithmeticFilterBuilder)1 IArithmeticPropertyFilterBuilder (org.jowidgets.cap.common.api.filter.IArithmeticPropertyFilterBuilder)1 ICustomFilterBuilder (org.jowidgets.cap.common.api.filter.ICustomFilterBuilder)1 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)1 IUiArithmeticFilter (org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)1 IUiArithmeticPropertyFilter (org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter)1 IUiBooleanFilter (org.jowidgets.cap.ui.api.filter.IUiBooleanFilter)1 IUiCustomFilter (org.jowidgets.cap.ui.api.filter.IUiCustomFilter)1 Some (org.jowidgets.util.maybe.Some)1