Search in sources :

Example 1 with ExpressionDependencies

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);
}
Also used : SpELExpressionEvaluator(org.springframework.data.mapping.model.SpELExpressionEvaluator) ExpressionDependencies(org.springframework.data.spel.ExpressionDependencies) ParameterBindingContext(org.springframework.data.mongodb.util.json.ParameterBindingContext)

Example 2 with ExpressionDependencies

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);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) ExpressionDependencies(org.springframework.data.spel.ExpressionDependencies) Test(org.junit.jupiter.api.Test)

Example 3 with ExpressionDependencies

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());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) ExpressionDependencies(org.springframework.data.spel.ExpressionDependencies) Test(org.junit.jupiter.api.Test)

Aggregations

ExpressionDependencies (org.springframework.data.spel.ExpressionDependencies)3 Test (org.junit.jupiter.api.Test)2 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)2 SpELExpressionEvaluator (org.springframework.data.mapping.model.SpELExpressionEvaluator)1 ParameterBindingContext (org.springframework.data.mongodb.util.json.ParameterBindingContext)1