Search in sources :

Example 1 with IArithmeticFilter

use of org.jowidgets.cap.common.api.filter.IArithmeticFilter in project jo-client-platform by jo-source.

the class CriteriaQueryCreator method createFilterPredicate.

private Predicate createFilterPredicate(final CriteriaBuilder criteriaBuilder, final Root<?> bean, final CriteriaQuery<?> query, final IFilter filter, final PARAM_TYPE parameter) {
    if (filter instanceof IPropertyFilter) {
        final IPropertyFilter propertyFilter = (IPropertyFilter) filter;
        final String propertyName = propertyFilter.getPropertyName();
        final IPropertyFilterPredicateCreator<PARAM_TYPE> predicateCreator = propertyFilterPredicateCreators.get(propertyName);
        if (predicateCreator != null) {
            return predicateCreator.createPredicate(criteriaBuilder, bean, query, propertyFilter, parameter);
        }
    }
    if (filter instanceof IArithmeticFilter) {
        return createArithmeticFilterPredicate(criteriaBuilder, bean, query, (IArithmeticFilter) filter);
    } else if (filter instanceof IArithmeticPropertyFilter) {
        // TODO MG support IArithmeticPropertyFilter
        throw new IllegalArgumentException("unsupported filter type: " + filter.getClass().getName());
    } else if (filter instanceof IBooleanFilter) {
        final Predicate predicate;
        predicate = createBooleanFilterPredicate(criteriaBuilder, bean, query, (IBooleanFilter) filter, parameter);
        return invertPredicateIfNeeded(criteriaBuilder, predicate, filter, true);
    } else if (filter instanceof ICustomFilter) {
        final ICustomFilter customFilter = (ICustomFilter) filter;
        final ICustomFilterPredicateCreator<PARAM_TYPE> customFilterPredicateCreator = getCustomFilterPredicateCreator(customFilter);
        if (customFilterPredicateCreator != null) {
            final Predicate predicate;
            predicate = customFilterPredicateCreator.createPredicate(criteriaBuilder, getPath(bean, customFilter.getPropertyName()), query, customFilter, parameter);
            return invertPredicateIfNeeded(criteriaBuilder, predicate, filter, true);
        } else {
            throw new IllegalArgumentException("unsupported custom filter type: " + customFilter.getFilterType());
        }
    } else {
        throw new IllegalArgumentException("unsupported filter type: " + filter.getClass().getName());
    }
}
Also used : IArithmeticPropertyFilter(org.jowidgets.cap.common.api.filter.IArithmeticPropertyFilter) IArithmeticFilter(org.jowidgets.cap.common.api.filter.IArithmeticFilter) IBooleanFilter(org.jowidgets.cap.common.api.filter.IBooleanFilter) ICustomFilterPredicateCreator(org.jowidgets.cap.service.jpa.api.query.ICustomFilterPredicateCreator) ICustomFilter(org.jowidgets.cap.common.api.filter.ICustomFilter) IPropertyFilter(org.jowidgets.cap.common.api.filter.IPropertyFilter) Predicate(javax.persistence.criteria.Predicate)

Example 2 with IArithmeticFilter

use of org.jowidgets.cap.common.api.filter.IArithmeticFilter in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method checkExecutableState.

private void checkExecutableState(final ILinkCreation link, final IExecutionCallback executionCallback) {
    final Collection<IBeanKey> linkableBeans = link.getLinkableBeans();
    if (!EmptyCheck.isEmpty(linkableBeans)) {
        for (final IBeanKey sourceBean : link.getSourceBeans()) {
            final IFilterFactory filterFactory = CapCommonToolkit.filterFactory();
            final Object[] linkableKeys = new Object[linkableBeans.size()];
            int index = 0;
            for (final IBeanKey key : linkableBeans) {
                linkableKeys[index] = key.getId();
                index++;
            }
            final IArithmeticFilter filter;
            if (destinationProperties != null) {
                filter = filterFactory.arithmeticFilter(destinationProperties.getKeyPropertyName(), ArithmeticOperator.CONTAINS_ANY, linkableKeys);
            } else if (sourceProperties != null) {
                filter = filterFactory.arithmeticFilter(sourceProperties.getKeyPropertyName(), ArithmeticOperator.CONTAINS_ANY, linkableKeys);
            } else {
                throw new IllegalStateException("Neither the source not the destination properties are defined");
            }
            final SyncResultCallback<Integer> result = new SyncResultCallback<Integer>();
            linkableReaderService.count(result, Collections.singletonList(sourceBean), filter, null, executionCallback);
            final Integer count = result.getResultSynchronious();
            if (count == null || count.intValue() < linkableKeys.length) {
                throw new ExecutableCheckException(sourceBean.getId(), "Beans are not linkable", DATASETS_CAN_NOT_BE_LINKED.get());
            }
        }
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilterFactory(org.jowidgets.cap.common.api.filter.IFilterFactory) IArithmeticFilter(org.jowidgets.cap.common.api.filter.IArithmeticFilter) ExecutableCheckException(org.jowidgets.cap.common.api.exception.ExecutableCheckException) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback)

Aggregations

IArithmeticFilter (org.jowidgets.cap.common.api.filter.IArithmeticFilter)2 Predicate (javax.persistence.criteria.Predicate)1 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)1 ExecutableCheckException (org.jowidgets.cap.common.api.exception.ExecutableCheckException)1 IArithmeticPropertyFilter (org.jowidgets.cap.common.api.filter.IArithmeticPropertyFilter)1 IBooleanFilter (org.jowidgets.cap.common.api.filter.IBooleanFilter)1 ICustomFilter (org.jowidgets.cap.common.api.filter.ICustomFilter)1 IFilterFactory (org.jowidgets.cap.common.api.filter.IFilterFactory)1 IPropertyFilter (org.jowidgets.cap.common.api.filter.IPropertyFilter)1 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)1 ICustomFilterPredicateCreator (org.jowidgets.cap.service.jpa.api.query.ICustomFilterPredicateCreator)1