Search in sources :

Example 1 with ExpressionEvaluator

use of io.seata.saga.engine.evaluation.expression.ExpressionEvaluator in project seata by seata.

the class LoopTaskUtils method getEvaluator.

/**
 * get loop completion condition evaluator
 *
 * @param context
 * @param completionCondition
 * @return
 */
private static ExpressionEvaluator getEvaluator(ProcessContext context, String completionCondition) {
    if (StringUtils.isBlank(completionCondition)) {
        completionCondition = DEFAULT_COMPLETION_CONDITION;
    }
    if (!EXPRESSION_EVALUATOR_MAP.containsKey(completionCondition)) {
        StateMachineConfig stateMachineConfig = (StateMachineConfig) context.getVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONFIG);
        ExpressionEvaluator expressionEvaluator = (ExpressionEvaluator) stateMachineConfig.getEvaluatorFactoryManager().getEvaluatorFactory(EvaluatorFactoryManager.EVALUATOR_TYPE_DEFAULT).createEvaluator(completionCondition);
        expressionEvaluator.setRootObjectName(null);
        EXPRESSION_EVALUATOR_MAP.put(completionCondition, expressionEvaluator);
    }
    return EXPRESSION_EVALUATOR_MAP.get(completionCondition);
}
Also used : StateMachineConfig(io.seata.saga.engine.StateMachineConfig) ExpressionEvaluator(io.seata.saga.engine.evaluation.expression.ExpressionEvaluator)

Example 2 with ExpressionEvaluator

use of io.seata.saga.engine.evaluation.expression.ExpressionEvaluator in project seata by seata.

the class ServiceTaskHandlerInterceptor method createEvaluator.

private Evaluator createEvaluator(EvaluatorFactoryManager evaluatorFactoryManager, String expressionStr) {
    String expressionType = null;
    String expressionContent = null;
    Evaluator evaluator = null;
    if (StringUtils.hasLength(expressionStr)) {
        if (expressionStr.startsWith("$")) {
            int expTypeStart = expressionStr.indexOf("$");
            int expTypeEnd = expressionStr.indexOf("{", expTypeStart);
            if (expTypeStart >= 0 && expTypeEnd > expTypeStart) {
                expressionType = expressionStr.substring(expTypeStart + 1, expTypeEnd);
            }
            int expEnd = expressionStr.lastIndexOf("}");
            if (expTypeEnd > 0 && expEnd > expTypeEnd) {
                expressionContent = expressionStr.substring(expTypeEnd + 1, expEnd);
            }
        } else {
            expressionContent = expressionStr;
        }
        EvaluatorFactory evaluatorFactory = evaluatorFactoryManager.getEvaluatorFactory(expressionType);
        if (evaluatorFactory == null) {
            throw new IllegalArgumentException("Cannot get EvaluatorFactory by Type[" + expressionType + "]");
        }
        evaluator = evaluatorFactory.createEvaluator(expressionContent);
        if (evaluator instanceof ExpressionEvaluator) {
            ((ExpressionEvaluator) evaluator).setRootObjectName(DomainConstants.VAR_NAME_OUTPUT_PARAMS);
        }
    }
    return evaluator;
}
Also used : EvaluatorFactory(io.seata.saga.engine.evaluation.EvaluatorFactory) ExpressionEvaluator(io.seata.saga.engine.evaluation.expression.ExpressionEvaluator) Evaluator(io.seata.saga.engine.evaluation.Evaluator) ExpressionEvaluator(io.seata.saga.engine.evaluation.expression.ExpressionEvaluator)

Aggregations

ExpressionEvaluator (io.seata.saga.engine.evaluation.expression.ExpressionEvaluator)2 StateMachineConfig (io.seata.saga.engine.StateMachineConfig)1 Evaluator (io.seata.saga.engine.evaluation.Evaluator)1 EvaluatorFactory (io.seata.saga.engine.evaluation.EvaluatorFactory)1