Search in sources :

Example 1 with NamedConsequence

use of org.drools.core.rule.NamedConsequence in project drools by kiegroup.

the class ConditionalBranchBuilder method build.

public ConditionalBranch build(RuleBuildContext context, BaseDescr descr, Pattern prefixPattern) {
    ConditionalBranchDescr conditionalBranch = (ConditionalBranchDescr) descr;
    String consequenceName = conditionalBranch.getConsequence().getName();
    if (!context.getRuleDescr().getNamedConsequences().keySet().contains(consequenceName)) {
        DroolsError err = new RuleBuildError(context.getRule(), context.getParentDescr(), null, "Unknown consequence name: " + consequenceName);
        context.addError(err);
        return null;
    }
    RuleConditionBuilder evalBuilder = (RuleConditionBuilder) context.getDialect().getBuilder(EvalDescr.class);
    EvalCondition condition = (EvalCondition) evalBuilder.build(context, conditionalBranch.getCondition(), getLastPattern(context));
    NamedConsequenceBuilder namedConsequenceBuilder = (NamedConsequenceBuilder) context.getDialect().getBuilder(NamedConsequenceDescr.class);
    NamedConsequence consequence = namedConsequenceBuilder.build(context, conditionalBranch.getConsequence());
    ConditionalBranchDescr elseBranchDescr = conditionalBranch.getElseBranch();
    return new ConditionalBranch(condition, consequence, elseBranchDescr != null ? build(context, elseBranchDescr, prefixPattern) : null);
}
Also used : DroolsError(org.drools.compiler.compiler.DroolsError) NamedConsequenceDescr(org.drools.compiler.lang.descr.NamedConsequenceDescr) ConditionalBranchDescr(org.drools.compiler.lang.descr.ConditionalBranchDescr) RuleBuildError(org.drools.compiler.compiler.RuleBuildError) EvalDescr(org.drools.compiler.lang.descr.EvalDescr) ConditionalBranch(org.drools.core.rule.ConditionalBranch) EvalCondition(org.drools.core.rule.EvalCondition) NamedConsequence(org.drools.core.rule.NamedConsequence)

Example 2 with NamedConsequence

use of org.drools.core.rule.NamedConsequence in project drools by kiegroup.

the class KiePackagesBuilder method buildConditionalConsequence.

private ConditionalBranch buildConditionalConsequence(RuleContext ctx, ConditionalNamedConsequenceImpl consequence) {
    EvalCondition evalCondition;
    if (consequence.getExpr() != null) {
        Pattern pattern = ctx.getPattern(consequence.getExpr().getVariables()[0]);
        EvalExpression eval = new LambdaEvalExpression(pattern, consequence.getExpr());
        evalCondition = new EvalCondition(eval, pattern.getRequiredDeclarations());
    } 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);
}
Also used : LambdaEvalExpression(org.drools.modelcompiler.constraints.LambdaEvalExpression) EvalExpression(org.drools.core.spi.EvalExpression) QueryCallPattern(org.drools.model.patterns.QueryCallPattern) AccumulatePattern(org.drools.model.AccumulatePattern) Pattern(org.drools.core.rule.Pattern) ConditionalBranch(org.drools.core.rule.ConditionalBranch) LambdaEvalExpression(org.drools.modelcompiler.constraints.LambdaEvalExpression) EvalCondition(org.drools.core.rule.EvalCondition) NamedConsequence(org.drools.core.rule.NamedConsequence)

Example 3 with NamedConsequence

use of org.drools.core.rule.NamedConsequence in project drools by kiegroup.

the class NamedConsequenceBuilder method build.

public void build(BuildContext context, BuildUtils utils, RuleConditionElement rce) {
    NamedConsequence namedConsequence = (NamedConsequence) rce;
    Timer timer = context.getRule().getTimer();
    if (timer != null) {
        ReteooComponentBuilder builder = utils.getBuilderFor(Timer.class);
        builder.build(context, utils, context.getRule().getTimer());
    }
    RuleTerminalNode terminalNode = buildTerminalNodeForNamedConsequence(context, namedConsequence);
    terminalNode.attach(context);
    terminalNode.networkUpdated(new UpdateContext());
    // adds the terminal node to the list of nodes created/added by this sub-rule
    context.getNodes().add(terminalNode);
    if (timer != null) {
        context.setTupleSource(context.getTupleSource().getLeftTupleSource());
    }
    context.setTerminated(namedConsequence.isTerminal());
}
Also used : Timer(org.drools.core.time.impl.Timer) UpdateContext(org.drools.core.common.UpdateContext) NamedConsequence(org.drools.core.rule.NamedConsequence) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Aggregations

NamedConsequence (org.drools.core.rule.NamedConsequence)3 ConditionalBranch (org.drools.core.rule.ConditionalBranch)2 EvalCondition (org.drools.core.rule.EvalCondition)2 DroolsError (org.drools.compiler.compiler.DroolsError)1 RuleBuildError (org.drools.compiler.compiler.RuleBuildError)1 ConditionalBranchDescr (org.drools.compiler.lang.descr.ConditionalBranchDescr)1 EvalDescr (org.drools.compiler.lang.descr.EvalDescr)1 NamedConsequenceDescr (org.drools.compiler.lang.descr.NamedConsequenceDescr)1 UpdateContext (org.drools.core.common.UpdateContext)1 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)1 Pattern (org.drools.core.rule.Pattern)1 EvalExpression (org.drools.core.spi.EvalExpression)1 Timer (org.drools.core.time.impl.Timer)1 AccumulatePattern (org.drools.model.AccumulatePattern)1 QueryCallPattern (org.drools.model.patterns.QueryCallPattern)1 LambdaEvalExpression (org.drools.modelcompiler.constraints.LambdaEvalExpression)1