Class DTOValidationRSQLVisitor

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

public class DTOValidationRSQLVisitor extends ValidationRSQLVisitor
RSQL AST visitor that validates filters against a DTO contract and maps DTO property paths to entity property paths.

This visitor is used when WebQuery.dtoClass() is configured. It enforces that:

  • The requested selector exists on the DTO type.
  • The terminal DTO field is annotated with RSQLFilterable.
  • The requested operator is allowed for that DTO field.
  • The resulting mapped entity path can be resolved on the configured entity type.

During validation, selector mappings are captured and exposed via getFieldMappings() so downstream query construction can apply DTO-to-entity path translation.

  • Constructor Details

    • DTOValidationRSQLVisitor

      public DTOValidationRSQLVisitor(Class<?> entityClass, Class<?> dtoClass, AnnotationUtil annotationUtil, boolean andNodeAllowed, boolean orNodeAllowed, int maxDepth)
      Creates a DTO-aware validation visitor.
      Parameters:
      entityClass - target entity type used for final path validation
      dtoClass - DTO type used to validate incoming selector paths
      annotationUtil - helper for resolving allowed operators from annotations
      andNodeAllowed - whether logical AND operator is allowed
      orNodeAllowed - whether logical OR operator is allowed
      maxDepth - maximum allowed depth for the RSQL AST
  • Method Details

    • getFieldMappings

      public Map<String,String> getFieldMappings()
      Returns immutable selector mappings generated while visiting nodes.
      Returns:
      map from request DTO path to resolved entity path
    • validateComparisonNode

      protected void validateComparisonNode(cz.jirutka.rsql.parser.ast.ComparisonNode node)
      Validates a single comparison expression and records DTO-to-entity mapping.
      Specified by:
      validateComparisonNode in class ValidationRSQLVisitor
      Parameters:
      node - node to validate