use of org.drools.model.constraints.SingleConstraint1 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);
}
use of org.drools.model.constraints.SingleConstraint1 in project drools by kiegroup.
the class KiePackagesBuilder method createWindowReference.
private <T> void createWindowReference(RuleContext ctx, WindowReference<T> window) {
WindowDeclaration windowDeclaration = new WindowDeclaration(window.getName(), ctx.getPkg().getName());
Variable<T> variable = declarationOf(window.getPatternType());
Pattern windowPattern = new Pattern(0, getClassObjectType(window.getPatternType()), variable.getName());
windowDeclaration.setPattern(windowPattern);
for (Predicate1<T> predicate : window.getPredicates()) {
SingleConstraint singleConstraint = new SingleConstraint1<>(generateName("expr"), variable, predicate);
ConstraintEvaluator constraintEvaluator = new ConstraintEvaluator(windowPattern, singleConstraint);
windowPattern.addConstraint(new LambdaConstraint(constraintEvaluator));
}
windowPattern.addBehavior(createWindow(window));
ctx.getPkg().addWindowDeclaration(windowDeclaration);
}
Aggregations