AvistoTelecom / jpa-search

This library allows you to create complex searching configurations in an easy way
GNU Lesser General Public License v3.0
1 stars 0 forks source link

Add a FilterOperation to test true/false fields #23

Open geraldgole opened 3 months ago

geraldgole commented 3 months ago

It would be nice to have a new FilterOperation type to test boolean fields in database.

Ex : GET /users?deleted=true

Suggested implementation :

public enum BooleanFilterOperation implements IFilterOperation<Boolean> {
    IS_TRUE_FALSE {
        @Override
        public Predicate calculate(CriteriaBuilder cb, Expression<?> expression, Boolean value) {
            return value
                    ? cb.isTrue((Expression<Boolean>) expression)
                    : cb.isFalse((Expression<Boolean>) expression);
        }
    };

    @Override
    public boolean needsMultipleValues() {
        return false;
    }

    @Override
    public Class<Boolean> getOperationType() {
        return Boolean.class;
    }
}