use of org.drools.modelcompiler.constraints.UnificationConstraint in project drools by kiegroup.
the class KiePackagesBuilder method buildPattern.
private Pattern buildPattern(RuleContext ctx, GroupElement group, Condition condition) {
org.drools.model.Pattern<?> modelPattern = (org.drools.model.Pattern) condition;
Pattern pattern = addPatternForVariable(ctx, group, modelPattern.getPatternVariable());
for (Binding binding : modelPattern.getBindings()) {
Declaration declaration = new Declaration(binding.getBoundVariable().getName(), new LambdaReadAccessor(binding.getBoundVariable().getType(), binding.getBindingFunction()), pattern, true);
pattern.addDeclaration(declaration);
if (binding.getReactOn() != null) {
addFieldsToPatternWatchlist(pattern, binding.getReactOn());
}
ctx.addInnerDeclaration(binding.getBoundVariable(), declaration);
}
Declaration queryArgDecl = ctx.getQueryDeclaration(modelPattern.getPatternVariable());
if (queryArgDecl != null) {
pattern.addConstraint(new UnificationConstraint(queryArgDecl));
}
addConstraintsToPattern(ctx, pattern, modelPattern, modelPattern.getConstraint());
addFieldsToPatternWatchlist(pattern, modelPattern.getWatchedProps());
return pattern;
}
use of org.drools.modelcompiler.constraints.UnificationConstraint 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.UnificationConstraint in project drools by kiegroup.
the class KiePackagesBuilder method createSingleConstraint.
private org.drools.core.spi.Constraint createSingleConstraint(RuleContext ctx, Pattern pattern, SingleConstraint singleConstraint) {
Variable[] vars = singleConstraint.getVariables();
Declaration[] declarations = new Declaration[vars.length];
Declaration unificationDeclaration = collectConstraintDeclarations(ctx, pattern, singleConstraint, vars, declarations);
ConstraintEvaluator constraintEvaluator = singleConstraint.isTemporal() ? new TemporalConstraintEvaluator(declarations, pattern, singleConstraint) : new ConstraintEvaluator(declarations, pattern, singleConstraint);
return unificationDeclaration != null ? new UnificationConstraint(unificationDeclaration, constraintEvaluator) : new LambdaConstraint(constraintEvaluator, singleConstraint.predicateInformation());
}
use of org.drools.modelcompiler.constraints.UnificationConstraint in project drools by kiegroup.
the class KiePackagesBuilder method buildPattern.
private RuleConditionElement buildPattern(RuleContext ctx, GroupElement group, org.drools.model.Pattern<?> modelPattern) {
Variable patternVariable = modelPattern.getPatternVariable();
Pattern pattern = addPatternForVariable(ctx, group, patternVariable, modelPattern.getType());
Arrays.stream(modelPattern.getWatchedProps()).forEach(pattern::addWatchedProperty);
pattern.setPassive(modelPattern.isPassive());
for (Binding binding : modelPattern.getBindings()) {
// FIXME this is returning null for BindViewItem2, BindViewItem3 etc (mdp)
Function1 f1 = getBindingFunction(ctx, patternVariable, binding);
Declaration declaration = new Declaration(binding.getBoundVariable().getName(), new LambdaReadAccessor(binding.getBoundVariable().getType(), f1), pattern, true);
pattern.addDeclaration(declaration);
if (binding.getReactOn() != null) {
Arrays.stream(binding.getReactOn()).forEach(pattern::addBoundProperty);
}
ctx.addDeclaration(binding.getBoundVariable(), declaration);
}
Declaration queryArgDecl = ctx.getQueryDeclaration(patternVariable);
if (queryArgDecl != null) {
pattern.addConstraint(new UnificationConstraint(queryArgDecl));
}
addConstraintsToPattern(ctx, pattern, modelPattern.getConstraint());
addReactiveMasksToPattern(pattern, modelPattern.getPatternClassMetadata());
return pattern;
}
Aggregations