Search in sources :

Example 1 with Expr1ViewItemImpl

use of org.drools.model.view.Expr1ViewItemImpl in project drools by kiegroup.

the class ViewFlowBuilder method viewItem2Condition.

private static Condition viewItem2Condition(ViewItem viewItem, Condition condition, BuildContext ctx) {
    if (viewItem instanceof AbstractExprViewItem) {
        ((PatternImpl) condition).addWatchedProps(((AbstractExprViewItem) viewItem).getWatchedProps());
    }
    if (viewItem instanceof Expr1ViewItemImpl) {
        Expr1ViewItemImpl expr = (Expr1ViewItemImpl) viewItem;
        if (expr.getPredicate() != null) {
            ((PatternImpl) condition).addConstraint(new SingleConstraint1(expr));
        }
        return condition;
    }
    if (viewItem instanceof ExprNViewItem) {
        ((PatternImpl) condition).addConstraint(SingleConstraint.createConstraint((ExprNViewItem) viewItem));
        return condition;
    }
    if (viewItem instanceof TemporalExprViewItem) {
        TemporalExprViewItem expr = (TemporalExprViewItem) viewItem;
        ((PatternImpl) condition).addConstraint(new TemporalConstraint(expr));
        return condition;
    }
    if (viewItem instanceof AccumulateExprViewItem) {
        AccumulateExprViewItem acc = (AccumulateExprViewItem) viewItem;
        for (AccumulateFunction accFunc : acc.getAccumulateFunctions()) {
            ctx.usedVars.add(accFunc.getVariable());
        }
        final Condition newCondition = acc.getExpr() instanceof InputViewItem ? condition : viewItem2Condition(acc.getExpr(), condition, ctx);
        return new AccumulatePatternImpl(newCondition, acc.getAccumulateFunctions());
    }
    if (viewItem instanceof CombinedExprViewItem) {
        CombinedExprViewItem combined = (CombinedExprViewItem) viewItem;
        CompositePatterns patterns = viewItems2Condition(new BuildContext(ctx, combined.getExpressions()), combined.getType(), false);
        return patterns.getSubConditions().size() == 1 ? patterns.getSubConditions().get(0) : patterns;
    }
    throw new UnsupportedOperationException("Unknown ViewItem: " + viewItem);
}
Also used : Condition(org.drools.model.Condition) AccumulatePatternImpl(org.drools.model.patterns.AccumulatePatternImpl) SingleConstraint1(org.drools.model.constraints.SingleConstraint1) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) InputViewItem(org.drools.model.view.InputViewItem) CompositePatterns(org.drools.model.patterns.CompositePatterns) AbstractExprViewItem(org.drools.model.view.AbstractExprViewItem) PatternImpl(org.drools.model.patterns.PatternImpl) ExistentialPatternImpl(org.drools.model.patterns.ExistentialPatternImpl) AccumulatePatternImpl(org.drools.model.patterns.AccumulatePatternImpl) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) TemporalConstraint(org.drools.model.constraints.TemporalConstraint) Expr1ViewItemImpl(org.drools.model.view.Expr1ViewItemImpl) AccumulateFunction(org.drools.model.functions.accumulate.AccumulateFunction) TemporalExprViewItem(org.drools.model.view.TemporalExprViewItem) ExprNViewItem(org.drools.model.view.ExprNViewItem)

Aggregations

Condition (org.drools.model.Condition)1 SingleConstraint1 (org.drools.model.constraints.SingleConstraint1)1 TemporalConstraint (org.drools.model.constraints.TemporalConstraint)1 AccumulateFunction (org.drools.model.functions.accumulate.AccumulateFunction)1 AccumulatePatternImpl (org.drools.model.patterns.AccumulatePatternImpl)1 CompositePatterns (org.drools.model.patterns.CompositePatterns)1 ExistentialPatternImpl (org.drools.model.patterns.ExistentialPatternImpl)1 PatternImpl (org.drools.model.patterns.PatternImpl)1 AbstractExprViewItem (org.drools.model.view.AbstractExprViewItem)1 AccumulateExprViewItem (org.drools.model.view.AccumulateExprViewItem)1 CombinedExprViewItem (org.drools.model.view.CombinedExprViewItem)1 Expr1ViewItemImpl (org.drools.model.view.Expr1ViewItemImpl)1 ExprNViewItem (org.drools.model.view.ExprNViewItem)1 InputViewItem (org.drools.model.view.InputViewItem)1 TemporalExprViewItem (org.drools.model.view.TemporalExprViewItem)1