Search in sources :

Example 11 with CompositePackageDescr

use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.

the class KnowledgeBuilderImpl method buildOtherDeclarations.

protected void buildOtherDeclarations(Collection<CompositePackageDescr> packages) {
    for (CompositePackageDescr packageDescr : packages) {
        setAssetFilter(packageDescr.getFilter());
        PackageRegistry pkgRegistry = getPackageRegistry(packageDescr.getNamespace());
        processOtherDeclarations(pkgRegistry, packageDescr);
        setAssetFilter(null);
    }
}
Also used : PackageRegistry(org.drools.compiler.compiler.PackageRegistry) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr)

Example 12 with CompositePackageDescr

use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.

the class KnowledgeBuilderImpl method buildTypeDeclarations.

protected void buildTypeDeclarations(Collection<CompositePackageDescr> packages) {
    Map<String, AbstractClassTypeDeclarationDescr> unprocesseableDescrs = new HashMap<>();
    List<TypeDefinition> unresolvedTypes = new ArrayList<>();
    List<AbstractClassTypeDeclarationDescr> unsortedDescrs = new ArrayList<>();
    for (CompositePackageDescr packageDescr : packages) {
        unsortedDescrs.addAll(packageDescr.getTypeDeclarations());
        unsortedDescrs.addAll(packageDescr.getEnumDeclarations());
    }
    getTypeBuilder().processTypeDeclarations(packages, unsortedDescrs, unresolvedTypes, unprocesseableDescrs);
    for (CompositePackageDescr packageDescr : packages) {
        for (ImportDescr importDescr : packageDescr.getImports()) {
            getPackageRegistry(packageDescr.getNamespace()).addImport(importDescr);
        }
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) AbstractClassTypeDeclarationDescr(org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr) ArrayList(java.util.ArrayList) ImportDescr(org.drools.drl.ast.descr.ImportDescr) FunctionImportDescr(org.drools.drl.ast.descr.FunctionImportDescr) AccumulateImportDescr(org.drools.drl.ast.descr.AccumulateImportDescr)

Example 13 with CompositePackageDescr

use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.

the class KnowledgeBuilderImpl method findChildrenRulesToBeRemoved.

private Collection<RuleImpl> findChildrenRulesToBeRemoved(PackageDescr packageDescr, Collection<RuleImpl> rulesToBeRemoved) {
    Collection<String> childrenRuleNamesToBeRemoved = new HashSet<>();
    Collection<RuleImpl> childrenRulesToBeRemoved = new HashSet<>();
    for (RuleImpl rule : rulesToBeRemoved) {
        if (rule.hasChildren()) {
            for (RuleImpl child : rule.getChildren()) {
                if (!rulesToBeRemoved.contains(child)) {
                    // if a rule has a child rule not marked to be removed ...
                    childrenRulesToBeRemoved.add(child);
                    childrenRuleNamesToBeRemoved.add(child.getName());
                    // ... remove the child rule but also add it back to the PackageDescr in order to readd it when also the parent rule will be readded ...
                    RuleDescr toBeReadded = new RuleDescr(child.getName());
                    toBeReadded.setNamespace(packageDescr.getNamespace());
                    packageDescr.addRule(toBeReadded);
                }
            }
        }
    }
    // ... add a filter to the PackageDescr to also consider the readded children rules as updated together with the parent one
    if (!childrenRuleNamesToBeRemoved.isEmpty()) {
        ((CompositePackageDescr) packageDescr).addFilter((type, pkgName, assetName) -> childrenRuleNamesToBeRemoved.contains(assetName) ? AssetFilter.Action.UPDATE : AssetFilter.Action.DO_NOTHING);
    }
    return childrenRulesToBeRemoved;
}
Also used : CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) HashSet(java.util.HashSet)

Example 14 with CompositePackageDescr

use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.

the class KnowledgeBuilderImpl method buildRules.

protected void buildRules(Collection<CompositePackageDescr> packages) {
    for (CompositePackageDescr packageDescr : packages) {
        setAssetFilter(packageDescr.getFilter());
        PackageRegistry pkgRegistry = getPackageRegistry(packageDescr.getNamespace());
        compileKnowledgePackages(packageDescr, pkgRegistry);
        setAssetFilter(null);
    }
    wireAllRules();
    processKieBaseTypes();
    for (CompositePackageDescr packageDescr : packages) {
        setAssetFilter(packageDescr.getFilter());
        compileRete(packageDescr);
        setAssetFilter(null);
    }
}
Also used : PackageRegistry(org.drools.compiler.compiler.PackageRegistry) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr)

Example 15 with CompositePackageDescr

use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.

the class ModelBuilderImpl method buildRules.

protected void buildRules(Collection<CompositePackageDescr> packages) {
    if (hasErrors()) {
        // if Error while generating pojo do not try compile rule as they very likely depends hence fail too.
        return;
    }
    for (CompositePackageDescr packageDescr : packages) {
        setAssetFilter(packageDescr.getFilter());
        PackageRegistry pkgRegistry = getPackageRegistry(packageDescr.getNamespace());
        compileKnowledgePackages(packageDescr, pkgRegistry);
        setAssetFilter(null);
        PackageModel pkgModel = packageModels.remove(pkgRegistry.getPackage().getName());
        pkgModel.setOneClassPerRule(oneClassPerRule);
        if (getResults(ResultSeverity.ERROR).isEmpty()) {
            packageSources.put(pkgModel.getName(), sourcesGenerator.apply(pkgModel));
        }
    }
}
Also used : PackageRegistry(org.drools.compiler.compiler.PackageRegistry) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr)

Aggregations

CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)16 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)8 HashMap (java.util.HashMap)6 PackageDescr (org.drools.drl.ast.descr.PackageDescr)6 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)5 ImportDescr (org.drools.drl.ast.descr.ImportDescr)5 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 TypeDeclaration (org.drools.core.rule.TypeDeclaration)3 AbstractClassTypeDeclarationDescr (org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr)3 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)3 KiePMMLDroolsAST (org.kie.pmml.models.drools.ast.KiePMMLDroolsAST)3 KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)3 StaticJavaParser.parseImport (com.github.javaparser.StaticJavaParser.parseImport)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2