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>
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");
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 Summary
ConstructorsConstructorDescriptionEntityValidationRSQLVisitor(Class<?> entityClass, FieldMapping[] fieldMappings, AnnotationUtil annotationUtil, boolean andNodeAllowed, boolean orNodeAllowed, int maxDepth) Creates a new entity validation visitor with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvalidateComparisonNode(cz.jirutka.rsql.parser.ast.ComparisonNode node) Validates a comparison node against the entity class.Methods inherited from class in.co.akshitbansal.springwebquery.ValidationRSQLVisitor
validateNode, visit, visit, visit
-
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 againstfieldMappings- array of field mappings (aliases) to considerannotationUtil- helper for annotation resolution and operator checksandNodeAllowed- whether logical AND operator is allowedorNodeAllowed- whether logical OR operator is allowedmaxDepth- maximum allowed depth for the RSQL AST
-
-
Method Details
-
validateComparisonNode
protected void validateComparisonNode(cz.jirutka.rsql.parser.ast.ComparisonNode node) Validates a comparison node against the entity class.- Specified by:
validateComparisonNodein classValidationRSQLVisitor- Parameters:
node- the comparison node to validate- Throws:
QueryValidationException- if the field is not allowed or operator is invalidQueryConfigurationException- if the field mapping is misconfigured
-