Search in sources :

Example 1 with PrintUtil

use of org.drools.mvel.parser.printer.PrintUtil in project drools by kiegroup.

the class PatternAccumulateConstraint method buildPattern.

@Override
public void buildPattern() {
    Map<String, List<BaseDescr>> constraintsByVar = new HashMap<>();
    for (BaseDescr constraint : constraintDescrs) {
        Set<String> exprIds = DrlxParseUtil.parseExpression(constraint.getText()).getExpr().findAll(DrlNameExpr.class).stream().map(PrintUtil::printNode).collect(toSet());
        for (AccumulateDescr.AccumulateFunctionCallDescr accFunc : source.getFunctions()) {
            if (exprIds.contains(accFunc.getBind())) {
                constraintsByVar.computeIfAbsent(accFunc.getBind(), s -> new ArrayList<>()).add(constraint);
                break;
            }
        }
    }
    constraintsByVar.forEach((id, constraints) -> {
        pattern.setIdentifier(id);
        new PatternDSLPattern(context, packageModel, pattern, constraints, null).buildPattern();
    });
    pattern.setIdentifier(null);
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) Set(java.util.Set) HashMap(java.util.HashMap) PatternDescr(org.drools.drl.ast.descr.PatternDescr) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) BaseDescr(org.drools.drl.ast.descr.BaseDescr) ArrayList(java.util.ArrayList) PrintUtil(org.drools.mvel.parser.printer.PrintUtil) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) DSLNode(org.drools.modelcompiler.builder.generator.visitor.DSLNode) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) Map(java.util.Map) Collectors.toSet(java.util.stream.Collectors.toSet) HashMap(java.util.HashMap) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BaseDescr(org.drools.drl.ast.descr.BaseDescr) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)1 BaseDescr (org.drools.drl.ast.descr.BaseDescr)1 PatternDescr (org.drools.drl.ast.descr.PatternDescr)1 PackageModel (org.drools.modelcompiler.builder.PackageModel)1 DrlxParseUtil (org.drools.modelcompiler.builder.generator.DrlxParseUtil)1 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)1 DSLNode (org.drools.modelcompiler.builder.generator.visitor.DSLNode)1 DrlNameExpr (org.drools.mvel.parser.ast.expr.DrlNameExpr)1 PrintUtil (org.drools.mvel.parser.printer.PrintUtil)1