Search in sources :

Example 1 with CriteriaParser

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

the class JPASpecificationIntegrationTest method givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect() {
    GenericSpecificationsBuilder<User> builder = new GenericSpecificationsBuilder<>();
    Function<SpecSearchCriteria, Specification<User>> converter = UserSpecification::new;
    CriteriaParser parser = new CriteriaParser();
    List<User> results = repository.findAll(builder.build(parser.parse("( lastName:doe OR firstName:john ) AND age:22"), converter));
    assertThat(results, hasSize(1));
    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
Also used : User(org.baeldung.persistence.model.User) CriteriaParser(org.baeldung.web.util.CriteriaParser) GenericSpecificationsBuilder(org.baeldung.persistence.dao.GenericSpecificationsBuilder) UserSpecification(org.baeldung.persistence.dao.UserSpecification) Specification(org.springframework.data.jpa.domain.Specification) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria) Test(org.junit.Test)

Example 2 with CriteriaParser

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

the class UserController method resolveSpecificationFromInfixExpr.

protected Specification<User> resolveSpecificationFromInfixExpr(String searchParameters) {
    CriteriaParser parser = new CriteriaParser();
    GenericSpecificationsBuilder<User> specBuilder = new GenericSpecificationsBuilder<>();
    return specBuilder.build(parser.parse(searchParameters), UserSpecification::new);
}
Also used : CriteriaParser(org.baeldung.web.util.CriteriaParser) User(org.baeldung.persistence.model.User) MyUser(org.baeldung.persistence.model.MyUser) UserSpecification(org.baeldung.persistence.dao.UserSpecification) GenericSpecificationsBuilder(org.baeldung.persistence.dao.GenericSpecificationsBuilder)

Aggregations

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