Class EntityValidationRSQLVisitor

java.lang.Object
in.co.akshitbansal.springwebquery.ValidationRSQLVisitor
in.co.akshitbansal.springwebquery.EntityValidationRSQLVisitor
All Implemented Interfaces:
cz.jirutka.rsql.parser.ast.RSQLVisitor<Void,NodeMetadata>

public class EntityValidationRSQLVisitor extends ValidationRSQLVisitor
RSQL AST visitor that validates RSQL queries against a given entity class.

This visitor traverses the Abstract Syntax Tree (AST) produced by the RSQL parser and ensures that:

  • All fields referenced in the query exist on the entity class
  • Only fields annotated with RSQLFilterable are filterable
  • Only allowed RSQL operators (as defined in the RSQLFilterable annotation) are used

If any violation is detected, a QueryException is thrown describing the invalid field or operator.

Usage example:


 Node root = new RSQLParser().parse("status==ACTIVE;age>30");
 EntityValidationRSQLVisitor visitor =
         new EntityValidationRSQLVisitor(User.class, new FieldMapping[0], annotationUtil, true, false, 1);
 root.accept(visitor, NodeMetadata.of(0));
 

This visitor is typically used in combination with RSQLJPASupport to ensure that only valid queries are converted into Spring Data JPA Specifications.

See Also:
  • Constructor Details

    • EntityValidationRSQLVisitor

      public EntityValidationRSQLVisitor(Class<?> entityClass, FieldMapping[] fieldMappings, AnnotationUtil annotationUtil, boolean andNodeAllowed, boolean orNodeAllowed, int maxDepth)
      Creates a new entity validation visitor with the specified configuration.
      Parameters:
      entityClass - the entity class to validate against
      fieldMappings - array of field mappings (aliases) to consider
      annotationUtil - helper for annotation resolution and operator checks
      andNodeAllowed - whether logical AND operator is allowed
      orNodeAllowed - whether logical OR operator is allowed
      maxDepth - maximum allowed depth for the RSQL AST
  • Method Details