Search in sources :

Example 1 with PackageModel

use of org.drools.modelcompiler.builder.PackageModel in project drools by kiegroup.

the class ToTypedExpressionTest method setUp.

@Before
public void setUp() throws Exception {
    imports = new HashSet<>();
    packageModel = new PackageModel("", null, false, null);
    typeResolver = new ClassTypeResolver(imports, getClass().getClassLoader());
    ruleContext = new RuleContext(knowledgeBuilder, packageModel, ruleDescr, typeResolver, true);
    imports.add("org.drools.modelcompiler.domain.Person");
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Before(org.junit.Before)

Example 2 with PackageModel

use of org.drools.modelcompiler.builder.PackageModel 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(NameExpr.class).stream().map(NameExpr::toString).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, false).buildPattern();
    });
    pattern.setIdentifier(null);
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) Set(java.util.Set) HashMap(java.util.HashMap) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) NameExpr(org.drools.javaparser.ast.expr.NameExpr) ArrayList(java.util.ArrayList) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) DSLNode(org.drools.modelcompiler.builder.generator.visitor.DSLNode) Map(java.util.Map) Collectors.toSet(java.util.stream.Collectors.toSet) HashMap(java.util.HashMap) NameExpr(org.drools.javaparser.ast.expr.NameExpr) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr)

Aggregations

PackageModel (org.drools.modelcompiler.builder.PackageModel)2 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.compiler.lang.descr.AccumulateDescr)1 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)1 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)1 NameExpr (org.drools.javaparser.ast.expr.NameExpr)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 Before (org.junit.Before)1 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)1