cz.jirutka.rsql.parser.ast.OrNode Java Examples

The following examples show how to use cz.jirutka.rsql.parser.ast.OrNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryRsqlVisitorTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testVisitOrNode() {
  String argument0 = "piet";
  ComparisonOperator operator0 = new ComparisonOperator("=q=");
  ComparisonNode node0 = new ComparisonNode(operator0, "*", singletonList(argument0));

  String argument1 = "jan";
  ComparisonOperator operator1 = new ComparisonOperator("=q=");
  ComparisonNode node1 = new ComparisonNode(operator1, "*", singletonList(argument1));

  OrNode orNode = new OrNode(asList(node0, node1));
  Query query =
      Query.builder()
          .setOperator(OR)
          .setValue(
              asList(
                  Query.builder().setOperator(MATCHES).setValue(argument0).build(),
                  Query.builder().setOperator(MATCHES).setValue(argument1).build()))
          .build();
  assertEquals(query, queryRsqlVisitor.visit(orNode));
}
 
Example #2
Source File: MolgenisRSQLVisitor.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Query<Entity> visit(OrNode node) {
  initQuery();
  boolean nested = node.getChildren().size() > 1;
  if (nested) {
    q.nest();
  }

  for (Iterator<Node> it = node.iterator(); it.hasNext(); ) {
    Node child = it.next();
    child.accept(this);

    if (it.hasNext()) {
      q.or();
    }
  }
  if (nested) {
    q.unnest();
  }

  return q;
}
 
Example #3
Source File: SearchFilterToQueryConverter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public SearchQuery visit(final OrNode node) {
  final List<SearchQuery> queries = new ArrayList<>();
  for (final Node child: node.getChildren()) {
    queries.add(child.accept(this));
  }
  return SearchQueryUtils.or(queries);
}
 
Example #4
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<Predicate> visit(final OrNode node, final String param) {
    beginLevel(true);
    final List<Predicate> childs = acceptChilds(node);
    endLevel();
    if (!childs.isEmpty()) {
        return toSingleList(cb.or(childs.toArray(new Predicate[childs.size()])));
    }
    return toSingleList(cb.conjunction());
}
 
Example #5
Source File: PermissionRsqlVisitor.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public PermissionsQuery visit(OrNode orNode) {
  List<Node> nodes = orNode.getChildren();
  PermissionsQuery permissionsQuery = new PermissionsQuery();
  if (nodes.size() == 2) {
    for (Node node : nodes) {
      if (node instanceof ComparisonNode) {
        setQuery((ComparisonNode) node, permissionsQuery);
      } else {
        throw new UnsupportedOperationException("invalide node");
      }
    }
  }
  return permissionsQuery;
}
 
Example #6
Source File: PermissionRsqlVisitorTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testVisitOr() {
  ComparisonNode comparisonNodeUser =
      new ComparisonNode(
          new ComparisonOperator("=="), "user", Collections.singletonList("user1"));
  ComparisonNode comparisonNodeRole =
      new ComparisonNode(
          new ComparisonOperator("=in=", true), "role", Arrays.asList("role1", "role2"));
  OrNode orNode = new OrNode(Arrays.asList(comparisonNodeUser, comparisonNodeRole));
  assertEquals(
      new PermissionsQuery(asList("user1"), asList("role1", "role2")), visitor.visit(orNode));
}
 
Example #7
Source File: RSQLSimpleConverter.java    From rsql-jpa-specification with MIT License 4 votes vote down vote up
@Override
public Void visit(OrNode node, MultiValueMap<String, String> map) {
	log.debug("visit(node:{},map:{})", node, map);
	node.getChildren().forEach(n -> n.accept(this, map));
	return null;
}
 
Example #8
Source File: RSQLComplexConverter.java    From rsql-jpa-specification with MIT License 4 votes vote down vote up
@Override
public Void visit(OrNode node, Map<String, MultiValueMap<String, String>> map) {
	log.debug("visit(node:{},map:{})", node, map);
	node.getChildren().forEach(n -> n.accept(this, map));
	return null;
}
 
Example #9
Source File: RSQLQueryDslPredicateConverter.java    From rsql-jpa-specification with MIT License 4 votes vote down vote up
@Override
public BooleanExpression visit(OrNode node, Path entityClass) {
	log.debug("visit(node:{},param:{})", node, entityClass);

	return node.getChildren().stream().map(n -> n.accept(this, entityClass)).collect(Collectors.reducing(BooleanExpression::or)).get();
}
 
Example #10
Source File: RSQLJPAPredicateConverter.java    From rsql-jpa-specification with MIT License 4 votes vote down vote up
@Override
public Predicate visit(OrNode node, Root root) {
	log.debug("visit(node:{},root:{})", node, root);

	return node.getChildren().stream().map(n -> n.accept(this, root)).collect(Collectors.reducing(builder::or)).get();
}
 
Example #11
Source File: RSQLNodeTraveller.java    From pnc with Apache License 2.0 4 votes vote down vote up
@Override
public T visit(OrNode node) {
    return visit((LogicalNode) node);
}
 
Example #12
Source File: RSQLNodeTraveller.java    From pnc with Apache License 2.0 4 votes vote down vote up
@Override
public T visit(OrNode node) {
    return visit((LogicalNode) node);
}
 
Example #13
Source File: QueryRsqlVisitor.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Query visit(OrNode node) {
  return visit(node, OR);
}
 
Example #14
Source File: AggregateQueryRsqlVisitor.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public AggregateQuery visit(OrNode node) {
  throw new MolgenisQueryException(
      "RSQL query operator OR (';' or 'or') not allowed in aggregates query");
}
 
Example #15
Source File: CustomRsqlVisitor.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Specification<T> visit(final OrNode node, final Void param) {
    return builder.createSpecification(node);
}