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