Search in sources :

Example 66 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class KnowledgeBaseImpl method addPackages.

/**
 * Add a <code>Package</code> to the network. Iterates through the
 * <code>Package</code> adding Each individual <code>Rule</code> to the
 * network. Before update network each referenced <code>WorkingMemory</code>
 * is locked.
 *
 * @param newPkgs The package to add.
 */
@Override
public void addPackages(Collection<KiePackage> newPkgs) {
    final List<InternalKnowledgePackage> clonedPkgs = new ArrayList<InternalKnowledgePackage>();
    for (KiePackage newPkg : newPkgs) {
        clonedPkgs.add(((InternalKnowledgePackage) newPkg).deepCloneIfAlreadyInUse(rootClassLoader));
    }
    enqueueModification(() -> internalAddPackages(clonedPkgs));
}
Also used : KiePackage(org.kie.api.definition.KiePackage) ArrayList(java.util.ArrayList) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 67 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class TraitFactory method getClassFieldAccessorStore.

protected ClassFieldAccessorStore getClassFieldAccessorStore() {
    InternalKnowledgePackage traitPackage = kBase.getPackagesMap().get(pack);
    if (traitPackage == null) {
        traitPackage = new KnowledgePackageImpl(pack);
        traitPackage.setClassFieldAccessorCache(kBase.getClassFieldAccessorCache());
        kBase.getPackagesMap().put(pack, traitPackage);
    }
    return traitPackage.getClassFieldAccessorStore();
}
Also used : KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 68 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class DroolsAbstractPMMLTest method getStartingRuleUnit.

protected Class<? extends RuleUnit> getStartingRuleUnit(String startingRule, InternalKnowledgeBase ikb, List<String> possiblePackages) {
    RuleUnitRegistry unitRegistry = ikb.getRuleUnitRegistry();
    Map<String, InternalKnowledgePackage> pkgs = ikb.getPackagesMap();
    RuleImpl ruleImpl = null;
    for (String pkgName : possiblePackages) {
        if (pkgs.containsKey(pkgName)) {
            InternalKnowledgePackage pkg = pkgs.get(pkgName);
            ruleImpl = pkg.getRule(startingRule);
            if (ruleImpl != null) {
                RuleUnitDescr descr = unitRegistry.getRuleUnitFor(ruleImpl).orElse(null);
                if (descr != null) {
                    return descr.getRuleUnitClass();
                }
            }
        }
    }
    return null;
}
Also used : RuleUnitRegistry(org.drools.core.ruleunit.RuleUnitRegistry) RuleUnitDescr(org.drools.core.ruleunit.RuleUnitDescr) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 69 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class PMMLExecutor method startingRuleUnit.

protected Class<? extends RuleUnit> startingRuleUnit(String startingRule, String modelId, String... knownPackageNames) {
    List<String> possiblePackages = calculatePossiblePackageNames(modelId, knownPackageNames);
    InternalKnowledgeBase internalKnowledgeBase = (InternalKnowledgeBase) kieBase;
    RuleUnitRegistry unitRegistry = internalKnowledgeBase.getRuleUnitRegistry();
    Map<String, InternalKnowledgePackage> pkgs = internalKnowledgeBase.getPackagesMap();
    RuleImpl ruleImpl = null;
    for (String pkgName : possiblePackages) {
        if (pkgs.containsKey(pkgName)) {
            InternalKnowledgePackage pkg = pkgs.get(pkgName);
            ruleImpl = pkg.getRule(startingRule);
            if (ruleImpl != null) {
                RuleUnitDescr descr = unitRegistry.getRuleUnitFor(ruleImpl).orElse(null);
                if (descr != null) {
                    return descr.getRuleUnitClass();
                }
            }
        }
    }
    return null;
}
Also used : RuleUnitRegistry(org.drools.core.ruleunit.RuleUnitRegistry) RuleUnitDescr(org.drools.core.ruleunit.RuleUnitDescr) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 70 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class ModelBuilderImpl method generatePOJOs.

protected void generatePOJOs(PackageDescr packageDescr, PackageRegistry pkgRegistry) {
    InternalKnowledgePackage pkg = pkgRegistry.getPackage();
    String pkgName = pkg.getName();
    PackageModel model = packageModels.computeIfAbsent(pkgName, s -> {
        final DialectCompiletimeRegistry dialectCompiletimeRegistry = pkgRegistry.getDialectCompiletimeRegistry();
        return new PackageModel(pkgName, this.getBuilderConfiguration(), isPattern, dialectCompiletimeRegistry);
    });
    model.addImports(pkg.getTypeResolver().getImports());
    generatePOJO(pkg, packageDescr, model);
}
Also used : DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)97 Test (org.junit.Test)32 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)28 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)26 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)24 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)21 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)20 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)16 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)14 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)13 TypeDeclaration (org.drools.core.rule.TypeDeclaration)13 HashMap (java.util.HashMap)12 Pattern (org.drools.core.rule.Pattern)12 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)11 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)11 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)11 ClassObjectType (org.drools.core.base.ClassObjectType)10 ArrayList (java.util.ArrayList)9 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)9 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)8