use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KnowledgeBaseImpl method removeObjectsGeneratedFromResource.
public boolean removeObjectsGeneratedFromResource(Resource resource) {
boolean modified = false;
for (InternalKnowledgePackage pkg : pkgs.values()) {
List<RuleImpl> rulesToBeRemoved = pkg.getRulesGeneratedFromResource(resource);
if (!rulesToBeRemoved.isEmpty()) {
this.reteooBuilder.removeRules(rulesToBeRemoved);
// in order to allow the correct flushing of all outstanding staged tuples
for (RuleImpl rule : rulesToBeRemoved) {
pkg.removeRule(rule);
}
}
List<Function> functionsToBeRemoved = pkg.removeFunctionsGeneratedFromResource(resource);
for (Function function : functionsToBeRemoved) {
internalRemoveFunction(pkg.getName(), function.getName());
}
List<Process> processesToBeRemoved = pkg.removeProcessesGeneratedFromResource(resource);
for (Process process : processesToBeRemoved) {
processes.remove(process.getId());
}
List<TypeDeclaration> removedTypes = pkg.removeTypesGeneratedFromResource(resource);
boolean resourceTypePackageSomethingRemoved = pkg.removeFromResourceTypePackageGeneratedFromResource(resource);
modified |= !rulesToBeRemoved.isEmpty() || !functionsToBeRemoved.isEmpty() || !processesToBeRemoved.isEmpty() || !removedTypes.isEmpty() || resourceTypePackageSomethingRemoved;
}
return modified;
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KnowledgePackageImpl method readExternal.
/**
* Handles the read serialization of the Package. Patterns in Rules may
* reference generated data which cannot be serialized by default methods.
* The Package uses PackageCompilationData to hold a reference to the
* generated bytecode; which must be restored before any Rules. A custom
* ObjectInputStream, able to resolve classes against the bytecode in the
* PackageCompilationData, is used to restore the Rules.
*
* @param stream, the stream to read data from in order to restore the object;
* should be an instance of DroolsObjectInputStream or
* InputStream
*/
public void readExternal(ObjectInput stream) throws IOException, ClassNotFoundException {
boolean isDroolsStream = stream instanceof DroolsObjectInputStream;
DroolsObjectInputStream in = isDroolsStream ? (DroolsObjectInputStream) stream : new DroolsObjectInputStream(new ByteArrayInputStream((byte[]) stream.readObject()));
this.name = (String) in.readObject();
this.classFieldAccessorStore = (ClassFieldAccessorStore) in.readObject();
in.setStore(this.classFieldAccessorStore);
this.dialectRuntimeRegistry = (DialectRuntimeRegistry) in.readObject();
this.typeDeclarations = (Map) in.readObject();
this.imports = (Map<String, ImportDeclaration>) in.readObject();
this.staticImports = (Set) in.readObject();
this.functions = (Map<String, Function>) in.readObject();
this.accumulateFunctions = (Map<String, AccumulateFunction>) in.readObject();
this.factTemplates = (Map) in.readObject();
this.ruleFlows = (Map) in.readObject();
this.globals = (Map<String, String>) in.readObject();
this.valid = in.readBoolean();
this.needStreamMode = in.readBoolean();
this.rules = (Map<String, RuleImpl>) in.readObject();
this.entryPointsIds = (Set<String>) in.readObject();
this.windowDeclarations = (Map<String, WindowDeclaration>) in.readObject();
this.traitRegistry = (TraitRegistry) in.readObject();
this.resourceTypePackages = (Map<ResourceType, ResourceTypePackage>) in.readObject();
in.setStore(null);
if (!isDroolsStream) {
in.close();
}
}
use of org.drools.core.definitions.rule.impl.RuleImpl 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;
}
use of org.drools.core.definitions.rule.impl.RuleImpl 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;
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KiePackagesBuilder method build.
public CanonicalKiePackages build() {
for (Model model : models) {
for (TypeMetaData metaType : model.getTypeMetaDatas()) {
KnowledgePackageImpl pkg = (KnowledgePackageImpl) packages.computeIfAbsent(metaType.getPackage(), this::createKiePackage);
pkg.addTypeDeclaration(createTypeDeclaration(pkg, metaType));
}
for (Global global : model.getGlobals()) {
KnowledgePackageImpl pkg = (KnowledgePackageImpl) packages.computeIfAbsent(global.getPackage(), this::createKiePackage);
pkg.addGlobal(global.getName(), global.getType());
}
for (Query query : model.getQueries()) {
KnowledgePackageImpl pkg = (KnowledgePackageImpl) packages.computeIfAbsent(query.getPackage(), this::createKiePackage);
pkg.addRule(compileQuery(pkg, query));
}
int ruleCounter = 0;
for (Rule rule : model.getRules()) {
KnowledgePackageImpl pkg = (KnowledgePackageImpl) packages.computeIfAbsent(rule.getPackage(), this::createKiePackage);
RuleImpl ruleImpl = compileRule(pkg, rule);
ruleImpl.setLoadOrder(ruleCounter++);
pkg.addRule(ruleImpl);
}
}
return new CanonicalKiePackages(packages);
}
Aggregations