use of org.drools.modelcompiler.constraints.LambdaConstraint in project drools by kiegroup.
the class KieBuilderTest method testPatternModelBuild.
@Test
public void testPatternModelBuild() throws Exception {
KieSession ksession = checkKieSession(ExecutableModelProject.class);
assertTrue(getAlphaConstraint(ksession) instanceof LambdaConstraint);
}
use of org.drools.modelcompiler.constraints.LambdaConstraint in project drools by kiegroup.
the class KieBuilderTest method testFlowModelBuild.
@Test
public void testFlowModelBuild() throws Exception {
KieSession ksession = checkKieSession(ExecutableModelFlowProject.class);
assertTrue(getAlphaConstraint(ksession) instanceof LambdaConstraint);
}
use of org.drools.modelcompiler.constraints.LambdaConstraint in project drools by kiegroup.
the class KiePackagesBuilder method addConstraintsToPattern.
private void addConstraintsToPattern(RuleContext ctx, Pattern pattern, org.drools.model.Pattern modelPattern, Constraint constraint) {
if (constraint.getType() == Constraint.Type.SINGLE) {
SingleConstraint singleConstraint = (SingleConstraint) constraint;
boolean isEqual = singleConstraint.getIndex() != null && singleConstraint.getIndex().getConstraintType() == Index.ConstraintType.EQUAL;
if (singleConstraint.getVariables().length > 0) {
Variable[] vars = singleConstraint.getVariables();
Declaration[] declarations = new Declaration[vars.length];
Declaration unificationDeclaration = null;
for (int i = 0; i < vars.length; i++) {
declarations[i] = ctx.getDeclaration(vars[i]);
if (isEqual && declarations[i].getPattern().getObjectType().equals(ClassObjectType.DroolsQuery_ObjectType)) {
unificationDeclaration = declarations[i];
} else if (pattern.getSource() instanceof MultiAccumulate) {
Declaration accDeclaration = pattern.getDeclarations().get(declarations[i].getBindingName());
if (accDeclaration != null) {
declarations[i].setReadAccessor(accDeclaration.getExtractor());
}
}
}
ConstraintEvaluator constraintEvaluator = singleConstraint.isTemporal() ? new TemporalConstraintEvaluator(declarations, pattern, singleConstraint) : new ConstraintEvaluator(declarations, pattern, singleConstraint);
org.drools.core.spi.Constraint droolsConstraint = unificationDeclaration != null ? new UnificationConstraint(unificationDeclaration, constraintEvaluator) : new LambdaConstraint(constraintEvaluator);
pattern.addConstraint(droolsConstraint);
}
} else if (modelPattern.getConstraint().getType() == Constraint.Type.AND) {
for (Constraint child : constraint.getChildren()) {
addConstraintsToPattern(ctx, pattern, modelPattern, child);
}
}
}
use of org.drools.modelcompiler.constraints.LambdaConstraint 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