use of org.drools.modelcompiler.constraints.LambdaEvalExpression in project drools by kiegroup.
the class KiePackagesBuilder method buildConditionalConsequence.
private ConditionalBranch buildConditionalConsequence(RuleContext ctx, ConditionalNamedConsequenceImpl consequence) {
// This makes the assumption the variable is for a pattern (not field) binding, and this binding must already exist.
// It's used for the implicit bindings
// The main issue with all of this, is it doesn't allow access to other previous variables. And it should work with
// with pattern bindings and field bindings. What if getVariables() returns an array.length > 1?
EvalCondition evalCondition;
if (consequence.getExpr() != null) {
Pattern pattern = ctx.getPattern(consequence.getExpr().getVariables()[0]);
if (pattern.getDeclaration() != null) {
// pattern has a root binding, so use that.
EvalExpression eval = new LambdaEvalExpression(pattern, consequence.getExpr());
evalCondition = new EvalCondition(eval, new Declaration[] { pattern.getDeclaration() });
} else {
// Pattern does not have root binding, so use field bindings.
Declaration[] declarations = pattern.getDeclarations().values().toArray(new Declaration[pattern.getDeclarations().size()]);
EvalExpression eval = new LambdaEvalExpression(declarations, consequence.getExpr());
evalCondition = new EvalCondition(eval, declarations);
}
} else {
evalCondition = new EvalCondition(LambdaEvalExpression.EMPTY, null);
}
return new ConditionalBranch(evalCondition, new NamedConsequence(consequence.getThenConsequence().getName(), consequence.getThenConsequence().isBreaking()), consequence.getElseBranch() != null ? buildConditionalConsequence(ctx, consequence.getElseBranch()) : null);
}
use of org.drools.modelcompiler.constraints.LambdaEvalExpression in project drools by kiegroup.
the class KiePackagesBuilder method buildEval.
private EvalCondition buildEval(RuleContext ctx, EvalImpl eval) {
Declaration[] declarations = Stream.of(eval.getExpr().getVariables()).map(ctx::getDeclaration).toArray(Declaration[]::new);
EvalExpression evalExpr = new LambdaEvalExpression(declarations, eval.getExpr());
return new EvalCondition(evalExpr, declarations);
}
Aggregations