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);
}
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);
}
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;
}
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)));
}
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)));
}
Aggregations