Search in sources :

Example 1 with Node

use of cz.jirutka.rsql.parser.ast.Node in project molgenis by molgenis.

the class MolgenisRSQL method createQuery.

public Query<Entity> createQuery(String rsql, EntityType entityType) {
    Node rootNode = rsqlParser.parse(rsql);
    MolgenisRSQLVisitor visitor = new MolgenisRSQLVisitor(entityType);
    return rootNode.accept(visitor);
}
Also used : Node(cz.jirutka.rsql.parser.ast.Node)

Example 2 with Node

use of cz.jirutka.rsql.parser.ast.Node in project tutorials by eugenp.

the class UserController method findAllByRsql.

@RequestMapping(method = RequestMethod.GET, value = "/users/rsql")
@ResponseBody
public List<User> findAllByRsql(@RequestParam(value = "search") String search) {
    Node rootNode = new RSQLParser().parse(search);
    Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    return dao.findAll(spec);
}
Also used : User(org.baeldung.persistence.model.User) MyUser(org.baeldung.persistence.model.MyUser) RSQLParser(cz.jirutka.rsql.parser.RSQLParser) Node(cz.jirutka.rsql.parser.ast.Node) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Node

use of cz.jirutka.rsql.parser.ast.Node in project tutorials by eugenp.

the class GenericRsqlSpecBuilder method createSpecification.

public Specifications<T> createSpecification(final LogicalNode logicalNode) {
    final List<Specifications<T>> specs = new ArrayList<Specifications<T>>();
    Specifications<T> temp;
    for (final Node node : logicalNode.getChildren()) {
        temp = createSpecification(node);
        if (temp != null) {
            specs.add(temp);
        }
    }
    Specifications<T> result = specs.get(0);
    if (logicalNode.getOperator() == LogicalOperator.AND) {
        for (int i = 1; i < specs.size(); i++) {
            result = Specifications.where(result).and(specs.get(i));
        }
    } else if (logicalNode.getOperator() == LogicalOperator.OR) {
        for (int i = 1; i < specs.size(); i++) {
            result = Specifications.where(result).or(specs.get(i));
        }
    }
    return result;
}
Also used : Specifications(org.springframework.data.jpa.domain.Specifications) ComparisonNode(cz.jirutka.rsql.parser.ast.ComparisonNode) Node(cz.jirutka.rsql.parser.ast.Node) LogicalNode(cz.jirutka.rsql.parser.ast.LogicalNode) ArrayList(java.util.ArrayList)

Example 4 with Node

use of cz.jirutka.rsql.parser.ast.Node in project tutorials by eugenp.

the class RsqlIntegrationTest method givenFirstNameInverse_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName!=john");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);
    assertThat(userTom, isIn(results));
    assertThat(userJohn, not(isIn(results)));
}
Also used : User(org.baeldung.persistence.model.User) RSQLParser(cz.jirutka.rsql.parser.RSQLParser) Node(cz.jirutka.rsql.parser.ast.Node) Test(org.junit.Test)

Example 5 with Node

use of cz.jirutka.rsql.parser.ast.Node in project tutorials by eugenp.

the class RsqlIntegrationTest method givenListOfFirstName_whenGettingListOfUsers_thenCorrect.

@Test
public void givenListOfFirstName_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName=in=(john,jack)");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);
    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
Also used : User(org.baeldung.persistence.model.User) RSQLParser(cz.jirutka.rsql.parser.RSQLParser) Node(cz.jirutka.rsql.parser.ast.Node) Test(org.junit.Test)

Aggregations

Node (cz.jirutka.rsql.parser.ast.Node)8 RSQLParser (cz.jirutka.rsql.parser.RSQLParser)6 User (org.baeldung.persistence.model.User)6 Test (org.junit.Test)5 ComparisonNode (cz.jirutka.rsql.parser.ast.ComparisonNode)1 LogicalNode (cz.jirutka.rsql.parser.ast.LogicalNode)1 ArrayList (java.util.ArrayList)1 MyUser (org.baeldung.persistence.model.MyUser)1 Specifications (org.springframework.data.jpa.domain.Specifications)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1