Class EntityValidationRSQLVisitor
java.lang.Object
in.co.akshitbansal.springwebquery.EntityValidationRSQLVisitor
public class EntityValidationRSQLVisitor
extends Object
implements cz.jirutka.rsql.parser.ast.RSQLVisitor<Void,Void>
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
RsqlFilterableare filterable - Only allowed RSQL operators (as defined in the
RsqlFilterableannotation) 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");
new EntityValidationRSQLVisitor(User.class, new FieldMapping[0], annotationUtil).visit(root);
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 Summary
ConstructorsConstructorDescriptionEntityValidationRSQLVisitor(Class<?> entityClass, FieldMapping[] fieldMappings, AnnotationUtil annotationUtil) Creates a new entity validation visitor with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionVisits anAndNodein the RSQL AST and recursively validates all child nodes.Visits aComparisonNodein the RSQL AST and validates the field and operator against the entity class.Visits anOrNodein the RSQL AST and recursively validates all child nodes.
-
Constructor Details
-
EntityValidationRSQLVisitor
public EntityValidationRSQLVisitor(Class<?> entityClass, FieldMapping[] fieldMappings, AnnotationUtil annotationUtil) Creates a new entity validation visitor with the specified configuration.- Parameters:
entityClass- the entity class to validate againstfieldMappings- array of field mappings (aliases) to considerannotationUtil- helper for annotation resolution and operator checks
-
-
Method Details
-
visit
Visits anAndNodein the RSQL AST and recursively validates all child nodes. -
visit
Visits anOrNodein the RSQL AST and recursively validates all child nodes. -
visit
Visits aComparisonNodein the RSQL AST and validates the field and operator against the entity class.- Specified by:
visitin interfacecz.jirutka.rsql.parser.ast.RSQLVisitor<Void,Void> - Parameters:
comparisonNode- the comparison nodeunused- unused parameter- Returns:
- null
- Throws:
QueryValidationException- if the field does not exist, is not filterable, or the operator is not allowedQueryConfigurationException- if a custom operator or field mapping is misconfigured
-