Search in sources :

Example 1 with ExpressionNode

use of org.springframework.data.mongodb.core.spel.ExpressionNode in project spring-data-mongodb by spring-projects.

the class SpelExpressionTransformer method transform.

/**
 * Transforms the given SpEL expression to a corresponding MongoDB expression against the given
 * {@link AggregationOperationContext} {@code context}.
 * <p>
 * Exposes the given @{code params} as <code>[0] ... [n]</code>.
 *
 * @param expression must not be {@literal null}
 * @param context must not be {@literal null}
 * @param params must not be {@literal null}
 * @return
 */
public Object transform(String expression, AggregationOperationContext context, Object... params) {
    Assert.notNull(expression, "Expression must not be null!");
    Assert.notNull(context, "AggregationOperationContext must not be null!");
    Assert.notNull(params, "Parameters must not be null!");
    SpelExpression spelExpression = (SpelExpression) PARSER.parseExpression(expression);
    ExpressionState state = new ExpressionState(new StandardEvaluationContext(params), CONFIG);
    ExpressionNode node = ExpressionNode.from(spelExpression.getAST(), state);
    return transform(new AggregationExpressionTransformationContext<ExpressionNode>(node, null, null, context));
}
Also used : ExpressionState(org.springframework.expression.spel.ExpressionState) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) ExpressionNode(org.springframework.data.mongodb.core.spel.ExpressionNode)

Aggregations

ExpressionNode (org.springframework.data.mongodb.core.spel.ExpressionNode)1 ExpressionState (org.springframework.expression.spel.ExpressionState)1 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1