use of org.springframework.data.spel.ExpressionDependencies in project spring-data-mongodb by spring-projects.
the class AbstractMongoQuery method prepareBindingContext.
/**
* Create the {@link ParameterBindingContext binding context} used for SpEL evaluation.
*
* @param source the JSON source.
* @param accessor value provider for parameter binding.
* @return never {@literal null}.
* @since 3.4
*/
protected ParameterBindingContext prepareBindingContext(String source, ConvertingParameterAccessor accessor) {
ExpressionDependencies dependencies = getParameterBindingCodec().captureExpressionDependencies(source, accessor::getBindableValue, expressionParser);
SpELExpressionEvaluator evaluator = getSpELExpressionEvaluatorFor(dependencies, accessor);
return new ParameterBindingContext(accessor::getBindableValue, evaluator);
}
use of org.springframework.data.spel.ExpressionDependencies in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReaderUnitTests method discoversCorrectlyDependenciesInExpression.
// DATAMONGO-1894
@Test
void discoversCorrectlyDependenciesInExpression() {
String json = "{ hello: ?#{hasRole('foo')} }";
ExpressionDependencies expressionDependencies = new ParameterBindingDocumentCodec().captureExpressionDependencies(json, it -> new Object(), new SpelExpressionParser());
assertThat(expressionDependencies).isNotEmpty();
assertThat(expressionDependencies.get()).hasSize(1);
}
use of org.springframework.data.spel.ExpressionDependencies in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReaderUnitTests method discoversNoDependenciesInExpression.
// DATAMONGO-1894
@Test
void discoversNoDependenciesInExpression() {
String json = "{ $and : [?#{ [0] == null ? { '$where' : 'true' } : { 'v1' : { '$in' : {[0]} } } }]}";
ExpressionDependencies expressionDependencies = new ParameterBindingDocumentCodec().captureExpressionDependencies(json, it -> new Object(), new SpelExpressionParser());
assertThat(expressionDependencies).isEqualTo(ExpressionDependencies.none());
}
Aggregations