Search in sources :

Example 11 with SpecSearchCriteria

use of org.baeldung.web.util.SpecSearchCriteria in project tutorials by eugenp.

the class UserSpecificationsBuilder method with.

public final UserSpecificationsBuilder with(final String orPredicate, final String key, final String operation, final Object value, final String prefix, final String suffix) {
    SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0));
    if (op != null) {
        if (op == SearchOperation.EQUALITY) {
            // the operation may be complex operation
            final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
            final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
            if (startWithAsterisk && endWithAsterisk) {
                op = SearchOperation.CONTAINS;
            } else if (startWithAsterisk) {
                op = SearchOperation.ENDS_WITH;
            } else if (endWithAsterisk) {
                op = SearchOperation.STARTS_WITH;
            }
        }
        params.add(new SpecSearchCriteria(orPredicate, key, op, value));
    }
    return this;
}
Also used : SearchOperation(org.baeldung.web.util.SearchOperation) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria)

Aggregations

SpecSearchCriteria (org.baeldung.web.util.SpecSearchCriteria)11 User (org.baeldung.persistence.model.User)9 Test (org.junit.Test)9 UserSpecification (org.baeldung.persistence.dao.UserSpecification)8 SearchOperation (org.baeldung.web.util.SearchOperation)2 GenericSpecificationsBuilder (org.baeldung.persistence.dao.GenericSpecificationsBuilder)1 UserSpecificationsBuilder (org.baeldung.persistence.dao.UserSpecificationsBuilder)1 CriteriaParser (org.baeldung.web.util.CriteriaParser)1 Specification (org.springframework.data.jpa.domain.Specification)1