Search in sources :

Example 1 with GroupByExprViewItem

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

the class ViewPatternBuilder method ruleItem2Condition.

public static Condition ruleItem2Condition(RuleItem ruleItem) {
    if (ruleItem instanceof PatternDefImpl) {
        PatternDefImpl<?> patternDef = (PatternDefImpl) ruleItem;
        Variable<?> patternVariable = patternDef.getFirstVariable();
        PatternImpl pattern = new PatternImpl(patternVariable, patternVariable instanceof Exchange ? Condition.Type.RECEIVER : Condition.Type.PATTERN);
        for (PatternItem patternItem : patternDef.getItems()) {
            if (patternItem instanceof PatternExprImpl) {
                pattern.addConstraint(((PatternExprImpl) patternItem).asConstraint(patternDef));
            } else if (patternItem instanceof PatternBindingImpl) {
                pattern.addBinding(((PatternBindingImpl) patternItem).asBinding(patternDef));
            } else {
                throw new UnsupportedOperationException("Unknown pattern item type: " + patternItem);
            }
        }
        pattern.addWatchedProps(patternDef.getWatch());
        pattern.setPassive(patternDef.isPassive());
        return pattern;
    }
    if (ruleItem instanceof FixedValueItem) {
        return new EvalImpl(((FixedValueItem) ruleItem).isValue());
    }
    if (ruleItem instanceof QueryCallViewItem) {
        return new QueryCallPattern((QueryCallViewItem) ruleItem);
    }
    if (ruleItem instanceof CombinedExprViewItem) {
        CombinedExprViewItem combined = (CombinedExprViewItem) ruleItem;
        List<Condition> conditions = new ArrayList<>();
        for (ViewItem expr : combined.getExpressions()) {
            conditions.add(ruleItem2Condition(expr));
        }
        return new CompositePatterns(combined.getType(), conditions);
    }
    if (ruleItem instanceof ExistentialExprViewItem) {
        ExistentialExprViewItem existential = (ExistentialExprViewItem) ruleItem;
        return new ExistentialPatternImpl(ruleItem2Condition(existential.getExpression()), existential.getType());
    }
    if (ruleItem instanceof GroupByExprViewItem) {
        GroupByExprViewItem groupBy = (GroupByExprViewItem) ruleItem;
        return new GroupByPatternImpl(ruleItem2Condition(groupBy.getExpr()), groupBy.getVars(), groupBy.getVarKey(), groupBy.getGroupingFunction(), groupBy.getAccumulateFunctions());
    }
    if (ruleItem instanceof AccumulateExprViewItem) {
        AccumulateExprViewItem acc = (AccumulateExprViewItem) ruleItem;
        return new AccumulatePatternImpl(ruleItem2Condition(acc.getExpr()), null, acc.getAccumulateFunctions());
    }
    if (ruleItem instanceof ExprViewItem) {
        return new EvalImpl(createConstraint((ExprViewItem) ruleItem));
    }
    if (ruleItem instanceof ExchangeDefImpl) {
        ExchangeDefImpl<?> exchangeDef = (ExchangeDefImpl) ruleItem;
        return new PatternImpl(exchangeDef.getFirstVariable(), Condition.Type.SENDER);
    }
    throw new UnsupportedOperationException("Unknown " + ruleItem);
}
Also used : AccumulatePatternImpl(org.drools.model.patterns.AccumulatePatternImpl) GroupByExprViewItem(org.drools.model.view.GroupByExprViewItem) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) ExistentialExprViewItem(org.drools.model.view.ExistentialExprViewItem) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) ExprViewItem(org.drools.model.view.ExprViewItem) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) ExistentialPatternImpl(org.drools.model.patterns.ExistentialPatternImpl) ExchangeDefImpl(org.drools.model.PatternDSL.ExchangeDefImpl) PatternItem(org.drools.model.PatternDSL.PatternItem) ArrayList(java.util.ArrayList) CompositePatterns(org.drools.model.patterns.CompositePatterns) GroupByExprViewItem(org.drools.model.view.GroupByExprViewItem) GroupByPatternImpl(org.drools.model.patterns.GroupByPatternImpl) PatternImpl(org.drools.model.patterns.PatternImpl) ExistentialPatternImpl(org.drools.model.patterns.ExistentialPatternImpl) AccumulatePatternImpl(org.drools.model.patterns.AccumulatePatternImpl) EvalImpl(org.drools.model.patterns.EvalImpl) QueryCallViewItem(org.drools.model.view.QueryCallViewItem) QueryCallPattern(org.drools.model.patterns.QueryCallPattern) GroupByPatternImpl(org.drools.model.patterns.GroupByPatternImpl) ExistentialExprViewItem(org.drools.model.view.ExistentialExprViewItem) Condition(org.drools.model.Condition) GroupByExprViewItem(org.drools.model.view.GroupByExprViewItem) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) ExistentialExprViewItem(org.drools.model.view.ExistentialExprViewItem) QueryCallViewItem(org.drools.model.view.QueryCallViewItem) ViewItem(org.drools.model.view.ViewItem) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) ExprViewItem(org.drools.model.view.ExprViewItem) FixedValueItem(org.drools.model.view.FixedValueItem) PatternExprImpl(org.drools.model.PatternDSL.PatternExprImpl) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) PatternBindingImpl(org.drools.model.PatternDSL.PatternBindingImpl) PatternDefImpl(org.drools.model.PatternDSL.PatternDefImpl)

Aggregations

ArrayList (java.util.ArrayList)1 Condition (org.drools.model.Condition)1 ExchangeDefImpl (org.drools.model.PatternDSL.ExchangeDefImpl)1 PatternBindingImpl (org.drools.model.PatternDSL.PatternBindingImpl)1 PatternDefImpl (org.drools.model.PatternDSL.PatternDefImpl)1 PatternExprImpl (org.drools.model.PatternDSL.PatternExprImpl)1 PatternItem (org.drools.model.PatternDSL.PatternItem)1 AccumulatePatternImpl (org.drools.model.patterns.AccumulatePatternImpl)1 CompositePatterns (org.drools.model.patterns.CompositePatterns)1 EvalImpl (org.drools.model.patterns.EvalImpl)1 ExistentialPatternImpl (org.drools.model.patterns.ExistentialPatternImpl)1 GroupByPatternImpl (org.drools.model.patterns.GroupByPatternImpl)1 PatternImpl (org.drools.model.patterns.PatternImpl)1 QueryCallPattern (org.drools.model.patterns.QueryCallPattern)1 AccumulateExprViewItem (org.drools.model.view.AccumulateExprViewItem)1 CombinedExprViewItem (org.drools.model.view.CombinedExprViewItem)1 ExistentialExprViewItem (org.drools.model.view.ExistentialExprViewItem)1 ExprViewItem (org.drools.model.view.ExprViewItem)1 FixedValueItem (org.drools.model.view.FixedValueItem)1 GroupByExprViewItem (org.drools.model.view.GroupByExprViewItem)1