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);
}
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;
}
Aggregations